Module: LinkHelper
- Extended by:
- T::Sig
- Defined in:
- lib/frontman/helpers/link_helper.rb
Instance Method Summary collapse
Instance Method Details
#generate_id(str, salt = '') ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/frontman/helpers/link_helper.rb', line 12 def generate_id(str, salt = '') id = slugify(str) @ids ||= {} @ids[salt.to_s + id] ||= 0 @ids[salt.to_s + id] += 1 @ids[salt.to_s + id] == 1 ? id : "#{id}-#{@ids[salt.to_s + id]}" end |
#reset_ids_generation ⇒ Object
22 23 24 |
# File 'lib/frontman/helpers/link_helper.rb', line 22 def reset_ids_generation @ids = {} end |
#slugify(string) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/frontman/helpers/link_helper.rb', line 27 def slugify(string) HTMLEntities.new .decode(string) .gsub(%r{</?[^>]*>}, '') .gsub(/\s/, '-') .gsub(%r{[\[\]()/",`'&<>\.*]}, '') .downcase end |