Class: Nanoc3::Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc3/base/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)

Instance Method Summary (collapse)

Constructor Details

- (Layout) initialize(raw_content, attributes, identifier, params_or_mtime = nil)

Creates a new layout.

layout, or the time when this layout was last modified (deprecated).

layout was last modified

Parameters:

  • raw_content (String)

    The raw content of this layout.

  • attributes (Hash)

    A hash containing this layout's attributes.

  • identifier (String)

    This layout's identifier.

  • params_or_mtime (Time, Hash, nil) (defaults to: nil)

    Extra parameters for the

Options Hash (params_or_mtime):

  • :mtime (Time, nil) — default: nil

    The time when this



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/nanoc3/base/layout.rb', line 38

def initialize(raw_content, attributes, identifier, params_or_mtime=nil)
  # Get params and mtime
  # TODO [in nanoc 4.0] clean this up
  if params_or_mtime.nil? || params_or_mtime.is_a?(Time)
    params = {}
    @mtime = params_or_mtime
  elsif params_or_mtime.is_a?(Hash)
    params = params_or_mtime
    @mtime = params[:mtime]
  end

  @raw_content  = raw_content
  @attributes   = attributes.symbolize_keys
  @identifier   = identifier.cleaned_identifier.freeze
end

Instance Attribute Details

- (Hash) attributes (readonly)

This layout's attributes

Returns:

  • (Hash)

    This layout's attributes



16
17
18
# File 'lib/nanoc3/base/layout.rb', line 16

def attributes
  @attributes
end

- (String) identifier

slash

Returns:

  • (String)

    This layout's identifier, starting and ending with a



20
21
22
# File 'lib/nanoc3/base/layout.rb', line 20

def identifier
  @identifier
end

- (Time) mtime (readonly)

The time when this layout was last modified

Returns:

  • (Time)

    The time when this layout was last modified



23
24
25
# File 'lib/nanoc3/base/layout.rb', line 23

def mtime
  @mtime
end

- (String) raw_content (readonly)

The raw content of this layout

Returns:

  • (String)

    The raw content of this layout



13
14
15
# File 'lib/nanoc3/base/layout.rb', line 13

def raw_content
  @raw_content
end

- (Nanoc3::Site) site

The site this layout belongs to

Returns:



10
11
12
# File 'lib/nanoc3/base/layout.rb', line 10

def site
  @site
end

Instance Method Details

- (Object) [](key)

Requests the attribute with the given key.

Parameters:

  • key (Symbol)

    The name of the attribute to fetch.

Returns:

  • (Object)

    The value of the requested attribute.



59
60
61
# File 'lib/nanoc3/base/layout.rb', line 59

def [](key)
  @attributes[key]
end

- (Object) inspect



63
64
65
# File 'lib/nanoc3/base/layout.rb', line 63

def inspect
  "<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier}>"
end