Created
          January 23, 2013 12:54 
        
      - 
      
- 
        Save greendog/4605222 to your computer and use it in GitHub Desktop. 
    Create a Liquid Handler for Rails 3.1
Use:
require 'action_view/template/handlers/liquid'
ActionView::Template.register_template_handler :liquid, ActionView::Template::Handlers::Liquid
  
        
  
    
      This file contains hidden or 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 ActionView::Template::Handlers::Liquid | |
| def self.call(template) | |
| "ActionView::Template::Handlers::Liquid.new(self).render(#{template.source.inspect}, local_assigns)" | |
| end | |
| def initialize(view) | |
| @view = view | |
| end | |
| def render(template, local_assigns = {}) | |
| @view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8' | |
| assigns = @view.assigns | |
| if @view.content_for?(:layout) | |
| assigns["content_for_layout"] = @view.content_for(:layout) | |
| end | |
| assigns.merge!(local_assigns.stringify_keys) | |
| controller = @view.controller | |
| filters = if controller.respond_to?(:liquid_filters, true) | |
| controller.send(:liquid_filters) | |
| elsif controller.respond_to?(:master_helper_module) | |
| [controller.master_helper_module] | |
| else | |
| [controller._helpers] | |
| end | |
| liquid = Liquid::Template.parse(template) | |
| liquid.render(assigns, :filters => filters, :registers => {:action_view => @view, :controller => @view.controller}) | |
| end | |
| def compilable? | |
| false | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment