Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class String
- def to_slug
- s = self.gsub(/&/, 'and') # replace ampersand chars with 'and' before stripping HTML
- s.gsub!(/<.*?>/, '') # strip HTML
- s.gsub!(/&/, 'and') # replace ampersand chars with 'and'
- s = Iconv.iconv('ascii//ignore//translit', 'utf-8', s).to_s # Borrowed partially from Technoweenie's PermalinkFu
- s.gsub!(/\W+/, ' ') # all non-word chars to spaces
- s.strip!
- s.downcase!
- s.gsub!(/[\W^-_]+/, '-') # replace non-word chars with dashes
- s.gsub!(/\-{2}/, '-') # remove double dashes
- s
- end
- end
Add Comment
Please, Sign In to add comment