Sha256: 0dedc3be31af3126606293596fdfd22f834fd6af690e22c51860b1abcbbe38f2

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

module Locomotive
  module Builder
    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

8 entries across 8 versions & 1 rubygems

Version Path
locomotivecms_builder-1.0.0.alpha8 lib/locomotive/builder/liquid/tags/with_scope.rb
locomotivecms_builder-1.0.0.alpha7 lib/locomotive/builder/liquid/tags/with_scope.rb
locomotivecms_builder-1.0.0.alpha6 lib/locomotive/builder/liquid/tags/with_scope.rb
locomotivecms_builder-1.0.0.alpha5 lib/locomotive/builder/liquid/tags/with_scope.rb
locomotivecms_builder-1.0.0.alpha4 lib/locomotive/builder/liquid/tags/with_scope.rb
locomotivecms_builder-1.0.0.alpha3 lib/locomotive/builder/liquid/tags/with_scope.rb
locomotivecms_builder-1.0.0.alpha2 lib/locomotive/builder/liquid/tags/with_scope.rb
locomotivecms_builder-1.0.0.alpha1 lib/locomotive/builder/liquid/tags/with_scope.rb