mirror of
https://github.com/kemko/liquid.git
synced 2026-01-06 10:15:40 +03:00
Abstract parser switching into tag
This commit is contained in:
@@ -22,5 +22,20 @@ module Liquid
|
||||
def blank?
|
||||
@blank || true
|
||||
end
|
||||
|
||||
def switch_parse(markup)
|
||||
case Template.error_mode
|
||||
when :strict then strict_parse(markup)
|
||||
when :lax then lax_parse(markup)
|
||||
when :warn
|
||||
begin
|
||||
return strict_parse(markup)
|
||||
rescue SyntaxError => e
|
||||
@warnings ||= []
|
||||
@warnings << e
|
||||
return lax_parse(markup)
|
||||
end
|
||||
end
|
||||
end
|
||||
end # Tag
|
||||
end # Liquid
|
||||
|
||||
@@ -46,28 +46,13 @@ module Liquid
|
||||
block = if tag == 'else'
|
||||
ElseCondition.new
|
||||
else
|
||||
parse_condition(markup)
|
||||
switch_parse(markup)
|
||||
end
|
||||
|
||||
@blocks.push(block)
|
||||
@nodelist = block.attach(Array.new)
|
||||
end
|
||||
|
||||
def parse_condition(markup)
|
||||
case Template.error_mode
|
||||
when :strict then strict_parse(markup)
|
||||
when :lax then lax_parse(markup)
|
||||
when :warn
|
||||
begin
|
||||
return strict_parse(markup)
|
||||
rescue SyntaxError => e
|
||||
@warnings ||= []
|
||||
@warnings << e
|
||||
return lax_parse(markup)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def lax_parse(markup)
|
||||
expressions = markup.scan(ExpressionsAndOperators).reverse
|
||||
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
|
||||
|
||||
Reference in New Issue
Block a user