Sha256: 8c3e33cb4ea2afef065c0736aa554398bd2053e484527680c96159d207bcfd78

Contents?: true

Size: 976 Bytes

Versions: 2

Compression:

Stored size: 976 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
    attr_reader :relationship

    # 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
        @relationship = parent_env.relationship
      else
        @template = template
        @numbering = Numbering.new
        @relationship = Relationship.new
      end
      #
      @context = Context.transform_hash(context)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sablon-0.1.1 lib/sablon/environment.rb
sablon-0.1.0 lib/sablon/environment.rb