Skip to content

Instantly share code, notes, and snippets.

@btakita
Created September 27, 2009 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btakita/195008 to your computer and use it in GitHub Desktop.
Save btakita/195008 to your computer and use it in GitHub Desktop.
module ActionView #:nodoc:
module TemplateHandlers #:nodoc:
class ErectorTemplate < TemplateHandler
include Compilable
def self.line_offset
2
end
ActionView::Template.instance_eval do
register_template_handler :ert, ActionView::TemplateHandlers::ErectorTemplate
end
def compile(template)
source = <<-ERT
<%=begin
extend ::Erector::Mixin
memoized_instance_variables = instance_variables.inject({}) do |all, instance_variable|
all[instance_variable] = instance_variable_get(instance_variable)
all
end
Erector.inline do
memoized_instance_variables.each do |instance_variable, value|
instance_variable_set(instance_variable, value)
end
eval(<<-RUBY, binding, __FILE__, 1)
#{template.source}
RUBY
end
end%>
ERT
::ERB.new(source, nil, "-", '@output_buffer').src
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment