Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Defined in:
- lib/forge/app/models/page.rb
Class Method Summary collapse
-
.find_by_slug!(slug) ⇒ Object
this will be included in rails automatically soon.
- .reorder!(list, parent_id) ⇒ Object
Instance Method Summary collapse
- #breadcrumb(separator = ' > ') ⇒ Object
- #list_title ⇒ Object
- #option_title ⇒ Object
- #parents ⇒ Object
-
#subpages_for_menu ⇒ Object
Return siblings if subpages aren’t available.
- #top_parent ⇒ Object
Class Method Details
.find_by_slug!(slug) ⇒ Object
this will be included in rails automatically soon
33 34 35 |
# File 'lib/forge/app/models/page.rb', line 33 def self.find_by_slug!(slug) self.find_by_slug(slug) or raise ActiveRecord::RecordNotFound, "could not find page '#{slug}'" end |
.reorder!(list, parent_id) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/forge/app/models/page.rb', line 78 def self.reorder!(list, parent_id) unless list.blank? pages = [] # Move all the pages to the right parent_id first list.each_with_index do |id,order| pages << Page.find_by_id(id) if pages[order] && parent_id pages[order].move_to_child_of(parent_id) end end # Then give them the ol shuffle first_page = pages[0] previous_page = first_page pages.each_with_index do |page, order| next if order == 0 page = pages[order] page.move_to_right_of(previous_page) page.save previous_page = page end end end |
Instance Method Details
#breadcrumb(separator = ' > ') ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/forge/app/models/page.rb', line 46 def (separator = ' > ') parent, pages = self.parent, [self.title] while parent pages << parent.title parent = parent.parent end pages.reverse.join(separator) end |
#list_title ⇒ Object
64 65 66 67 68 |
# File 'lib/forge/app/models/page.rb', line 64 def list_title title = self.title.size > 64 ? self.title[0..64].strip + '...' : self.title title = self.published? ? title : title + " (Draft)" return title end |
#option_title ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/forge/app/models/page.rb', line 70 def option_title ot = '' ot << " " * ((depth || 0) * 3) ot << "- " if (depth || 0) > 0 ot << title ot.html_safe end |
#parents ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/forge/app/models/page.rb', line 37 def parents parent, parents = self.parent, [] while parent parents << parent parent = parent.parent end return parents end |
#subpages_for_menu ⇒ Object
Return siblings if subpages aren’t available
24 25 26 27 28 29 30 |
# File 'lib/forge/app/models/page.rb', line 24 def if subpages.blank? Page.where(:published => true, :show_in_menu => true, :parent_id => parent_id) unless parent_id.blank? else subpages.where(:published => true, :show_in_menu => true) end end |
#top_parent ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/forge/app/models/page.rb', line 55 def top_parent parent, parents = self.parent, [self] while parent parents << self parent = parent.parent end return parents.last end |