Class: Inkling::Path
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Inkling::Path
- Defined in:
- app/models/inkling/path.rb
Overview
an associated object which tracks all the relative URL paths to content in the system
Instance Method Summary collapse
-
#restricts?(sub_path) ⇒ Boolean
called before adding a new child path to see if the content object restricts what it’s path should nest if there isn’t a restricts() impl.
- #slug_unique? ⇒ Boolean
-
#sluggerize(slug) ⇒ Object
stolen from enki.
- #update_slug! ⇒ Object
Instance Method Details
#restricts?(sub_path) ⇒ Boolean
called before adding a new child path to see if the content object restricts what it’s path should nest if there isn’t a restricts() impl. on the content object, false is returned, allowing anything to be nested
19 20 21 22 23 24 25 |
# File 'app/models/inkling/path.rb', line 19 def restricts?(sub_path) if self.content self.content.restricts?(sub_path.content) if self.content.respond_to? :restricts? else false end end |
#slug_unique? ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'app/models/inkling/path.rb', line 46 def slug_unique? pre_existing = Inkling::Path.find_by_slug(self.slug) if pre_existing and (self.new_record? or (pre_existing.id != self.id)) self.errors.add("path (#{self.slug}) already taken by another object in this website ") end end |
#sluggerize(slug) ⇒ Object
stolen from enki
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/inkling/path.rb', line 34 def sluggerize(slug) slug.downcase! slug.gsub!(/&(\d)+;/, '') # Ditch Entities slug.gsub!('&', 'and') # Replace & with 'and' slug.gsub!(/['"]/, '') # replace quotes by nothing slug.gsub!(/\ +/, '-') # replace all white space sections with a dash slug.gsub!(/(-)$/, '') # trim dashes slug.gsub!(/^(-)/, '') # trim dashes slug.gsub!(/[^\/a-zA-Z0-9\-]/, '-') # Get rid of anything we don't like slug end |
#update_slug! ⇒ Object
27 28 29 30 31 |
# File 'app/models/inkling/path.rb', line 27 def update_slug! slug = self.parent ? "#{self.parent.slug}/" : "/" slug += "#{self.content.title}" self.slug = sluggerize(slug) end |