Class: Nanoc::Layout
- Inherits:
-
Object
- Object
- Nanoc::Layout
- Extended by:
- Memoization
- Defined in:
- lib/nanoc/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)
-
- (Hash) attributes
readonly
This layout’s attributes.
-
- (String) identifier
This layout’s identifier, starting and ending with a slash.
-
- (String) raw_content
readonly
The raw content of this layout.
Instance Method Summary (collapse)
-
- (Object) ==(other)
-
- (Object) [](key)
Requests the attribute with the given key.
-
- (String) checksum
The checksum for this object.
-
- (Boolean) eql?(other)
-
- (void) freeze
Prevents all further modifications to the layout.
-
- (Object) hash
-
- (Layout) initialize(raw_content, attributes, identifier, params = nil)
constructor
Creates a new layout.
-
- (Object) inspect
-
- (Object) marshal_dump
-
- (Object) marshal_load(source)
-
- (Object) mtime
deprecated
Deprecated.
Access the modification time using
layout[:mtime]
instead. -
- (Object) reference
private
Returns an object that can be used for uniquely identifying objects.
-
- (Symbol) type
private
Returns the type of this object.
Methods included from Memoization
Constructor Details
- (Layout) initialize(raw_content, attributes, identifier, params = nil)
Creates a new layout.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nanoc/base/source_data/layout.rb', line 36 def initialize(raw_content, attributes, identifier, params = nil) @raw_content = raw_content @attributes = attributes.symbolize_keys_recursively @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
- (Hash) attributes (readonly)
Returns This layout’s attributes
15 16 17 |
# File 'lib/nanoc/base/source_data/layout.rb', line 15 def attributes @attributes end |
- (String) identifier
Returns This layout’s identifier, starting and ending with a slash
19 20 21 |
# File 'lib/nanoc/base/source_data/layout.rb', line 19 def identifier @identifier end |
- (String) raw_content (readonly)
Returns The raw content of this layout
12 13 14 |
# File 'lib/nanoc/base/source_data/layout.rb', line 12 def raw_content @raw_content end |
Instance Method Details
- (Object) ==(other)
103 104 105 |
# File 'lib/nanoc/base/source_data/layout.rb', line 103 def ==(other) self.eql?(other) end |
- (Object) [](key)
Requests the attribute with the given key.
52 53 54 |
# File 'lib/nanoc/base/source_data/layout.rb', line 52 def [](key) @attributes[key] end |
- (String) checksum
Returns The checksum for this object. If its contents change, the checksum will change as well.
90 91 92 |
# File 'lib/nanoc/base/source_data/layout.rb', line 90 def checksum Nanoc::Checksummer.calc(self) end |
- (Boolean) eql?(other)
99 100 101 |
# File 'lib/nanoc/base/source_data/layout.rb', line 99 def eql?(other) self.class == other.class && identifier == other.identifier end |
- (void) freeze
This method returns an undefined value.
Prevents all further modifications to the layout.
69 70 71 72 73 |
# File 'lib/nanoc/base/source_data/layout.rb', line 69 def freeze attributes.freeze_recursively identifier.freeze raw_content.freeze end |
- (Object) hash
95 96 97 |
# File 'lib/nanoc/base/source_data/layout.rb', line 95 def hash self.class.hash ^ identifier.hash end |
- (Object) inspect
84 85 86 |
# File 'lib/nanoc/base/source_data/layout.rb', line 84 def inspect "<#{self.class} identifier=\"#{identifier}\">" end |
- (Object) marshal_dump
107 108 109 110 111 112 113 |
# File 'lib/nanoc/base/source_data/layout.rb', line 107 def marshal_dump [ @raw_content, @attributes, @identifier ] end |
- (Object) marshal_load(source)
115 116 117 118 119 |
# File 'lib/nanoc/base/source_data/layout.rb', line 115 def marshal_load(source) @raw_content, @attributes, @identifier = *source end |
- (Object) mtime
Access the modification time using layout[:mtime]
instead.
122 123 124 |
# File 'lib/nanoc/base/source_data/layout.rb', line 122 def mtime self[:mtime] end |
- (Object) reference
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/nanoc/base/source_data/layout.rb', line 80 def reference [ type, identifier ] end |
- (Symbol) type
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/nanoc/base/source_data/layout.rb', line 62 def type :layout end |