Class: Nanoc3::CodeSnippet

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc3/base/code_snippet.rb

Overview

Nanoc3::CodeSnippet represent a piece of custom code of a nanoc site. It contains the textual source code as well as a mtime, which is used to speed up site compilation.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CodeSnippet) initialize(data, filename, mtime = nil)

Creates a new code snippet.

compilation

nil)

Parameters:

  • data (String)

    The raw source code which will be executed before

  • filename (String)

    The filename corresponding to this code snippet

  • mtime (Time) (defaults to: nil)

    The time when the code was last modified (can be



39
40
41
42
43
# File 'lib/nanoc3/base/code_snippet.rb', line 39

def initialize(data, filename, mtime=nil)
  @data     = data
  @filename = filename
  @mtime    = mtime
end

Instance Attribute Details

- (String) data (readonly)

A string containing the actual code in this code snippet.

Returns:



18
19
20
# File 'lib/nanoc3/base/code_snippet.rb', line 18

def data
  @data
end

- (String) filename (readonly)

The filename corresponding to this code snippet.

Returns:



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

def filename
  @filename
end

- (Time) mtime (readonly)

The time where this code snippet was last modified.

Returns:



28
29
30
# File 'lib/nanoc3/base/code_snippet.rb', line 28

def mtime
  @mtime
end

- (Nanoc3::Site) site

The Site this code snippet belongs to.

Returns:



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

def site
  @site
end

Instance Method Details

- (void) load

This method returns an undefined value.

Loads the code by executing it.



48
49
50
# File 'lib/nanoc3/base/code_snippet.rb', line 48

def load
  eval(@data, TOPLEVEL_BINDING, @filename)
end