Sha256: b9f07f19ac4500dda8add349c55c7d457cb25d91289ee37f472e718d74606258

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# encoding: utf-8

module Nanoc3

  # Nanoc3::CodeSnippet represent a piece of custom code of a nanoc site. It
  # contains the textual source code as well as a mtime, which is used to
  # speed up site compilation.
  class CodeSnippet

    # The {Nanoc3::Site} this code snippet belongs to.
    #
    # @return [Nanoc3::Site]
    attr_accessor :site

    # 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

    # The time where this code snippet was last modified.
    #
    # @return [Time]
    attr_reader :mtime

    # 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]   mtime    The time when the code was last modified (can be nil)
    def initialize(data, filename, mtime=nil)
      @data     = data
      @filename = filename
      @mtime    = mtime
    end

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

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nanoc3-3.1.0a2 lib/nanoc3/base/code_snippet.rb
nanoc3-3.1.0a1 lib/nanoc3/base/code_snippet.rb