Merge pull request #4368 from tchak/auto-link
Auto-link valeur des champs
This commit is contained in:
commit
b52dfebfca
6 changed files with 25 additions and 2 deletions
1
Gemfile
1
Gemfile
|
@ -7,6 +7,7 @@ gem 'active_model_serializers'
|
|||
gem 'activestorage-openstack', git: 'https://github.com/fredZen/activestorage-openstack.git', branch: 'frederic/fix_upload_signature'
|
||||
gem 'administrate'
|
||||
gem 'after_party'
|
||||
gem 'anchored'
|
||||
gem 'axlsx', '~> 3.0.0.pre' # https://github.com/randym/axlsx/issues/501#issuecomment-373640365
|
||||
gem 'bcrypt'
|
||||
gem 'bootstrap-sass', '>= 3.4.1'
|
||||
|
|
|
@ -95,6 +95,7 @@ GEM
|
|||
selectize-rails (~> 0.6)
|
||||
aes_key_wrap (1.0.1)
|
||||
after_party (1.10.0)
|
||||
anchored (1.1.0)
|
||||
arel (9.0.0)
|
||||
ast (2.4.0)
|
||||
attr_required (1.0.1)
|
||||
|
@ -722,6 +723,7 @@ DEPENDENCIES
|
|||
activestorage-openstack!
|
||||
administrate
|
||||
after_party
|
||||
anchored
|
||||
axlsx (~> 3.0.0.pre)
|
||||
bcrypt
|
||||
bootstrap-sass (>= 3.4.1)
|
||||
|
|
|
@ -17,4 +17,12 @@ module ChampHelper
|
|||
{ type_de_champ_id: champ.type_de_champ_id }
|
||||
end
|
||||
end
|
||||
|
||||
def format_text_value(text)
|
||||
sanitized_text = sanitize(text)
|
||||
auto_linked_text = Anchored::Linker.auto_link(sanitized_text, target: '_blank', rel: 'noopener') do |link_href|
|
||||
truncate(link_href, length: 60)
|
||||
end
|
||||
simple_format(auto_linked_text, {}, sanitize: false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1 +1 @@
|
|||
= simple_format(champ.to_s)
|
||||
= format_text_value(champ.to_s)
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
- when TypeDeChamp.type_champs.fetch(:datetime)
|
||||
= c.to_s
|
||||
- else
|
||||
= sanitize(c.to_s)
|
||||
= format_text_value(c.to_s)
|
||||
|
||||
- if c.type_champ != TypeDeChamp.type_champs.fetch(:header_section)
|
||||
%td.updated-at
|
||||
|
|
|
@ -40,6 +40,18 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
|
|||
expect(subject).not_to include(champ3.libelle)
|
||||
expect(subject).not_to include(champ3.value)
|
||||
end
|
||||
|
||||
context "with auto-link" do
|
||||
let(:champ1) { create(:champ_text, value: "https://github.com/tchak") }
|
||||
let(:champ2) { create(:champ_textarea, value: "https://github.com/LeSim") }
|
||||
let(:link1) { '<a href="https://github.com/tchak" target="_blank" rel="noopener">https://github.com/tchak</a>' }
|
||||
let(:link2) { '<a href="https://github.com/LeSim" target="_blank" rel="noopener">https://github.com/LeSim</a>' }
|
||||
|
||||
it "render links" do
|
||||
expect(subject).to include(link1)
|
||||
expect(subject).to include(link2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with a dossier champ, but we are not authorized to acces the dossier" do
|
||||
|
|
Loading…
Reference in a new issue