Created
September 21, 2011 07:06
-
-
Save sgruhier/1231441 to your computer and use it in GitHub Desktop.
Rails 3.1 version of extra/liquid_view.rb of liquid markup gem
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
class LiquidHandler | |
PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template | |
_response url _request _cookies variables_added _flash params _headers request cookies | |
ignore_missing_templates flash _params logger before_filter_chain_aborted headers ) | |
def self.call(template) | |
new.compile(template) | |
end | |
def compile(template) | |
<<-LIQUID | |
variables = assigns.reject{ |k,v| LiquidHandler::PROTECTED_ASSIGNS.include?(k) } | |
if content_for_layout = instance_variable_get("@content_for_layout") | |
variables['content_for_layout'] = content_for_layout | |
end | |
variables.merge!(local_assigns.stringify_keys) | |
liquid = Liquid::Template.parse("#{template.source.gsub(/\"/, '\\\"')}") | |
liquid.render(variables, :registers => {:action_view => self, :controller => controller}) | |
LIQUID | |
end | |
end | |
::ActionView::Template.register_template_handler(:liquid, LiquidHandler) |
Hi,
I am new to rails.I heard a about the liquid template concept. Can any one tell me how to implement the liquid template in the project?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is working fine for regular files. However for layouts content_for_layout did not work. Here is my layout . http://pastie.org/2747749
Any suggestions. Thanks.