Merge pull request #1508 from betagouv/fix_explanation
_explication: display champ.description instead of champ.value
This commit is contained in:
commit
468adbeda4
5 changed files with 40 additions and 5 deletions
|
@ -20,7 +20,7 @@ class RootController < ApplicationController
|
|||
end
|
||||
|
||||
def patron
|
||||
description = 'a not so long description'
|
||||
description = 'aller voir le super site : https://demarches-simplifiees.fr'
|
||||
|
||||
all_champs = TypeDeChamp.type_champs
|
||||
.map { |name, _| TypeDeChamp.new(type_champ: name, private: false, libelle: name, description: description, mandatory: true) }
|
||||
|
@ -45,8 +45,7 @@ class RootController < ApplicationController
|
|||
type_champ_values = {
|
||||
'date': '2016-07-26',
|
||||
'datetime': '26/07/2016 07:35',
|
||||
'textarea': 'Une description de mon projet',
|
||||
'explication': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. In erat mauris, faucibus quis pharetra sit amet, pretium ac libero. Etiam vehicula eleifend bibendum. Morbi gravida metus ut sapien condimentum sodales mollis augue sodales. Vestibulum quis quam at sem placerat aliquet',
|
||||
'textarea': 'Une description de mon projet'
|
||||
}
|
||||
|
||||
type_champ_values.each do |(type_champ, value)|
|
||||
|
|
|
@ -2,4 +2,10 @@ 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, '<a target="_blank" href="\0">\0</a>')
|
||||
sanitize(with_links, attributes: %w(href target))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,4 +8,4 @@
|
|||
= "modifié le #{champ.updated_at.strftime('%d/%m/%Y à %H:%M')}"
|
||||
|
||||
- if champ.description.present?
|
||||
%span.notice= champ.description
|
||||
%span.notice= html_formatted_description(champ.description)
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
%h2.explication-libelle= champ.libelle
|
||||
%p.explication= champ.value
|
||||
.explication
|
||||
= html_formatted_description(champ.description)
|
||||
|
|
29
spec/helpers/champ_helper_spec.rb
Normal file
29
spec/helpers/champ_helper_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
RSpec.describe ChampHelper, type: :helper do
|
||||
describe "#html_formatted_description" do
|
||||
subject { html_formatted_description(description) }
|
||||
|
||||
context "with some simple texte" do
|
||||
let(:description) { "1er ligne \n 2ieme ligne" }
|
||||
|
||||
it { is_expected.to eq("<p>1er ligne \n<br> 2ieme ligne</p>") }
|
||||
end
|
||||
|
||||
context "with a link" do
|
||||
let(:description) { "https://d-s.fr" }
|
||||
|
||||
it { is_expected.to eq("<p><a target=\"_blank\" href=\"https://d-s.fr\">https://d-s.fr</a></p>") }
|
||||
end
|
||||
|
||||
context "with empty decription" do
|
||||
let(:description) { nil }
|
||||
|
||||
it { is_expected.to eq('<p></p>') }
|
||||
end
|
||||
|
||||
context "with a bad script" do
|
||||
let(:description) { '<script>bad</script>' }
|
||||
|
||||
it { is_expected.to eq('<p>bad</p>') }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue