Skip to content

Commit

Permalink
Merge pull request Shopify#506 from Shopify/fix_capture_with_hyphen
Browse files Browse the repository at this point in the history
Use VariableSignature as Syntax for Capture tag to allow hyphens in variable names
  • Loading branch information
fw42 committed Jan 11, 2015
2 parents 4b0a7c5 + 7cfee16 commit bebd357
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/liquid/tags/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Liquid
# in a sidebar or footer.
#
class Capture < Block
Syntax = /(\w+)/
Syntax = /(#{VariableSignature}+)/o

def initialize(tag_name, markup, options)
super
Expand Down
10 changes: 10 additions & 0 deletions test/integration/assign_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
class AssignTest < Minitest::Test
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
assert_template_result('.foo.',
'{% assign foo = values %}.{{ foo[0] }}.',
Expand Down
10 changes: 10 additions & 0 deletions test/integration/capture_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ def test_captures_block_content_in_variable
assert_template_result("test string", "{% capture 'var' %}test string{% endcapture %}{{var}}", {})
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
template_source = <<-END_TEMPLATE
{% assign var = '' %}
Expand Down

0 comments on commit bebd357

Please sign in to comment.