Remove parser switching duplication

This commit is contained in:
Tristan Hume
2014-09-05 14:12:29 +00:00
committed by Florian Weingarten
parent 5eff375094
commit 3a0ee6ae91
4 changed files with 38 additions and 39 deletions
+30
View File
@@ -0,0 +1,30 @@
module Liquid
module ParserSwitching
def parse_with_selected_parser(markup)
case @options[:error_mode] || Template.error_mode
when :strict then strict_parse_with_error_context(markup)
when :lax then lax_parse(markup)
when :warn
begin
return strict_parse_with_error_context(markup)
rescue SyntaxError => e
@warnings ||= []
@warnings << e
return lax_parse(markup)
end
end
end
private
def strict_parse_with_error_context(markup)
strict_parse(markup)
rescue SyntaxError => e
e.message << markup_context(markup)
raise e
end
def markup_context(markup)
" in \"#{markup.strip}\""
end
end
end