Hi all!
HAML templates support locals out of the box. Unfortunately, ERB
templates do not. I have most of the solution working. The only
thing that doesn't work right now is layout rendering. Can anybody
spot my mistake ?
http://pastie.org/225387
class RenderContext
def initialize(parent_context)
@erb_parent_context = parent_context
end
def method_missing(*args, &block)
@erb_parent_context.send(*args, &block)
end
end
def render_erb(content, options = {})
context = RenderContext.new(self)
metaclass = class << context; self; end
instance_variables.each do |key|
next if %w(@request @response @route_params).include?(key)
context.instance_variable_set(key,
instance_variable_get(key))
end
(options[:locals] || Hash.new).each do |key, value|
metaclass.send(:attr_reader, key)
context.instance_variable_set("@#{key}", value)
end
::ERB.new(content).result(context.send(:binding))
end
Thanks !
François