Class: Nanoc::CodeSnippet

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

Overview

Nanoc::CodeSnippet represent a piece of custom code of a nanoc site.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

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

Creates a new code snippet.

Parameters:

  • data (String)

    The raw source code which will be executed before compilation

  • filename (String)

    The filename corresponding to this code snippet

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

    Extra parameters. Ignored by nanoc; it is only included for backwards compatibility.



27
28
29
30
# File 'lib/nanoc/base/source_data/code_snippet.rb', line 27

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

Instance Attribute Details

- (String) data (readonly)

A string containing the actual code in this code snippet.

Returns:



11
12
13
# File 'lib/nanoc/base/source_data/code_snippet.rb', line 11

def data
  @data
end

- (String) filename (readonly)

The filename corresponding to this code snippet.

Returns:



16
17
18
# File 'lib/nanoc/base/source_data/code_snippet.rb', line 16

def filename
  @filename
end

Instance Method Details

- (String) checksum

Returns The checksum for this object. If its contents change, the checksum will change as well.

Returns:

  • (String)

    The checksum for this object. If its contents change, the checksum will change as well.



52
53
54
# File 'lib/nanoc/base/source_data/code_snippet.rb', line 52

def checksum
  Nanoc::Checksummer.calc(self)
end

- (Object) inspect



46
47
48
# File 'lib/nanoc/base/source_data/code_snippet.rb', line 46

def inspect
  "<#{self.class} filename=\"#{filename}\">"
end

- (void) load

This method returns an undefined value.

Loads the code by executing it.



35
36
37
# File 'lib/nanoc/base/source_data/code_snippet.rb', line 35

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

- (Object) reference

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

Returns:

  • (Object)

    An unique reference to this object



42
43
44
# File 'lib/nanoc/base/source_data/code_snippet.rb', line 42

def reference
  [ :code_snippet, filename ]
end