Sha256: a28e5b1ca4de5bc9120c9e673a0ea57dad7687a3890da58315d729001694e22a

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

module Locomotive
  module Wagon
    module Liquid
      module Tags
        class WithScope < ::Liquid::Block

          def initialize(tag_name, markup, tokens, context)
            @options = {}

            markup.scan(::Liquid::TagAttributes) do |key, value|
              @options[key] = value
            end

            super
          end

          def render(context)
            context.stack do
              context['with_scope'] = decode(@options, context)
              render_all(@nodelist, context)
            end
          end

          private

          def decode(attributes, context)
            attributes.each_pair do |key, value|
              attributes[key] = (case value
              when /^true|false$/i then value == 'true'
              when /^[0-9]+$/ then value.to_i
              when /^["|'](.+)["|']$/ then $1.gsub(/^["|']/, '').gsub(/["|']$/, '')
              else
                context[value] || value
              end)
            end
          end
        end

        ::Liquid::Template.register_tag('with_scope', WithScope)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
locomotivecms_wagon-1.2.2 lib/locomotive/wagon/liquid/tags/with_scope.rb
locomotivecms_wagon-1.2.1 lib/locomotive/wagon/liquid/tags/with_scope.rb
locomotivecms_wagon-1.2.0 lib/locomotive/wagon/liquid/tags/with_scope.rb
locomotivecms_wagon-1.1.0 lib/locomotive/wagon/liquid/tags/with_scope.rb
locomotivecms_wagon-1.0.2 lib/locomotive/wagon/liquid/tags/with_scope.rb
locomotivecms_wagon-1.0.1 lib/locomotive/wagon/liquid/tags/with_scope.rb
locomotivecms_wagon-1.0.0 lib/locomotive/wagon/liquid/tags/with_scope.rb