class Nanoc::Core::CodeSnippet

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

@api private

Attributes

data[R]

A string containing the actual code in this code snippet.

@return [String]

filename[R]

The filename corresponding to this code snippet.

@return [String]

Public Class Methods

new(data, filename) click to toggle source

Creates a new code snippet.

@param [String] data The raw source code which will be executed before

compilation

@param [String] filename The filename corresponding to this code snippet

# File lib/nanoc/core/code_snippet.rb, line 28
def initialize(data, filename)
  @data     = data
  @filename = filename
end

Public Instance Methods

inspect() click to toggle source
# File lib/nanoc/core/code_snippet.rb, line 52
def inspect
  "<#{self.class} filename=\"#{filename}\">"
end
load() click to toggle source

Loads the code by executing it.

@return [void]

# File lib/nanoc/core/code_snippet.rb, line 37
def load
  # rubocop:disable Security/Eval
  eval('def self.use_helper(mod); Nanoc::Core::Context.instance_eval { include mod }; end', TOPLEVEL_BINDING)
  eval(@data, TOPLEVEL_BINDING, @filename)
  # rubocop:enable Security/Eval
  nil
end
reference() click to toggle source

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

@return [Object] An unique reference to this object

# File lib/nanoc/core/code_snippet.rb, line 48
def reference
  "code_snippet:#{filename}"
end