Sha256: a86a69a1d4cc440dfde547cd2b43aa029456a614c893691b6c6870c1edf8beb7

Contents?: true

Size: 1.13 KB

Versions: 18

Compression:

Stored size: 1.13 KB

Contents

require 'test_helper'

class CaptureTest < Test::Unit::TestCase
  include Liquid

  def test_captures_block_content_in_variable
    assert_template_result("test string", "{% capture 'var' %}test string{% endcapture %}{{var}}", {})
  end

  def test_capture_to_variable_from_outer_scope_if_existing
    template_source = <<-END_TEMPLATE
    {% assign var = '' %}
    {% if true %}
    {% capture var %}first-block-string{% endcapture %}
    {% endif %}
    {% if true %}
    {% capture var %}test-string{% endcapture %}
    {% endif %}
    {{var}}
    END_TEMPLATE
    template = Template.parse(template_source)
    rendered = template.render
    assert_equal "test-string", rendered.gsub(/\s/, '')
  end

  def test_assigning_from_capture
    template_source = <<-END_TEMPLATE
    {% assign first = '' %}
    {% assign second = '' %}
    {% for number in (1..3) %}
    {% capture first %}{{number}}{% endcapture %}
    {% assign second = first %}
    {% endfor %}
    {{ first }}-{{ second }}
    END_TEMPLATE
    template = Template.parse(template_source)
    rendered = template.render
    assert_equal "3-3", rendered.gsub(/\s/, '')
  end
end # CaptureTest

Version data entries

18 entries across 18 versions & 4 rubygems

Version Path
liquid-2.6.3 test/liquid/capture_test.rb
liquid-2.6.2 test/liquid/capture_test.rb
liquid-2.6.1 test/liquid/capture_test.rb
liquid-2.5.5 test/liquid/capture_test.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/liquid-2.6.0/test/liquid/capture_test.rb
liquid-2.6.0 test/liquid/capture_test.rb
liquid-2.5.4 test/liquid/capture_test.rb
liquid-2.6.0.rc1 test/liquid/capture_test.rb
liquid-2.5.3 test/liquid/capture_test.rb
liquid-2.5.1 test/liquid/capture_test.rb
wordify_liquid-2.5.1 test/liquid/capture_test.rb
liquid-2.5.0 test/liquid/capture_test.rb
liquid-2.4.1 test/liquid/capture_test.rb
liquid-2.4.0 test/liquid/capture_test.rb
spinto-liquid-2.3.0.3 test/liquid/capture_test.rb
spinto-liquid-2.3.0.2 test/liquid/capture_test.rb
spinto-liquid-2.3.0.1 test/liquid/capture_test.rb
liquid-2.3.0 test/liquid/capture_test.rb