Sha256: cf16324ac369a1bd52f2d61028a29a5f69ab50b3d130d0913c27e4c4995e3c27

Contents?: true

Size: 1.11 KB

Versions: 7

Compression:

Stored size: 1.11 KB

Contents

module Locomotive
  module Wagon
    module Liquid
      module Tags

        class Snippet < ::Liquid::Include

          def render(context)
            name = @template_name.gsub(/[\"\']/, '')

            source = context.registers[:mounting_point].snippets[name].try(:source)

            Locomotive::Wagon::Logger.info "  Rendered snippet #{name}"

            partial = ::Liquid::Template.parse(source)

            variable = context[@variable_name || @template_name[1..-2]]

            context.stack do
              @attributes.each do |key, value|
                context[key] = context[value]
              end

              output = (if variable.is_a?(Array)
                variable.collect do |variable|
                  context[@template_name[1..-2]] = variable
                  partial.render(context)
                end
              else
                context[@template_name[1..-2]] = variable
                partial.render(context)
              end)

              output
            end
          end

        end

        ::Liquid::Template.register_tag('include', Snippet)
      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/snippet.rb
locomotivecms_wagon-1.2.1 lib/locomotive/wagon/liquid/tags/snippet.rb
locomotivecms_wagon-1.2.0 lib/locomotive/wagon/liquid/tags/snippet.rb
locomotivecms_wagon-1.1.0 lib/locomotive/wagon/liquid/tags/snippet.rb
locomotivecms_wagon-1.0.2 lib/locomotive/wagon/liquid/tags/snippet.rb
locomotivecms_wagon-1.0.1 lib/locomotive/wagon/liquid/tags/snippet.rb
locomotivecms_wagon-1.0.0 lib/locomotive/wagon/liquid/tags/snippet.rb