Sha256: 92709f1103e2016762d51389836554e932085d991218de2d4bead4c8a4282555

Contents?: true

Size: 857 Bytes

Versions: 1

Compression:

Stored size: 857 Bytes

Contents

module Sablon
  # Combines the user supplied context and template into a single object
  # to manage data during template processing.
  class Environment
    attr_reader :template
    attr_reader :numbering
    attr_reader :context

    # returns a new environment with merged contexts
    def alter_context(context = {})
      new_context = @context.merge(context)
      Environment.new(nil, new_context, self)
    end

    private

    def initialize(template, context = {}, parent_env = nil)
      # pass attributes of the supplied environment to the new one or
      # create new references
      if parent_env
        @template = parent_env.template
        @numbering = parent_env.numbering
      else
        @template = template
        @numbering = Numbering.new
      end
      #
      @context = Context.transform_hash(context)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sablon-0.0.22 lib/sablon/environment.rb