mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
Make stuff nicer
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
# This class is used by tags to parse themselves
|
|
||||||
# it provides helpers and encapsulates state
|
|
||||||
class Parser
|
class Parser
|
||||||
def initialize(input)
|
def initialize(input)
|
||||||
l = Lexer.new(input)
|
l = Lexer.new(input)
|
||||||
@@ -54,7 +52,6 @@ module Liquid
|
|||||||
variable_signature
|
variable_signature
|
||||||
elsif [:string, :number].include? token[0]
|
elsif [:string, :number].include? token[0]
|
||||||
consume
|
consume
|
||||||
token[1]
|
|
||||||
elsif token.first == :open_round
|
elsif token.first == :open_round
|
||||||
consume
|
consume
|
||||||
first = expression
|
first = expression
|
||||||
|
|||||||
+3
-9
@@ -3,14 +3,8 @@ module Liquid
|
|||||||
attr_accessor :nodelist, :options
|
attr_accessor :nodelist, :options
|
||||||
|
|
||||||
def self.new_with_options(tag_name, markup, tokens, options)
|
def self.new_with_options(tag_name, markup, tokens, options)
|
||||||
# Forgive me Matz for I have sinned.
|
# Forgive me Matz for I have sinned. I know this code is weird
|
||||||
# I have forsaken the holy idioms of Ruby and used Class#allocate.
|
# but it was necessary to maintain API compatibility.
|
||||||
# I fulfilled my mandate by maintaining API compatibility and performance,
|
|
||||||
# even though it may displease your Lordship.
|
|
||||||
#
|
|
||||||
# In all seriousness though, I can prove to a reasonable degree of certainty
|
|
||||||
# that setting options before calling initialize is required to maintain API compatibility.
|
|
||||||
# I tried doing it without it and not only did I break compatibility, it was much slower.
|
|
||||||
new_tag = self.allocate
|
new_tag = self.allocate
|
||||||
new_tag.options = options
|
new_tag.options = options
|
||||||
new_tag.send(:initialize, tag_name, markup, tokens)
|
new_tag.send(:initialize, tag_name, markup, tokens)
|
||||||
@@ -39,7 +33,7 @@ module Liquid
|
|||||||
@blank || true
|
@blank || true
|
||||||
end
|
end
|
||||||
|
|
||||||
def switch_parse(markup)
|
def parse_with_selected_parser(markup)
|
||||||
case @options[:error_mode] || Template.error_mode
|
case @options[:error_mode] || Template.error_mode
|
||||||
when :strict then strict_parse(markup)
|
when :strict then strict_parse(markup)
|
||||||
when :lax then lax_parse(markup)
|
when :lax then lax_parse(markup)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ module Liquid
|
|||||||
Syntax = /\A(#{VariableSegment}+)\s+in\s+(#{QuotedFragment}+)\s*(reversed)?/o
|
Syntax = /\A(#{VariableSegment}+)\s+in\s+(#{QuotedFragment}+)\s*(reversed)?/o
|
||||||
|
|
||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
switch_parse(markup)
|
parse_with_selected_parser(markup)
|
||||||
@nodelist = @for_block = []
|
@nodelist = @for_block = []
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ module Liquid
|
|||||||
block = if tag == 'else'
|
block = if tag == 'else'
|
||||||
ElseCondition.new
|
ElseCondition.new
|
||||||
else
|
else
|
||||||
switch_parse(markup)
|
parse_with_selected_parser(markup)
|
||||||
end
|
end
|
||||||
|
|
||||||
@blocks.push(block)
|
@blocks.push(block)
|
||||||
@@ -79,7 +79,7 @@ module Liquid
|
|||||||
|
|
||||||
while op = (p.id?('and') || p.id?('or'))
|
while op = (p.id?('and') || p.id?('or'))
|
||||||
new_cond = parse_comparison(p)
|
new_cond = parse_comparison(p)
|
||||||
new_cond.send(op.to_sym, condition)
|
new_cond.send(op, condition)
|
||||||
condition = new_cond
|
condition = new_cond
|
||||||
end
|
end
|
||||||
p.consume(:end_of_string)
|
p.consume(:end_of_string)
|
||||||
|
|||||||
Reference in New Issue
Block a user