liquid-rails icon indicating copy to clipboard operation
liquid-rails copied to clipboard

Is this gem still maintained?

Open vitobotta opened this issue 4 years ago • 7 comments

Hi! Just found this gem as I am looking to use Liquid in my Rails 6 app. It looks like it hasn't been updated in 2 years tho. Is it because it still just works or because it's no longer maintained?

Thanks in advance

vitobotta avatar Apr 01 '20 16:04 vitobotta

@vitobotta with how long it's been since any issues have been answered by @chamnap, I'd say it might be time to create a fork, or a new gem for ruby 2.7 and rails 6

SampsonCrowley avatar May 07 '20 00:05 SampsonCrowley

I don't have the time to be a sole maintainer on this, but I'd be happy to contribute from time to time should a new fork arise. I think Liquid still should have a real shot at being a decent Rails template handler—for certain use cases, it's better than any alternative.

jaredcwhite avatar May 08 '20 17:05 jaredcwhite

Hi, in the meantime I just created a simple handler in my app without using any gems. It's so simple really

vitobotta avatar May 15 '20 19:05 vitobotta

@vitobotta Oh that sounds cool. Could you put up a Gist or an example somewhere?

jaredcwhite avatar May 15 '20 20:05 jaredcwhite


module ActionView
  class Template
    module Handlers
      # Add support for Liquid templates
      class LiquidHandler
        def self.call(_template, render_str)
          "ActionView::Template::Handlers::LiquidHandler.new(self).render('#{render_str}', local_assigns)"
        end

        def initialize(view)
          @view = view
        end

        def assigns(local_assigns)
          @view.controller.headers['Content-Type'] ||= 'text/html; charset=utf-8'
          assigns = @view.assigns
          assigns['content_for_layout'] = @view.content_for(:layout) if @view.content_for?(:layout)
          assigns.merge!(local_assigns.stringify_keys)
          assigns
        end

        def controller
          @view.controller
        end

        def 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
        end

        def render(template, local_assigns = {})
          liquid = Liquid::Template.parse(template)
          liquid.render(
            assigns(local_assigns), filters:, registers: { action_view: @view, controller: @view.controller }
          )
        end

        def compilable?
          false
        end
      end
    end
  end
end

ActionView::Template.register_template_handler :liquid, ActionView::Template::Handlers::LiquidHandler

These links helped: https://medium.com/@pratikbh06/customisable-email-templates-in-rails-made-easy-using-panoramic-and-liquid-rails-d1d71f61387d http://royvandermeij.com/blog/2011/09/21/create-a-liquid-handler-for-rails-3-dot-1/

Place the above code into the initializers and it should work with just the standard liquid gem and allow creating a .liquid file and handler

      format.liquid do
        render locals: { name: 'John Doe' }
      end

andrewsheelan avatar Jun 13 '22 16:06 andrewsheelan

Unfortunately this gem apparently isn't maintained since there are some security alerts on the pinned versions of dependencies this gem uses.

richardonrails avatar Jul 01 '22 18:07 richardonrails

Is anyone maintaining a fork of this gem that upgraded dependencies and support for Rails 7?

richardonrails avatar Jul 01 '22 18:07 richardonrails