Sha256: 62b2bd0119000590a71c2f1bc4b4e66f5c28db6d89bfbd254a7b381c9d3e5ca3

Contents?: true

Size: 937 Bytes

Versions: 14

Compression:

Stored size: 937 Bytes

Contents

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

        def initialize(tag_name, markup, tokens, context)
          @attributes = {}
          markup.scan(::Liquid::TagAttributes) do |key, value|
            @attributes[key] = value
          end
          super
        end

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

        private

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

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
locomotive_cms-1.0.0.beta.2 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-1.0.0.beta lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta12 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta11 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta10 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta9 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta8 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta7 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta5 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta4 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta3 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta2 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4.beta1 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.4 lib/locomotive/liquid/tags/with_scope.rb