class Templet::Renderer

Performs the rendition

Public Class Methods

new(*contexts, **locals) click to toggle source

contexts a list of object refererences for method lookups

locals named variables passed into the renderer

# File lib/templet/renderer.rb, line 16
def initialize(*contexts, **locals)
  @contexts = contexts.flatten

  # Local variables take precedence
  @contexts.unshift ::OpenStruct.new(**locals) if locals.any?
end

Public Instance Methods

call(&block) click to toggle source

The block contains the markup

# File lib/templet/renderer.rb, line 29
def call(&block)
  Renderers::ListPresenter.new.(instance_eval(&block))
end
method_missing(name, *args, &block) click to toggle source
# File lib/templet/renderer.rb, line 33
def method_missing(name, *args, &block)
  @contexts.each do |context|
    if context.respond_to?(name, true)
      return context.send(name, *args, &block)
    end
  end
  fallback(name, *args, &block)
end
new_instance(*contexts, **locals) click to toggle source

Used for augmenting and overriding method lookups in children

# File lib/templet/renderer.rb, line 24
def new_instance(*contexts, **locals)
  Renderer.new(*(contexts | @contexts), **locals)
end
respond_to?(method_name, *) click to toggle source
# File lib/templet/renderer.rb, line 42
def respond_to?(method_name, *)
  @contexts.each do |context|
    return true if context.respond_to?(method_name, true)
  end
  false
end

Private Instance Methods

fallback(name, *args, &block)

Allows you to reimplement fallback in a subclass For example, you might use the Rails helper method content_tag instead

Alias for: tag
tag(name, *args, &block) click to toggle source
# File lib/templet/renderer.rb, line 51
def tag(name, *args, &block)
  Renderers::Tag.new(name).(*args, &block)
end
Also aliased as: fallback