Class: PandaCms::Slug
- Inherits:
-
Object
- Object
- PandaCms::Slug
- Defined in:
- app/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
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/lib/panda_cms/slug.rb', line 9 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(/[\!\@\£\$\%\^\&\*\(\)\+\=\{\}\[\]\:\;\"\'\|\\\`\<\>\?\,\.\/]+/, "") # Replace any whitespace character with - string = string.gsub(/[^\w\s-]/, "-") # Replace multiple occurences of _ and - with - string.gsub(/[\s_-]+/, "-") end |