Sha256: c240c85cab538f77d4d8157f1f5770c0f494edf61e60091565da60e69742bf72

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

module InlineTemplates
  class RenderingContext < BlankObject
    make_blank :instance_exec, :instance_variable_get, :instance_variable_set

    def initialize(context, locals, builder, view = nil)
      @_inlinetemplates_context = context
      @_inlinetemplates_locals = locals
      @_inlinetemplates_builder = builder
      @_inlinetemplates_view = view || context

      context.instance_variables.each do |var|
        instance_variable_set var, BufferWrapper.wrap(context.instance_variable_get(var), self)
      end
    end
 
    def t(obj)
      BufferWrapper.wrap obj.to_s, self
    end

    def h(obj)
      BufferWrapper.wrap obj.to_s.html_safe, self
    end

    def inlinetemplates_append(obj)
      @_inlinetemplates_view.output_buffer.append = obj
    end

    def inlinetemplates_instance_exec(new_self, *args, &block)
      RenderingContext.new(new_self, @_inlinetemplates_locals, @_inlinetemplates_builder, @_inlinetemplates_view).instance_exec(*args, &block)
    end
 
    def method_missing(name, *args, &block)
      args.map! &BufferWrapper.method(:unwrap)
      block = BufferWrapper.create_proxy_proc(block, self) unless block.nil?

      if @_inlinetemplates_locals.include?(name) && args.length == 0
        result = @_inlinetemplates_locals[name]
 
      elsif @_inlinetemplates_context.respond_to?(name, true)
        result = @_inlinetemplates_context.__send__ name, *args, &block
 
      elsif @_inlinetemplates_builder.can_build?(name)
        result = @_inlinetemplates_builder.build @_inlinetemplates_view, name, *args, &block
 
      else
        super
      end
 
      BufferWrapper.wrap result, self
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
inline_templates-1.0.0 lib/inline_templates/rendering_context.rb
inline_templates-0.0.6 lib/inline_templates/rendering_context.rb
inline_templates-0.0.5 lib/inline_templates/rendering_context.rb
inline_templates-0.0.4 lib/inline_templates/rendering_context.rb
inline_templates-0.0.3 lib/inline_templates/rendering_context.rb