Class: ContentDriven::Page
- Inherits:
-
Hash
- Object
- Hash
- ContentDriven::Page
- 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
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Attributes included from Hooks
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
Extend the DSL when Page is subclasses.
Instance Method Summary collapse
-
#add_child(key, page = nil) ⇒ Object
Add a child page.
- #children ⇒ Object
-
#initialize(&block) ⇒ Page
constructor
A new instance of Page.
-
#root? ⇒ Boolean
Is this a root page, i.e.
-
#to_sym ⇒ Object
Returns the URL fragment as a symbol, or :root if it is the root page.
Methods included from DSL
Methods included from Hooks
Methods included from Routes
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
#date ⇒ Object
Returns the value of attribute date.
13 14 15 |
# File 'lib/content_driven/page.rb', line 13 def date @date end |
#parent ⇒ Object
Returns the value of attribute parent.
13 14 15 |
# File 'lib/content_driven/page.rb', line 13 def parent @parent end |
#title ⇒ Object
Returns the value of attribute title.
13 14 15 |
# File 'lib/content_driven/page.rb', line 13 def title @title end |
#url ⇒ Object
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 |
#children ⇒ Object
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?
43 44 45 |
# File 'lib/content_driven/page.rb', line 43 def root? self.parent.nil? end |
#to_sym ⇒ Object
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 |