Sha256: 02c9450b72b1ac6ff31cc2bbcf50d4afc0b860a4b0199b341c0cc0828e90d139

Contents?: true

Size: 1.04 KB

Versions: 45

Compression:

Stored size: 1.04 KB

Contents

module RailsConnector::LiquidSupport

  # This is a wrapper class used internally to make helper methods available in
  # Liquid templates. Helpers have to be enabled in the app initialization like this:
  #
  #    RailsConnector::LiquidSupport.enable_helpers(
  #       :helper_a,
  #       :helper_b
  #     )
  class GeneralHelperTag < Liquid::Tag
    attr_reader :params

    def initialize(tag_name, markup, tokens)
      @tag_name = tag_name
      @params = markup.to_s.scan(/(#{::Liquid::Expression})*/).flatten.compact.map(&:strip)
      super
    end

    def render(context)
      context.registers[:action_view].__send__(@tag_name, *params(context))
    end

    def self.<<(helper)
      Liquid::Template.register_tag(helper, self)
      self
    end

  protected

    def params(context)
      @params.map { |p| context[p] || p }.map do |item|
        case item
        when LinkDrop
          item.destination.__drop_content
        when ObjDrop
          item.__drop_content
        else
          item.to_s
        end
      end
    end
  end

end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
infopark_rails_connector-6.8.0.beta.200.713.e5c3150 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.681.7c84f4a lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.663.ceecdee lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.650.7c93155 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.621.4c8e1b0 lib/rails_connector/liquid_support/general_helper_tag.rb