Module: Inkling::Slugs

Defined in:
lib/inkling/slugs.rb

Instance Method Summary collapse

Instance Method Details

#sluggerize(slug) ⇒ Object

copied from enki see www.enkiblog.com/



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/inkling/slugs.rb', line 4

def sluggerize(slug)
  text = slug.dup
  text.downcase!
  text.gsub!(/&(\d)+;/, '') # Ditch Entities
  text.gsub!('&', 'and') # Replace & with 'and'
  text.gsub!(/['"]/, '') # replace quotes by nothing
  text.gsub!(/\ +/, '-') # replace all white space sections with a dash
  text.gsub!(/(-)$/, '') # trim dashes
  text.gsub!(/^(-)/, '') # trim dashes
  text.gsub!(/[^\/a-zA-Z0-9\-]/, '-') # Get rid of anything we don't like
  text
end