Created
November 20, 2010 00:19
-
-
Save Fjan/707461 to your computer and use it in GitHub Desktop.
Enable preprocessing in erubis with the <%=== %> directive
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
# Just drop this in the initializers directory of a rails 3 app and then use <%=== code %> in your templates | |
# and the code will be eval'ed at compile time, for example: <%=== link_to 'home', '/' %> actually puts | |
# <a href="/">home</a> in the compiled template avoiding the need to call link_to on every render | |
# This can provide a significant speedup of your rails views but beware that many rails helpers can produce | |
# different output depending on the context that is not available at compile time. | |
# For example, @form.text_field :name would produce different HTML if there was an error on the :name field. | |
# It doesn't work yet on asset tags like <%= javascript_include_tag :default %> | |
module ActionView | |
class Base | |
def get_binding | |
return binding | |
end | |
end | |
class Template | |
module Handlers | |
class Erubis < ::Erubis::Eruby | |
def add_expr_debug(src, code) | |
src << "@output_buffer.safe_concat('" << escape_text(eval(code,ActionView::Base.new.get_binding).to_s) << "');" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment