Module: PermalinkFu
- Defined in:
- lib/permalink_fu.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
-
.escape(str) ⇒ Object
This method does the actual permalink escaping.
Instance Method Summary collapse
Class Method Details
.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 |
Instance Method Details
#has_permalink(attr_names = [], permalink_field = nil, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/permalink_fu.rb', line 5 def has_permalink(attr_names = [], permalink_field = nil, = {}) if permalink_field.is_a?(Hash) = permalink_field permalink_field = nil end ClassMethods.setup_permalink_fu_on self do self.permalink_attributes = Array(attr_names) self.permalink_field = (permalink_field || 'permalink').to_s self. = {:unique => true}.update() end include InstanceMethods end |