Sha256: ed83f298e85f7ed6874d8dfa91ef0b97886b5b1ef19ed8275f3e1d940d2ed7b8

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

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
    def initialize(data, filename)
      @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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
nanoc-4.2.0 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.6 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.2.0b1 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.5 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.4 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.3 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.2 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.1 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.0 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.0rc2 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.0rc1 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.0b1 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.1.0a1 lib/nanoc/base/entities/code_snippet.rb