From 152cf03d72c73002570a1a414cc289f910433c6f Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 24 May 2018 18:01:40 +0200 Subject: [PATCH] [Fix #1801] rename and move html_formatted_description in a generic helper --- app/helpers/champ_helper.rb | 6 ------ app/helpers/string_to_html_helper.rb | 7 +++++++ ...{champ_helper_spec.rb => string_to_html_helper_spec.rb} | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 app/helpers/string_to_html_helper.rb rename spec/helpers/{champ_helper_spec.rb => string_to_html_helper_spec.rb} (81%) diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb index aefbb0490..b9145628a 100644 --- a/app/helpers/champ_helper.rb +++ b/app/helpers/champ_helper.rb @@ -2,10 +2,4 @@ module ChampHelper def is_not_header_nor_explication?(champ) !['header_section', 'explication'].include?(champ.type_champ) end - - def html_formatted_description(description) - html_formatted = simple_format(description) - with_links = html_formatted.gsub(URI.regexp, '\0') - sanitize(with_links, attributes: %w(href target)) - end end diff --git a/app/helpers/string_to_html_helper.rb b/app/helpers/string_to_html_helper.rb new file mode 100644 index 000000000..793bc8b58 --- /dev/null +++ b/app/helpers/string_to_html_helper.rb @@ -0,0 +1,7 @@ +module StringToHtmlHelper + def string_to_html(str) + html_formatted = simple_format(str) + with_links = html_formatted.gsub(URI.regexp, '\0') + sanitize(with_links, attributes: %w(href target)) + end +end diff --git a/spec/helpers/champ_helper_spec.rb b/spec/helpers/string_to_html_helper_spec.rb similarity index 81% rename from spec/helpers/champ_helper_spec.rb rename to spec/helpers/string_to_html_helper_spec.rb index 581e1be2c..c597fb8f5 100644 --- a/spec/helpers/champ_helper_spec.rb +++ b/spec/helpers/string_to_html_helper_spec.rb @@ -1,6 +1,6 @@ -RSpec.describe ChampHelper, type: :helper do - describe "#html_formatted_description" do - subject { html_formatted_description(description) } +RSpec.describe StringToHtmlHelper, type: :helper do + describe "#string_to_html" do + subject { string_to_html(description) } context "with some simple texte" do let(:description) { "1er ligne \n 2ieme ligne" }