Class: Panda::CMS::Slug
- Inherits:
-
Object
- Object
- Panda::CMS::Slug
- Defined in:
- lib/panda/cms/slug.rb
Class Method Summary collapse
-
.generate(string) ⇒ Object
Generates a slug from a provided string.
Class Method Details
.generate(string) ⇒ Object
Generates a slug from a provided string
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/panda/cms/slug.rb', line 12 def self.generate(string) # Trim whitespace and downcase the string string = string.to_s.strip.downcase # Replace & with "and" string = string.gsub("&", "and") # Remove special characters string = string.gsub(%r{[!@£\\\^\[\]/]+}, "") # Replace any whitespace character with - string = string.gsub(/[^\w\s-]/, "-") # Replace multiple occurences of _ and - with - string.gsub(/[\s_-]+/, "-") end |