Sha256: 56fcb6e55530b3d1918f2b42cdecd52cd8c65176cbc85a714f6b8b40036bebbd
Contents?: true
Size: 768 Bytes
Versions: 5
Compression:
Stored size: 768 Bytes
Contents
# typed: true # frozen_string_literal: false require 'htmlentities' require 'singleton' require 'sorbet-runtime' module LinkHelper extend T::Sig sig { params(str: String, salt: String).returns(String) } 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 sig { void } def reset_ids_generation @ids = {} end sig { params(string: String).returns(String) } def slugify(string) HTMLEntities.new .decode(string) .gsub(%r{</?[^>]*>}, '') .gsub(/\s/, '-') .gsub(%r{[\[\]()/",`'&<>\.*]}, '') .downcase end end
Version data entries
5 entries across 5 versions & 1 rubygems