Method: PermalinkFu.escape
- Defined in:
- lib/permalink_fu.rb
.escape(str) ⇒ Object
This method does the actual permalink escaping.
21 22 23 24 25 26 27 28 29 |
# File 'lib/permalink_fu.rb', line 21 def escape(str) s = ClassMethods.decode(str)#.force_encoding("UTF-8") s.gsub!(/[^\x00-\x7F]+/, '') # Remove anything non-ASCII entirely (e.g. diacritics). s.gsub!(/[^\w_ \-]+/i, '') # Remove unwanted chars. s.gsub!(/[ \-]+/i, '-') # No more than one of the separator in a row. s.gsub!(/^\-|\-$/i, '') # Remove leading/trailing separator. s.downcase! s.size == 0 ? ClassMethods.random_permalink(str) : s end |