Sha256: dd2317517fbcf930915138922c50f2ace0ea20272af582389ac1604d42d64dcf

Contents?: true

Size: 739 Bytes

Versions: 1

Compression:

Stored size: 739 Bytes

Contents

module Liquid

  # Capture stores the result of a block into a variable without rendering it inplace.
  #
  #   {% capture heading %}
  #     Monkeys!
  #   {% end %}
  #   ...
  #   <h1>{{ monkeys }}</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)
      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[@to] = output.join
      ''
    end
  end

  Template.register_tag('capture', Capture)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
drnic-liquid-2.1.0 lib/liquid/tags/capture.rb