mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Make stuff nicer
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
module Liquid
|
||||
# This class is used by tags to parse themselves
|
||||
# it provides helpers and encapsulates state
|
||||
class Parser
|
||||
def initialize(input)
|
||||
l = Lexer.new(input)
|
||||
@@ -54,7 +52,6 @@ module Liquid
|
||||
variable_signature
|
||||
elsif [:string, :number].include? token[0]
|
||||
consume
|
||||
token[1]
|
||||
elsif token.first == :open_round
|
||||
consume
|
||||
first = expression
|
||||
|
||||
+3
-9
@@ -3,14 +3,8 @@ module Liquid
|
||||
attr_accessor :nodelist, :options
|
||||
|
||||
def self.new_with_options(tag_name, markup, tokens, options)
|
||||
# Forgive me Matz for I have sinned.
|
||||
# I have forsaken the holy idioms of Ruby and used Class#allocate.
|
||||
# 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.
|
||||
# Forgive me Matz for I have sinned. I know this code is weird
|
||||
# but it was necessary to maintain API compatibility.
|
||||
new_tag = self.allocate
|
||||
new_tag.options = options
|
||||
new_tag.send(:initialize, tag_name, markup, tokens)
|
||||
@@ -39,7 +33,7 @@ module Liquid
|
||||
@blank || true
|
||||
end
|
||||
|
||||
def switch_parse(markup)
|
||||
def parse_with_selected_parser(markup)
|
||||
case @options[:error_mode] || Template.error_mode
|
||||
when :strict then strict_parse(markup)
|
||||
when :lax then lax_parse(markup)
|
||||
|
||||
@@ -47,7 +47,7 @@ module Liquid
|
||||
Syntax = /\A(#{VariableSegment}+)\s+in\s+(#{QuotedFragment}+)\s*(reversed)?/o
|
||||
|
||||
def initialize(tag_name, markup, tokens)
|
||||
switch_parse(markup)
|
||||
parse_with_selected_parser(markup)
|
||||
@nodelist = @for_block = []
|
||||
super
|
||||
end
|
||||
|
||||
@@ -46,7 +46,7 @@ module Liquid
|
||||
block = if tag == 'else'
|
||||
ElseCondition.new
|
||||
else
|
||||
switch_parse(markup)
|
||||
parse_with_selected_parser(markup)
|
||||
end
|
||||
|
||||
@blocks.push(block)
|
||||
@@ -79,7 +79,7 @@ module Liquid
|
||||
|
||||
while op = (p.id?('and') || p.id?('or'))
|
||||
new_cond = parse_comparison(p)
|
||||
new_cond.send(op.to_sym, condition)
|
||||
new_cond.send(op, condition)
|
||||
condition = new_cond
|
||||
end
|
||||
p.consume(:end_of_string)
|
||||
|
||||
Reference in New Issue
Block a user