Guest User

Untitled

a guest
Jul 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class String
  2. def to_slug
  3. s = self.gsub(/&/, 'and') # replace ampersand chars with 'and' before stripping HTML
  4. s.gsub!(/<.*?>/, '') # strip HTML
  5. s.gsub!(/&/, 'and') # replace ampersand chars with 'and'
  6. s = Iconv.iconv('ascii//ignore//translit', 'utf-8', s).to_s # Borrowed partially from Technoweenie's PermalinkFu
  7. s.gsub!(/\W+/, ' ') # all non-word chars to spaces
  8. s.strip!
  9. s.downcase!
  10. s.gsub!(/[\W^-_]+/, '-') # replace non-word chars with dashes
  11. s.gsub!(/\-{2}/, '-') # remove double dashes
  12. s
  13. end
  14. end
Add Comment
Please, Sign In to add comment