Class: Nanoc2::Template
- Inherits:
-
Object
- Object
- Nanoc2::Template
- Defined in:
- lib/nanoc2/base/template.rb
Overview
A Nanoc2::Template represents a template, which can be used for creating new pages. Pages don’t necessary have to be created using templates, but they can be useful for generating pages where you only have to “fill in the blanks”.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of this template.
-
#page_attributes ⇒ Object
readonly
A hash containing the attributes a page created using this template will have.
-
#page_content ⇒ Object
readonly
The raw content a page created using this template will have.
-
#site ⇒ Object
The Nanoc2::Site this template belongs to.
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes the template.
-
#initialize(page_content, page_attributes, name) ⇒ Template
constructor
Creates a new template.
-
#move_to(new_name) ⇒ Object
Renames the template.
-
#save ⇒ Object
Saves the template in the database, creating it if it doesn’t exist yet or updating it if it already exists.
Constructor Details
#initialize(page_content, page_attributes, name) ⇒ Template
Creates a new template.
name
-
The name of this template.
page_content
-
The raw content a page created using this template will have.
page_attributes
-
A hash containing the attributes a page created using this template will have.
31 32 33 34 35 |
# File 'lib/nanoc2/base/template.rb', line 31 def initialize(page_content, page_attributes, name) @page_content = page_content @page_attributes = page_attributes.clean @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of this template.
13 14 15 |
# File 'lib/nanoc2/base/template.rb', line 13 def name @name end |
#page_attributes ⇒ Object (readonly)
A hash containing the attributes a page created using this template will have.
20 21 22 |
# File 'lib/nanoc2/base/template.rb', line 20 def page_attributes @page_attributes end |
#page_content ⇒ Object (readonly)
The raw content a page created using this template will have.
16 17 18 |
# File 'lib/nanoc2/base/template.rb', line 16 def page_content @page_content end |
#site ⇒ Object
The Nanoc2::Site this template belongs to.
10 11 12 |
# File 'lib/nanoc2/base/template.rb', line 10 def site @site end |
Instance Method Details
#delete ⇒ Object
Deletes the template. Tells the site’s data source to delete the template.
56 57 58 59 60 |
# File 'lib/nanoc2/base/template.rb', line 56 def delete @site.data_source.loading do @site.data_source.delete_template(self) end end |
#move_to(new_name) ⇒ Object
Renames the template. Tells the site’s data source to rename the template.
48 49 50 51 52 |
# File 'lib/nanoc2/base/template.rb', line 48 def move_to(new_name) @site.data_source.loading do @site.data_source.move_template(self, new_name) end end |
#save ⇒ Object
Saves the template in the database, creating it if it doesn’t exist yet or updating it if it already exists. Tells the site’s data source to save the template.
40 41 42 43 44 |
# File 'lib/nanoc2/base/template.rb', line 40 def save @site.data_source.loading do @site.data_source.save_template(self) end end |