mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 07:05:12 -07:00
IF tag
- now properly allows operands to have conditions (eg and, or) [closes #13]
This commit is contained in:
@@ -14,7 +14,7 @@ module Liquid
|
|||||||
class If < Block
|
class If < Block
|
||||||
SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]"
|
SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]"
|
||||||
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/
|
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/
|
||||||
ExpressionsAndOperators = /(?:\b(?:and|or)\b|(?:\s*(?!\b(?:and|or)\b)(?:#{QuotedFragment}|\S+)\s*)+)/
|
ExpressionsAndOperators = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QuotedFragment}|\S+)\s*)+)/
|
||||||
|
|
||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
@blocks = []
|
@blocks = []
|
||||||
@@ -56,7 +56,7 @@ module Liquid
|
|||||||
condition = Condition.new($1, $2, $3)
|
condition = Condition.new($1, $2, $3)
|
||||||
|
|
||||||
while not expressions.empty?
|
while not expressions.empty?
|
||||||
operator = expressions.shift
|
operator = (expressions.shift).to_s.strip
|
||||||
|
|
||||||
raise(SyntaxError, SyntaxHelp) unless expressions.shift.to_s =~ Syntax
|
raise(SyntaxError, SyntaxHelp) unless expressions.shift.to_s =~ Syntax
|
||||||
|
|
||||||
|
|||||||
@@ -151,9 +151,10 @@ class IfElseTest < Test::Unit::TestCase
|
|||||||
Condition.operators.delete 'contains'
|
Condition.operators.delete 'contains'
|
||||||
end
|
end
|
||||||
|
|
||||||
# def test_operators_are_ignored_unless_isolated
|
def test_operators_are_ignored_unless_isolated
|
||||||
# Condition.operators['contains'] = :[]
|
Condition.operators['contains'] = :[]
|
||||||
#
|
|
||||||
# assert_template_result('yes', %({% if 'gnomeslab' == 'gnomeslab' %}yes{% endif %}))
|
assert_template_result('yes',
|
||||||
# end
|
%({% if 'gnomeslab-and-or-liquid' contains 'gnomeslab-and-or-liquid' %}yes{% endif %}))
|
||||||
|
end
|
||||||
end # IfElseTest
|
end # IfElseTest
|
||||||
|
|||||||
Reference in New Issue
Block a user