mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-18 02:10:41 -07:00
Support prop spreading
This commit is contained in:
committed by
Guilherme Carreiro
parent
0ceeefba02
commit
d4d2237b90
@@ -12,6 +12,14 @@ module Liquid
|
||||
@p = point
|
||||
end
|
||||
|
||||
def read(type = nil)
|
||||
token = @tokens[@p]
|
||||
if type && token[0] != type
|
||||
raise SyntaxError, "Expected #{type} but found #{@tokens[@p].first}"
|
||||
end
|
||||
token[1]
|
||||
end
|
||||
|
||||
def consume(type = nil)
|
||||
token = @tokens[@p]
|
||||
if type && token[0] != type
|
||||
|
||||
+47
-13
@@ -76,10 +76,25 @@ module Liquid
|
||||
inner_context['forloop'] = forloop if forloop
|
||||
|
||||
@attributes.each do |key, value|
|
||||
if key == "..." && is_inline
|
||||
context.scopes.each do |scope|
|
||||
scope.each do |k, v|
|
||||
inner_context[k] = v
|
||||
if key.start_with?("...") && is_inline
|
||||
if key == "..."
|
||||
context.scopes.each do |scope|
|
||||
scope.each do |k, v|
|
||||
inner_context[k] = v
|
||||
end
|
||||
end
|
||||
else
|
||||
obj = context.evaluate(value)
|
||||
if obj.is_a?(Liquid::Drop)
|
||||
(obj.class.invokable_methods - ['to_liquid']).each do |method_name|
|
||||
inner_context[method_name] = obj.invoke_drop(method_name)
|
||||
end
|
||||
elsif obj.is_a?(Hash)
|
||||
obj.each do |k, v|
|
||||
inner_context[k] = v
|
||||
end
|
||||
else
|
||||
raise ::ArgumentError
|
||||
end
|
||||
end
|
||||
else
|
||||
@@ -117,11 +132,24 @@ module Liquid
|
||||
p.consume?(:comma)
|
||||
|
||||
@attributes = {}
|
||||
while p.look(:id)
|
||||
key = p.consume
|
||||
p.consume(:colon)
|
||||
@attributes[key] = safe_parse_expression(p)
|
||||
p.consume?(:comma)
|
||||
while p.look(:dotdotdot) || p.look(:id)
|
||||
if p.consume?(:dotdotdot)
|
||||
if p.look(:id)
|
||||
identifier = p.read(:id)
|
||||
key = "...#{identifier}"
|
||||
@attributes.delete(key)
|
||||
@attributes[key] = safe_parse_expression(p)
|
||||
else
|
||||
@attributes.delete("...")
|
||||
@attributes["..."] = true
|
||||
end
|
||||
else
|
||||
key = p.consume
|
||||
p.consume(:colon)
|
||||
@attributes.delete(key)
|
||||
@attributes[key] = safe_parse_expression(p)
|
||||
end
|
||||
p.consume?(:comma) # optional comma
|
||||
end
|
||||
|
||||
p.consume(:end_of_string)
|
||||
@@ -150,10 +178,16 @@ module Liquid
|
||||
@is_for_loop = (with_or_for == FOR)
|
||||
|
||||
@attributes = {}
|
||||
markup.scan(/(\.\.\.)(?=\s|,|$)|#{TagAttributes.source}/) do |context_marker, key, value|
|
||||
if context_marker
|
||||
@attributes.delete("...")
|
||||
@attributes["..."] = true
|
||||
markup.scan(/(\.\.\.)(\w+)?(?=\s|,|$)|#{TagAttributes.source}/) do |spread, identifier, key, value|
|
||||
if spread
|
||||
if identifier
|
||||
spread_key = "...#{identifier}"
|
||||
@attributes.delete(spread_key)
|
||||
@attributes[spread_key] = parse_expression(identifier)
|
||||
else
|
||||
@attributes.delete("...")
|
||||
@attributes["..."] = true
|
||||
end
|
||||
elsif key && value
|
||||
@attributes.delete(key)
|
||||
@attributes[key] = parse_expression(value)
|
||||
|
||||
Reference in New Issue
Block a user