mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -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
|
||||
SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]"
|
||||
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)
|
||||
@blocks = []
|
||||
@@ -56,7 +56,7 @@ module Liquid
|
||||
condition = Condition.new($1, $2, $3)
|
||||
|
||||
while not expressions.empty?
|
||||
operator = expressions.shift
|
||||
operator = (expressions.shift).to_s.strip
|
||||
|
||||
raise(SyntaxError, SyntaxHelp) unless expressions.shift.to_s =~ Syntax
|
||||
|
||||
|
||||
@@ -151,9 +151,10 @@ class IfElseTest < Test::Unit::TestCase
|
||||
Condition.operators.delete 'contains'
|
||||
end
|
||||
|
||||
# def test_operators_are_ignored_unless_isolated
|
||||
# Condition.operators['contains'] = :[]
|
||||
#
|
||||
# assert_template_result('yes', %({% if 'gnomeslab' == 'gnomeslab' %}yes{% endif %}))
|
||||
# end
|
||||
def test_operators_are_ignored_unless_isolated
|
||||
Condition.operators['contains'] = :[]
|
||||
|
||||
assert_template_result('yes',
|
||||
%({% if 'gnomeslab-and-or-liquid' contains 'gnomeslab-and-or-liquid' %}yes{% endif %}))
|
||||
end
|
||||
end # IfElseTest
|
||||
|
||||
Reference in New Issue
Block a user