Class: Tenon::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tenon::Page
- Defined in:
- app/models/tenon/page.rb
Class Method Summary collapse
Instance Method Summary collapse
- #published? ⇒ Boolean
- #siblings_for_menu ⇒ Object
-
#subpages_for_menu ⇒ Object
Return siblings if subpages aren’t available.
Class Method Details
.reorder!(list, parent_id) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/tenon/page.rb', line 41 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) pages[order].move_to_child_of(parent_id) if pages[order] && parent_id 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
#published? ⇒ Boolean
64 65 66 |
# File 'app/models/tenon/page.rb', line 64 def published? publish_at.present? ? publish_at <= Time.now : false end |
#siblings_for_menu ⇒ Object
37 38 39 |
# File 'app/models/tenon/page.rb', line 37 def parent. if parent end |
#subpages_for_menu ⇒ Object
Return siblings if subpages aren’t available
29 30 31 32 33 34 35 |
# File 'app/models/tenon/page.rb', line 29 def if subpages.blank? else subpages.where(published: true, show_in_menu: true) end end |