class Markaby::Rails::TemplateHandler

Attributes

view[RW]

Public Instance Methods

compile(template, local_assigns={}) click to toggle source
# File lib/markaby/rails/current.rb, line 8
def compile(template, local_assigns={})
  <<-CODE
    __template_handler = Markaby::Rails::TemplateHandler.new
    __template_handler.view = self
    __template_handler.render(lambda {
      #{template.source}
    }, local_assigns)
  CODE
end
render(template, local_assigns = (template.respond_to?(:locals) ? template.locals : {})) click to toggle source
# File lib/markaby/rails/current.rb, line 18
def render(template, local_assigns = (template.respond_to?(:locals) ? template.locals : {}))
  builder = RailsBuilder.new(instance_variables.merge(local_assigns), @view)
  @view.output_buffer = builder

  template.is_a?(Proc) ?
    builder.instance_eval(&template) :
    builder.instance_eval(template.source)

  builder.to_s
end

Private Instance Methods

instance_variable_hash(object) click to toggle source
# File lib/markaby/rails/current.rb, line 37
def instance_variable_hash(object)
  returning Hash.new do |hash|
    object.instance_variables.each do |var_name|
      hash[var_name.gsub("@", "")] = object.instance_variable_get(var_name)
    end
  end
end
instance_variables() click to toggle source
# File lib/markaby/rails/current.rb, line 33
def instance_variables
  instance_variable_hash(@view)
end