Sha256: b72493c2045c3a348a4e67a5638bbe015427a56ef7d9c2ef5b5f8c6a7bda8d54

Contents?: true

Size: 958 Bytes

Versions: 17

Compression:

Stored size: 958 Bytes

Contents

module Locomotive
  module Liquid
    module Tags
      class WithScope < ::Liquid::Block
    
        def initialize(tag_name, markup, tokens)
          @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

17 entries across 17 versions & 1 rubygems

Version Path
locomotive_cms-0.0.3.3 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.3.1 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.2.9 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.2.8 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.2.7 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.2.6 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.2.5 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.2.4 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.2.3 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.2.2 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.2.1 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.2 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.1.4 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.1.3 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.1.2 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.1.1 lib/locomotive/liquid/tags/with_scope.rb
locomotive_cms-0.0.1 lib/locomotive/liquid/tags/with_scope.rb