Sha256: 1c7e2ffbf02880d6e40914a5841c8f631223a8f76c600e53232c9176a476dce1

Contents?: true

Size: 1.04 KB

Versions: 10

Compression:

Stored size: 1.04 KB

Contents

module Nanoc

  # Nanoc::Code represent the 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 Code

    # The Nanoc::Site this code belongs to.
    attr_accessor :site

    # The textual source code representation.
    attr_reader :data

    # The time where the code was last modified.
    attr_reader :mtime

    # Creates a new code object. +data+ is the raw source code, which will be
    # executed before compilation. +mtime+ is the time when the code was last
    # modified (optional).
    def initialize(data, mtime=nil)
      @data  = data
      @mtime = mtime
    end

    # Loads the code by executing it.
    def load
      eval(@data, TOPLEVEL_BINDING)
    end

    # Saves the code in the database, creating it if it doesn't exist yet or
    # updating it if it already exists. Tells the site's data source to save
    # the code.
    def save
      @site.data_source.loading do
        @site.data_source.save_code(self)
      end
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
nanoc-2.1.3 lib/nanoc/base/code.rb
nanoc-2.1 lib/nanoc/base/code.rb
nanoc-2.1.1 lib/nanoc/base/code.rb
nanoc-2.1.2 lib/nanoc/base/code.rb
nanoc-2.1.4 lib/nanoc/base/code.rb
nanoc-2.1.5 lib/nanoc/base/code.rb
nanoc-2.1.6 lib/nanoc/base/code.rb
nanoc-2.2 lib/nanoc/base/code.rb
nanoc-2.2.1 lib/nanoc/base/code.rb
nanoc-2.2.2 lib/nanoc/base/code.rb