Parent

Class/Module Index [+]

Quicksearch

Nanoc::Layout

Represents a layout in a nanoc site. It has content, attributes, an identifier and a modification time (to speed up compilation).

Attributes

attributes[R]

@return [Hash] This layout's attributes

identifier[RW]

@return [String] This layout's identifier, starting and ending with a

slash
raw_content[R]

@return [String] The raw content of this layout

Public Class Methods

new(raw_content, attributes, identifier, params=nil) click to toggle source

Creates a new layout.

@param [String] raw_content The raw content of this layout.

@param [Hash] attributes A hash containing this layout's attributes.

@param [String] identifier This layout's identifier.

@param [Time, Hash] params Extra parameters. For backwards

compatibility, this can be a Time instance indicating the time when
this layout was last modified (mtime).

@option params [Time, nil] :mtime (nil) The time when this layout was

last modified. Deprecated; pass the modification time as the `:mtime`
attribute instead.
# File lib/nanoc/base/source_data/layout.rb, line 35
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

Public Instance Methods

==(other) click to toggle source
# File lib/nanoc/base/source_data/layout.rb, line 104
def ==(other)
  self.eql?(other)
end
[](key) click to toggle source

Requests the attribute with the given key.

@param [Symbol] key The name of the attribute to fetch.

@return [Object] The value of the requested attribute.

# File lib/nanoc/base/source_data/layout.rb, line 51
def [](key)
  @attributes[key]
end
checksum() click to toggle source

@return [String] The checksum for this object. If its contents change,

the checksum will change as well.
# File lib/nanoc/base/source_data/layout.rb, line 89
def checksum
  attributes = @attributes.dup
  attributes.delete(:file)
  @raw_content.checksum + ',' + attributes.checksum
end
eql?(other) click to toggle source
# File lib/nanoc/base/source_data/layout.rb, line 100
def eql?(other)
  self.class == other.class && self.identifier == other.identifier
end
freeze() click to toggle source

Prevents all further modifications to the layout.

@return [void]

# File lib/nanoc/base/source_data/layout.rb, line 68
def freeze
  attributes.freeze_recursively
  identifier.freeze
  raw_content.freeze
end
hash() click to toggle source
# File lib/nanoc/base/source_data/layout.rb, line 96
def hash
  self.class.hash ^ self.identifier.hash
end
inspect() click to toggle source
# File lib/nanoc/base/source_data/layout.rb, line 83
def inspect
  "<#{self.class} identifier=\"#{self.identifier}\">"
end
marshal_dump() click to toggle source
# File lib/nanoc/base/source_data/layout.rb, line 108
def marshal_dump
  [
    @raw_content,
    @attributes,
    @identifier
  ]
end
marshal_load(source) click to toggle source
# File lib/nanoc/base/source_data/layout.rb, line 116
def marshal_load(source)
  @raw_content,
  @attributes,
  @identifier = *source
end
mtime() click to toggle source

@deprecated Access the modification time using `layout` instead.

# File lib/nanoc/base/source_data/layout.rb, line 123
def mtime
  self[:mtime]
end
reference() click to toggle source

Returns an object that can be used for uniquely identifying objects.

@api private

@return [Object] An unique reference to this object

# File lib/nanoc/base/source_data/layout.rb, line 79
def reference
  [ type, self.identifier ]
end
type() click to toggle source

Returns the type of this object. Will always return `:layout`, because this is a layout. For items, this method returns `:item`.

@api private

@return [Symbol] :layout

# File lib/nanoc/base/source_data/layout.rb, line 61
def type
  :layout
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.