Created
September 27, 2009 20:55
-
-
Save btakita/195008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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