Class: Tenon::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/tenon/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reorder!(list, parent_id) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/tenon/page.rb', line 47

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

Returns:

  • (Boolean)


70
71
72
# File 'app/models/tenon/page.rb', line 70

def published?
  publish_at.present? ? publish_at <= Time.now : false
end

#siblings_for_menuObject



39
40
41
42
43
44
45
# File 'app/models/tenon/page.rb', line 39

def siblings_for_menu
  if parent
    parent.subpages_for_menu
  else
    []
  end
end

#subpages_for_menuObject

Return siblings if subpages aren’t available



31
32
33
34
35
36
37
# File 'app/models/tenon/page.rb', line 31

def subpages_for_menu
  if subpages.blank?
    siblings_for_menu
  else
    subpages.for_menu
  end
end