Sha256: 0816789882196ef1386106b28d0a5344ea0cc633fa9e757fa2b98888de5615e0
Contents?: true
Size: 1.11 KB
Versions: 8
Compression:
Stored size: 1.11 KB
Contents
module Locomotive module Liquid module Tags # Filter a collection # # Usage: # # {% with_scope main_developer: 'John Doe', active: true %} # {% for project in contents.projects %} # {{ project.name }} # {% endfor %} # {% endwith_scope %} # class WithScope < ::Liquid::Block TagAttributes = /(\w+|\w+\.\w+)\s*\:\s*(#{::Liquid::QuotedFragment})/ def initialize(tag_name, markup, tokens, context) @attributes = HashWithIndifferentAccess.new markup.scan(TagAttributes) do |key, value| @attributes[key] = value end super end def render(context) context.stack do context['with_scope'] = decode(@attributes, context) render_all(@nodelist, context) end end private def decode(attributes, context) attributes.each_pair do |key, value| attributes[key] = context[value] end end end ::Liquid::Template.register_tag('with_scope', WithScope) end end end
Version data entries
8 entries across 8 versions & 1 rubygems