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.9.1.3.22208381 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.9.0.3.197272233 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.3.174.51542603 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.3.115.227021242 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.3.73.75172665 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.3.2.153416031 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.3.67.110847540 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.3.1.23895778 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.2.36.82613853 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.2.7.128454143 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.1.26.236500544 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.1 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.539.93842523 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.529.114081979 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.518.30999728 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.515.34928522 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.498.46559598 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.480.261594408 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.444.171626367 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.406.131718077 lib/rails_connector/liquid_support/general_helper_tag.rb