Sha256: e0f1236ccefe5cd4d800f150e189742f428793a3588231d584f4a90834d8e458

Contents?: true

Size: 1.37 KB

Versions: 15

Compression:

Stored size: 1.37 KB

Contents

# encoding: utf-8

module Nanoc

  # Nanoc::CodeSnippet represent a piece of custom code of a nanoc site.
  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=#{self.filename}>"
    end

    # @return [String] The checksum for this object. If its contents change,
    #   the checksum will change as well.
    def checksum
      @data.checksum
    end

  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nanoc-3.5.0 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.5.0b2 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.5.0b1 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.4.3 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.4.2 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.4.1 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.4.0 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.3.7 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.3.6 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.3.5 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.3.4 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.3.3 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.3.2 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.3.1 lib/nanoc/base/source_data/code_snippet.rb
nanoc-3.3.0 lib/nanoc/base/source_data/code_snippet.rb