mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
Merge pull request #506 from Shopify/fix_capture_with_hyphen
Use VariableSignature as Syntax for Capture tag to allow hyphens in variable names
This commit is contained in:
@@ -11,7 +11,7 @@ module Liquid
|
|||||||
# in a sidebar or footer.
|
# in a sidebar or footer.
|
||||||
#
|
#
|
||||||
class Capture < Block
|
class Capture < Block
|
||||||
Syntax = /(\w+)/
|
Syntax = /(#{VariableSignature}+)/o
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def initialize(tag_name, markup, options)
|
||||||
super
|
super
|
||||||
|
|||||||
@@ -3,6 +3,16 @@ require 'test_helper'
|
|||||||
class AssignTest < Minitest::Test
|
class AssignTest < Minitest::Test
|
||||||
include Liquid
|
include Liquid
|
||||||
|
|
||||||
|
def test_assign_with_hyphen_in_variable_name
|
||||||
|
template_source = <<-END_TEMPLATE
|
||||||
|
{% assign this-thing = 'Print this-thing' %}
|
||||||
|
{{ this-thing }}
|
||||||
|
END_TEMPLATE
|
||||||
|
template = Template.parse(template_source)
|
||||||
|
rendered = template.render!
|
||||||
|
assert_equal "Print this-thing", rendered.strip
|
||||||
|
end
|
||||||
|
|
||||||
def test_assigned_variable
|
def test_assigned_variable
|
||||||
assert_template_result('.foo.',
|
assert_template_result('.foo.',
|
||||||
'{% assign foo = values %}.{{ foo[0] }}.',
|
'{% assign foo = values %}.{{ foo[0] }}.',
|
||||||
|
|||||||
@@ -7,6 +7,16 @@ class CaptureTest < Minitest::Test
|
|||||||
assert_template_result("test string", "{% capture 'var' %}test string{% endcapture %}{{var}}", {})
|
assert_template_result("test string", "{% capture 'var' %}test string{% endcapture %}{{var}}", {})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_capture_with_hyphen_in_variable_name
|
||||||
|
template_source = <<-END_TEMPLATE
|
||||||
|
{% capture this-thing %}Print this-thing{% endcapture %}
|
||||||
|
{{ this-thing }}
|
||||||
|
END_TEMPLATE
|
||||||
|
template = Template.parse(template_source)
|
||||||
|
rendered = template.render!
|
||||||
|
assert_equal "Print this-thing", rendered.strip
|
||||||
|
end
|
||||||
|
|
||||||
def test_capture_to_variable_from_outer_scope_if_existing
|
def test_capture_to_variable_from_outer_scope_if_existing
|
||||||
template_source = <<-END_TEMPLATE
|
template_source = <<-END_TEMPLATE
|
||||||
{% assign var = '' %}
|
{% assign var = '' %}
|
||||||
|
|||||||
Reference in New Issue
Block a user