Class: Nanoc2::Layout
- Inherits:
-
Object
- Object
- Nanoc2::Layout
- Defined in:
- lib/nanoc2/base/layout.rb
Overview
A Nanoc2::Layout represents a layout in a nanoc site. It has content, attributes (for determining which filter to use for laying out a page), a path (because layouts are organised hierarchically), and a modification time (to speed up compilation).
Constant Summary collapse
- DEFAULTS =
Default values for layouts.
{ :filter => 'erb' }
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
A hash containing this layout’s attributes.
-
#content ⇒ Object
readonly
The raw content of this layout.
-
#mtime ⇒ Object
readonly
The time when this layout was last modified.
-
#path ⇒ Object
readonly
This layout’s path, starting and ending with a slash.
-
#site ⇒ Object
The Nanoc2::Site this layout belongs to.
Instance Method Summary collapse
-
#attribute_named(name) ⇒ Object
Returns the attribute with the given name.
-
#delete ⇒ Object
Deletes the layout.
-
#filter_class ⇒ Object
Returns the filter class needed for this layout.
-
#initialize(content, attributes, path, mtime = nil) ⇒ Layout
constructor
Creates a new layout.
- #inspect ⇒ Object
-
#move_to(new_path) ⇒ Object
Moves the layout to a new path.
-
#save ⇒ Object
Saves the layout in the database, creating it if it doesn’t exist yet or updating it if it already exists.
-
#to_proxy ⇒ Object
Returns a proxy (Nanoc2::LayoutProxy) for this layout.
Constructor Details
#initialize(content, attributes, path, mtime = nil) ⇒ Layout
Creates a new layout.
content
-
The raw content of this layout.
attributes
-
A hash containing this layout’s attributes.
path
-
This layout’s path, starting and ending with a slash.
mtime
-
The time when this layout was last modified.
38 39 40 41 42 43 |
# File 'lib/nanoc2/base/layout.rb', line 38 def initialize(content, attributes, path, mtime=nil) @content = content @attributes = attributes.clean @path = path.cleaned_path @mtime = mtime end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
A hash containing this layout’s attributes.
21 22 23 |
# File 'lib/nanoc2/base/layout.rb', line 21 def attributes @attributes end |
#content ⇒ Object (readonly)
The raw content of this layout.
18 19 20 |
# File 'lib/nanoc2/base/layout.rb', line 18 def content @content end |
#mtime ⇒ Object (readonly)
The time when this layout was last modified.
27 28 29 |
# File 'lib/nanoc2/base/layout.rb', line 27 def mtime @mtime end |
#path ⇒ Object (readonly)
This layout’s path, starting and ending with a slash.
24 25 26 |
# File 'lib/nanoc2/base/layout.rb', line 24 def path @path end |
#site ⇒ Object
The Nanoc2::Site this layout belongs to.
15 16 17 |
# File 'lib/nanoc2/base/layout.rb', line 15 def site @site end |
Instance Method Details
#attribute_named(name) ⇒ Object
Returns the attribute with the given name.
51 52 53 54 |
# File 'lib/nanoc2/base/layout.rb', line 51 def attribute_named(name) return @attributes[name] if @attributes.has_key?(name) return DEFAULTS[name] end |
#delete ⇒ Object
Deletes the layout. Tells the site’s data source to delete the layout.
79 80 81 82 83 |
# File 'lib/nanoc2/base/layout.rb', line 79 def delete @site.data_source.loading do @site.data_source.delete_layout(self) end end |
#filter_class ⇒ Object
Returns the filter class needed for this layout.
57 58 59 |
# File 'lib/nanoc2/base/layout.rb', line 57 def filter_class Nanoc2::Filter.named(attribute_named(:filter)) end |
#inspect ⇒ Object
85 86 87 |
# File 'lib/nanoc2/base/layout.rb', line 85 def inspect "<#{self.class} path=#{self.path}>" end |
#move_to(new_path) ⇒ Object
Moves the layout to a new path. Tells the site’s data source to move the layout.
72 73 74 75 76 |
# File 'lib/nanoc2/base/layout.rb', line 72 def move_to(new_path) @site.data_source.loading do @site.data_source.move_layout(self, new_path) end end |
#save ⇒ Object
Saves the layout 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 layout.
64 65 66 67 68 |
# File 'lib/nanoc2/base/layout.rb', line 64 def save @site.data_source.loading do @site.data_source.save_layout(self) end end |
#to_proxy ⇒ Object
Returns a proxy (Nanoc2::LayoutProxy) for this layout.
46 47 48 |
# File 'lib/nanoc2/base/layout.rb', line 46 def to_proxy @proxy ||= LayoutProxy.new(self) end |