Module: BlogLogic::Base
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- @@sluggable_attribute =
nil
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
13 14 15 |
# File 'lib/blog_logic/base.rb', line 13 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#make_slug ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/blog_logic/base.rb', line 17 def make_slug if self.desired_slug && ! self.desired_slug.blank? text = self.desired_slug elsif self.slug text = self.slug elsif self.respond_to?(:page_title) text = self.page_title.to_s.downcase elsif self.respond_to?(:name) text = self.name.to_s.downcase end # Translation borrowed from permalink_fu text = text.to_s text.gsub!(/[^\x00-\x7F]+/, '-') # Remove anything non-ASCII entirely (e.g. diacritics). text.gsub!(/[^\/\w_ \-]+/i, '-') # Remove unwanted chars. text.gsub!(/[ \-]+/i, '-') # No more than one of the separator in a row. text.gsub!(/^\-|\-$/i, '') # Remove leading/trailing separator. text.downcase! self.slug = text end |