Sha256: c578e862dd8f45135d608be4344ce6daf4249fa31f41498281de1fbb9f301f9a

Contents?: true

Size: 762 Bytes

Versions: 2

Compression:

Stored size: 762 Bytes

Contents

module Liquid

  # Capture stores the result of a block into a variable without rendering it inplace.
  #
  #   {% capture heading %}
  #     Monkeys!
  #   {% endcapture %}
  #   ...
  #   <h1>{{ heading }}</h1>
  #
  # Capture is useful for saving content for use later in your template, such as
  # in a sidebar or footer.
  #
  class Capture < Block
    Syntax = /(\w+)/

    def initialize(tag_name, markup, tokens, context)
      if markup =~ Syntax
        @to = $1
      else
        raise SyntaxError.new("Syntax Error in 'capture' - Valid syntax: capture [var]")
      end

      super
    end

    def render(context)
      output = super
      context.scopes.last[@to] = output
      ''
    end
  end

  Template.register_tag('capture', Capture)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
locomotive_liquid-2.4.2 lib/liquid/tags/capture.rb
locomotive_liquid-2.4.1 lib/liquid/tags/capture.rb