Sha256: a9e144f7b3e0b55be987ac1078368a2089be76335bf9af6cba1ca48db2d33412

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

# encoding: utf-8

module Nanoc::Int
  # Nanoc::Int::CodeSnippet represent a piece of custom code of a nanoc site.
  #
  # @api private
  class CodeSnippet
    # A string containing the actual code in this code snippet.
    #
    # @return [String]
    attr_reader :data

    # The filename corresponding to this code snippet.
    #
    # @return [String]
    attr_reader :filename

    # 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
    #
    # @param [Time, Hash] _params Extra parameters. Ignored by nanoc; it is
    #   only included for backwards compatibility.
    def initialize(data, filename, _params = nil)
      @data     = data
      @filename = filename
    end

    # Loads the code by executing it.
    #
    # @return [void]
    def load
      eval(@data, TOPLEVEL_BINDING, @filename)
    end

    # Returns an object that can be used for uniquely identifying objects.
    #
    # @return [Object] An unique reference to this object
    def reference
      [:code_snippet, filename]
    end

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

    # @return [String] The checksum for this object. If its contents change,
    #   the checksum will change as well.
    def __nanoc_checksum
      Nanoc::Int::Checksummer.calc(self)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nanoc-4.0.0b2 lib/nanoc/base/source_data/code_snippet.rb
nanoc-4.0.0b1 lib/nanoc/base/source_data/code_snippet.rb
nanoc-4.0.0a2 lib/nanoc/base/source_data/code_snippet.rb
nanoc-4.0.0a1 lib/nanoc/base/source_data/code_snippet.rb