Class: Nanoc3::Layout
- Inherits:
-
Object
- Object
- Nanoc3::Layout
- Extended by:
- Memoization
- Defined in:
- lib/nanoc3/base/source_data/layout.rb
Overview
Represents a layout in a nanoc site. It has content, attributes, an identifier and a modification time (to speed up compilation).
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
This layout’s attributes.
-
#identifier ⇒ String
This layout’s identifier, starting and ending with a slash.
-
#raw_content ⇒ String
readonly
The raw content of this layout.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#[](key) ⇒ Object
Requests the attribute with the given key.
-
#checksum ⇒ String
The checksum for this object.
- #eql?(other) ⇒ Boolean
-
#freeze ⇒ void
Prevents all further modifications to the layout.
- #hash ⇒ Object
-
#initialize(raw_content, attributes, identifier, params = nil) ⇒ Layout
constructor
Creates a new layout.
- #inspect ⇒ Object
- #marshal_dump ⇒ Object
- #marshal_load(source) ⇒ Object
-
#mtime ⇒ Object
deprecated
Deprecated.
Access the modification time using ‘layout` instead.
-
#reference ⇒ Object
private
Returns an object that can be used for uniquely identifying objects.
-
#type ⇒ Symbol
private
Returns the type of this object.
Methods included from Memoization
Constructor Details
#initialize(raw_content, attributes, identifier, params = nil) ⇒ Layout
Creates a new layout.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 36 def initialize(raw_content, attributes, identifier, params=nil) @raw_content = raw_content @attributes = attributes.symbolize_keys @identifier = identifier.cleaned_identifier.freeze # Set mtime params ||= {} params = { :mtime => params } if params.is_a?(Time) @attributes.merge(:mtime => params[:mtime]) if params[:mtime] end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
Returns This layout’s attributes.
15 16 17 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 15 def attributes @attributes end |
#identifier ⇒ String
Returns This layout’s identifier, starting and ending with a slash.
19 20 21 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 19 def identifier @identifier end |
#raw_content ⇒ String (readonly)
Returns The raw content of this layout.
12 13 14 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 12 def raw_content @raw_content end |
Instance Method Details
#==(other) ⇒ Object
105 106 107 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 105 def ==(other) self.eql?(other) end |
#[](key) ⇒ Object
Requests the attribute with the given key.
52 53 54 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 52 def [](key) @attributes[key] end |
#checksum ⇒ String
Returns The checksum for this object. If its contents change, the checksum will change as well.
90 91 92 93 94 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 90 def checksum attributes = @attributes.dup attributes.delete(:file) @raw_content.checksum + ',' + attributes.checksum end |
#eql?(other) ⇒ Boolean
101 102 103 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 101 def eql?(other) self.class == other.class && self.identifier == other.identifier end |
#freeze ⇒ void
This method returns an undefined value.
Prevents all further modifications to the layout.
69 70 71 72 73 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 69 def freeze attributes.freeze_recursively identifier.freeze raw_content.freeze end |
#hash ⇒ Object
97 98 99 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 97 def hash self.class.hash ^ self.identifier.hash end |
#inspect ⇒ Object
84 85 86 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 84 def inspect "<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier}>" end |
#marshal_dump ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 109 def marshal_dump [ @raw_content, @attributes, @identifier ] end |
#marshal_load(source) ⇒ Object
117 118 119 120 121 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 117 def marshal_load(source) @raw_content, @attributes, @identifier = *source end |
#mtime ⇒ Object
Access the modification time using ‘layout` instead.
124 125 126 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 124 def mtime self[:mtime] end |
#reference ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an object that can be used for uniquely identifying objects.
80 81 82 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 80 def reference [ type, self.identifier ] end |
#type ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the type of this object. Will always return ‘:layout`, because this is a layout. For items, this method returns `:item`.
62 63 64 |
# File 'lib/nanoc3/base/source_data/layout.rb', line 62 def type :layout end |