Make stuff nicer

This commit is contained in:
Tristan Hume
2013-08-02 15:17:17 -04:00
parent 48f50eea3b
commit 15b53b77d6
4 changed files with 6 additions and 15 deletions
-3
View File
@@ -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
View File
@@ -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)
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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)