Class: Page

Inherits:
Content
  • Object
show all
Defined in:
app/models/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Content

#author_name, #body_html, #publish!, #published=, #published?, #status, #status=

Class Method Details

.rootObject



15
16
17
# File 'app/models/page.rb', line 15

def self.root
  roots.first
end

Instance Method Details

#ancestorsObject



24
25
26
27
28
# File 'app/models/page.rb', line 24

def ancestors
  node, nodes = self, []
  nodes << node = node.parent while node.parent
  nodes
end

#root?Boolean Also known as: homepage?

Returns:

  • (Boolean)


19
20
21
# File 'app/models/page.rb', line 19

def root?
  self == Page.root || Page.count == 0 && new_record?
end

#urlObject



30
31
32
33
34
# File 'app/models/page.rb', line 30

def url
  links = (ancestors.map(&:permalink) << permalink).delete_if(&:blank?)
  
  "/#{links.join('/')}"
end