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.356.19698103 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.348.160665197 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.328.4a753fc lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.322.c003f11 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.210.ed204b0 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.110.6570b45 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.72.d18d096 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.23.da7f96b lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.16.def5e85 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.15.a24f5ff lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.891.647580e lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.889.d503e42 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.883.f5f063b lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.884.4bd86e6 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.869.9609b39 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.856.8c0fec5 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.809.bdfa8c3 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.785.05d4af9 lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.744.99f67fc lib/rails_connector/liquid_support/general_helper_tag.rb
infopark_rails_connector-6.8.0.beta.200.720.44fbabd lib/rails_connector/liquid_support/general_helper_tag.rb