Class: ContentDriven::Page

Inherits:
Hash
  • Object
show all
Extended by:
DSL, Hooks
Includes:
Routes
Defined in:
lib/content_driven/page.rb

Overview

ContentDriven defines a tree of content. Page is the base class. A Page has a parent and zero or more children

Direct Known Subclasses

Article, Blog, BlogPost, Site, Tag, TagCloud

Instance Attribute Summary collapse

Attributes included from Hooks

#after_hooks

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL

define_dsl_for

Methods included from Hooks

after, call_after_hooks

Methods included from Routes

#content_for

Constructor Details

#initialize(&block) ⇒ Page

Returns a new instance of Page.



24
25
26
27
28
29
# File 'lib/content_driven/page.rb', line 24

def initialize &block
  if block_given?
    self.instance_eval &block
  end
  self.class.call_after_hooks
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



13
14
15
# File 'lib/content_driven/page.rb', line 13

def date
  @date
end

#parentObject

Returns the value of attribute parent.



13
14
15
# File 'lib/content_driven/page.rb', line 13

def parent
  @parent
end

#titleObject

Returns the value of attribute title.



13
14
15
# File 'lib/content_driven/page.rb', line 13

def title
  @title
end

#urlObject

Returns the value of attribute url.



13
14
15
# File 'lib/content_driven/page.rb', line 13

def url
  @url
end

Class Method Details

.inherited(subclass) ⇒ Object

Extend the DSL when Page is subclasses



20
21
22
# File 'lib/content_driven/page.rb', line 20

def self.inherited(subclass)
  define_dsl_for(subclass)
end

Instance Method Details

#add_child(key, page = nil) ⇒ Object

Add a child page. You will seldom need to call this directly. Instead use add_blog or add_article



33
34
35
36
37
38
39
40
# File 'lib/content_driven/page.rb', line 33

def add_child key, page = nil
  if key.is_a? Page
    page, key = key, (self.keys.length + 1).to_sym
  end
  page.parent = self
  page.url = key
  self[key] = page
end

#childrenObject



52
53
54
# File 'lib/content_driven/page.rb', line 52

def children
  self
end

#root?Boolean

Is this a root page, i.e. it has no parent?

Returns:

  • (Boolean)


43
44
45
# File 'lib/content_driven/page.rb', line 43

def root?
  self.parent.nil?
end

#to_symObject

Returns the URL fragment as a symbol, or :root if it is the root page



48
49
50
# File 'lib/content_driven/page.rb', line 48

def to_sym
  root? ? :root : self.url.to_sym
end