New variable parser!

This commit is contained in:
Tristan Hume
2013-07-25 11:38:57 -04:00
parent f43e973e67
commit 4da7b36139
5 changed files with 76 additions and 15 deletions
+26
View File
@@ -18,6 +18,10 @@ module Liquid
@markup = markup
@name = nil
@filters = []
parse(markup)
end
def old_parse(markup)
if match = markup.match(/\s*(#{QuotedFragment})(.*)/o)
@name = match[1]
if match[2].match(/#{FilterSeparator}\s*(.*)/o)
@@ -33,6 +37,28 @@ module Liquid
end
end
def parse(markup)
p = Parser.new(markup)
# Could be just filters with no input
@name = p.look(:pipe) ? '' : p.expression
while p.consume?(:pipe)
filtername = p.consume(:id)
filterargs = p.consume?(:colon) ? parse_filterargs(p) : []
@filters << [filtername, filterargs]
end
p.consume(:end_of_string)
end
def parse_filterargs(p)
# first argument
filterargs = [p.argument]
# followed by comma separated others
while p.consume?(:comma)
filterargs << p.argument
end
filterargs
end
def render(context)
return '' if @name.nil?
@filters.inject(context[@name]) do |output, filter|