Module: Slug
- Defined in:
- lib/slug.rb
Constant Summary collapse
- CHAR_FILTER_REGEXP =
:/?#[]@!$&‘()*+,;=_.~%`^|{}“<>
/[:\/\?#\[\]@!\$&'\(\)\*\+,;=_\.~%\\`^\s|\{\}"<>]+/
- MAX_LENGTH =
255
Class Method Summary collapse
Class Method Details
.for(string, default = "topic", max_length = MAX_LENGTH, method: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/slug.rb', line 8 def self.for(string, default = "topic", max_length = MAX_LENGTH, method: nil) string = string.gsub(/:([\w\-+]+(?::t\d)?):/, "") if string.present? # strip emoji strings method = (method || SiteSetting.slug_generation_method || :ascii).to_sym max_length = 9999 if method == :encoded # do not truncate encoded slugs slug = case method when :ascii self.ascii_generator(string) when :encoded self.encoded_generator(string) when :none self.none_generator(string) end slug = self.prettify_slug(slug, max_length: max_length) (slug.blank? || slug_is_only_numbers?(slug)) ? default : slug end |