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/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index 521fa4329..e26e40545 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -68,7 +68,7 @@ %h4.text-info = procedure.libelle - = h sanitize(procedure.description) + = h string_to_html(procedure.description) .champs.col-xs-6.col-md-3 %h4.text-info diff --git a/app/views/dossiers/etapes/_etape1.html.haml b/app/views/dossiers/etapes/_etape1.html.haml index aab261b68..7b12d5ecc 100644 --- a/app/views/dossiers/etapes/_etape1.html.haml +++ b/app/views/dossiers/etapes/_etape1.html.haml @@ -16,7 +16,7 @@ = @facade.procedure.libelle #description_procedure{ style: 'width: 95%;', class: (@facade.etablissement.nil? ? '' : 'mask') } - = h simple_format(@facade.procedure.description) + = h string_to_html(@facade.procedure.description) - if @facade.procedure.lien_site_web.present? .center diff --git a/app/views/new_user/dossiers/identite.html.haml b/app/views/new_user/dossiers/identite.html.haml index 54fea25a4..6847dc8f6 100644 --- a/app/views/new_user/dossiers/identite.html.haml +++ b/app/views/new_user/dossiers/identite.html.haml @@ -9,7 +9,7 @@ %h2.procedure-title = @dossier.procedure.libelle .procedure-description - = h simple_format(@dossier.procedure.description) + = h string_to_html(@dossier.procedure.description) .column = form_for @dossier.individual, url: update_identite_dossier_path(@dossier), html: { class: "form" } do |f| diff --git a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml index 76d7c3596..8c1070299 100644 --- a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml +++ b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml @@ -8,4 +8,4 @@ = "modifié le #{champ.updated_at.strftime('%d/%m/%Y à %H:%M')}" - if champ.description.present? - %span.notice= html_formatted_description(champ.description) + %span.notice= string_to_html(champ.description) diff --git a/app/views/shared/dossiers/editable_champs/_explication.html.haml b/app/views/shared/dossiers/editable_champs/_explication.html.haml index 07ef71490..4dce77388 100644 --- a/app/views/shared/dossiers/editable_champs/_explication.html.haml +++ b/app/views/shared/dossiers/editable_champs/_explication.html.haml @@ -1,3 +1,3 @@ %h2.explication-libelle= champ.libelle .explication - = html_formatted_description(champ.description) + = string_to_html(champ.description) diff --git a/app/views/users/sessions/_resume_procedure.html.haml b/app/views/users/sessions/_resume_procedure.html.haml index f42a11ad1..56ea59e91 100644 --- a/app/views/users/sessions/_resume_procedure.html.haml +++ b/app/views/users/sessions/_resume_procedure.html.haml @@ -13,7 +13,7 @@ %h2#titre-procedure.text-info = @dossier.procedure.libelle %p.procedure-description - = h sanitize(@dossier.procedure.description) + = h string_to_html(@dossier.procedure.description) - else #logo_procedure.flag diff --git a/app/views/users/siret/_pro.html.haml b/app/views/users/siret/_pro.html.haml index f263f255a..5ddb0de3d 100644 --- a/app/views/users/siret/_pro.html.haml +++ b/app/views/users/siret/_pro.html.haml @@ -6,7 +6,7 @@ = @procedure.libelle %div - = simple_format(@procedure.description) + = h string_to_html(@procedure.description) %br = form_tag(url_for({ controller: :dossiers, action: :create }), class: 'form-inline', method: 'POST') do |f| 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" }