Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Liquid::ParseContext#parse_expression for liquid-c node disabling #1333

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/liquid/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def self.operators
@@operators
end

def self.parse_expression(markup)
@@method_literals[markup] || Expression.parse(markup)
def self.parse_expression(parse_context, markup)
@@method_literals[markup] || parse_context.parse_expression(markup)
end

attr_reader :attachment, :child_condition
Expand Down
4 changes: 4 additions & 0 deletions lib/liquid/parse_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def new_block_body
Liquid::BlockBody.new
end

def parse_expression(markup)
Expression.parse(markup)
end

def partial=(value)
@partial = value
@options = value ? partial_options : @template_options
Expand Down
6 changes: 6 additions & 0 deletions lib/liquid/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,11 @@ def render_to_output_buffer(context, output)
def blank?
false
end

private

def parse_expression(markup)
parse_context.parse_expression(markup)
end
end
end
4 changes: 2 additions & 2 deletions lib/liquid/tags/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(tag_name, markup, options)
@blocks = []

if markup =~ Syntax
@left = Expression.parse(Regexp.last_match(1))
@left = parse_expression(Regexp.last_match(1))
else
raise SyntaxError, options[:locale].t("errors.syntax.case")
end
Expand Down Expand Up @@ -68,7 +68,7 @@ def record_when_condition(markup)

markup = Regexp.last_match(2)

block = Condition.new(@left, '==', Condition.parse_expression(Regexp.last_match(1)))
block = Condition.new(@left, '==', Condition.parse_expression(parse_context, Regexp.last_match(1)))
block.attach(body)
@blocks << block
end
Expand Down
4 changes: 2 additions & 2 deletions lib/liquid/tags/cycle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(tag_name, markup, options)
case markup
when NamedSyntax
@variables = variables_from_string(Regexp.last_match(2))
@name = Expression.parse(Regexp.last_match(1))
@name = parse_expression(Regexp.last_match(1))
when SimpleSyntax
@variables = variables_from_string(markup)
@name = @variables.to_s
Expand Down Expand Up @@ -61,7 +61,7 @@ def render_to_output_buffer(context, output)
def variables_from_string(markup)
markup.split(',').collect do |var|
var =~ /\s*(#{QuotedFragment})\s*/o
Regexp.last_match(1) ? Expression.parse(Regexp.last_match(1)) : nil
Regexp.last_match(1) ? parse_expression(Regexp.last_match(1)) : nil
end.compact
end

Expand Down
8 changes: 4 additions & 4 deletions lib/liquid/tags/for.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def lax_parse(markup)
collection_name = Regexp.last_match(2)
@reversed = !!Regexp.last_match(3)
@name = "#{@variable_name}-#{collection_name}"
@collection_name = Expression.parse(collection_name)
@collection_name = parse_expression(collection_name)
markup.scan(TagAttributes) do |key, value|
set_attribute(key, value)
end
Expand All @@ -112,7 +112,7 @@ def strict_parse(markup)
raise SyntaxError, options[:locale].t("errors.syntax.for_invalid_in") unless p.id?('in')

collection_name = p.expression
@collection_name = Expression.parse(collection_name)
@collection_name = parse_expression(collection_name)

@name = "#{@variable_name}-#{collection_name}"
@reversed = p.id?('reversed')
Expand Down Expand Up @@ -198,10 +198,10 @@ def set_attribute(key, expr)
@from = if expr == 'continue'
:continue
else
Expression.parse(expr)
parse_expression(expr)
end
when 'limit'
@limit = Expression.parse(expr)
@limit = parse_expression(expr)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/liquid/tags/if.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def push_block(tag, markup)
end

def parse_expression(markup)
Condition.parse_expression(markup)
Condition.parse_expression(parse_context, markup)
end

def lax_parse(markup)
Expand Down
6 changes: 3 additions & 3 deletions lib/liquid/tags/include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def initialize(tag_name, markup, options)
variable_name = Regexp.last_match(3)

@alias_name = Regexp.last_match(5)
@variable_name_expr = variable_name ? Expression.parse(variable_name) : nil
@template_name_expr = Expression.parse(template_name)
@variable_name_expr = variable_name ? parse_expression(variable_name) : nil
@template_name_expr = parse_expression(template_name)
@attributes = {}

markup.scan(TagAttributes) do |key, value|
@attributes[key] = Expression.parse(value)
@attributes[key] = parse_expression(value)
end

else
Expand Down
6 changes: 3 additions & 3 deletions lib/liquid/tags/render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def initialize(tag_name, markup, options)
variable_name = Regexp.last_match(4)

@alias_name = Regexp.last_match(6)
@variable_name_expr = variable_name ? Expression.parse(variable_name) : nil
@template_name_expr = Expression.parse(template_name)
@variable_name_expr = variable_name ? parse_expression(variable_name) : nil
@template_name_expr = parse_expression(template_name)
@for = (with_or_for == FOR)

@attributes = {}
markup.scan(TagAttributes) do |key, value|
@attributes[key] = Expression.parse(value)
@attributes[key] = parse_expression(value)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/liquid/tags/table_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def initialize(tag_name, markup, options)
super
if markup =~ Syntax
@variable_name = Regexp.last_match(1)
@collection_name = Expression.parse(Regexp.last_match(2))
@collection_name = parse_expression(Regexp.last_match(2))
@attributes = {}
markup.scan(TagAttributes) do |key, value|
@attributes[key] = Expression.parse(value)
@attributes[key] = parse_expression(value)
end
else
raise SyntaxError, options[:locale].t("errors.syntax.table_row")
Expand Down