Use accessors

This commit is contained in:
Mike Angell
2019-10-16 01:54:45 +10:00
parent 03a5375c8c
commit 938ca78be6
14 changed files with 25 additions and 25 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
module Liquid module Liquid
class Tag class Tag
attr_reader :nodelist, :tag_name, :line_number, :parse_context attr_reader :nodelist, :tag_name, :line_number, :parse_context, :markup
alias_method :options, :parse_context alias_method :options, :parse_context
include ParserSwitching include ParserSwitching
+3 -3
View File
@@ -19,11 +19,11 @@ module Liquid
attr_reader :to, :from attr_reader :to, :from
def parse(_tokens) def parse(_tokens)
if @markup =~ Syntax if markup =~ Syntax
@to = Regexp.last_match(1) @to = Regexp.last_match(1)
@from = Variable.new(Regexp.last_match(2), @parse_context) @from = Variable.new(Regexp.last_match(2), options)
else else
raise SyntaxError, @parse_context[:locale].t(self.class.syntax_error_translation_key) raise SyntaxError, options[:locale].t(self.class.syntax_error_translation_key)
end end
end end
+2 -2
View File
@@ -16,10 +16,10 @@ module Liquid
Syntax = /(#{VariableSignature}+)/o Syntax = /(#{VariableSignature}+)/o
def parse(_tokens) def parse(_tokens)
if @markup =~ Syntax if markup =~ Syntax
@to = Regexp.last_match(1) @to = Regexp.last_match(1)
else else
raise SyntaxError, @parse_context[:locale].t("errors.syntax.capture") raise SyntaxError, options[:locale].t("errors.syntax.capture")
end end
super super
end end
+2 -2
View File
@@ -10,10 +10,10 @@ module Liquid
def parse(tokens) def parse(tokens)
@blocks = [] @blocks = []
if @markup =~ Syntax if options =~ Syntax
@left = Expression.parse(Regexp.last_match(1)) @left = Expression.parse(Regexp.last_match(1))
else else
raise SyntaxError, @parse_context[:locale].t("errors.syntax.case") raise SyntaxError, options[:locale].t("errors.syntax.case")
end end
body = BlockBody.new body = BlockBody.new
+2 -2
View File
@@ -20,7 +20,7 @@ module Liquid
attr_reader :variables attr_reader :variables
def parse(_tokens) def parse(_tokens)
case @markup case markup
when NamedSyntax when NamedSyntax
@variables = variables_from_string(Regexp.last_match(2)) @variables = variables_from_string(Regexp.last_match(2))
@name = Expression.parse(Regexp.last_match(1)) @name = Expression.parse(Regexp.last_match(1))
@@ -28,7 +28,7 @@ module Liquid
@variables = variables_from_string(@markup) @variables = variables_from_string(@markup)
@name = @variables.to_s @name = @variables.to_s
else else
raise SyntaxError, @parse_context[:locale].t("errors.syntax.cycle") raise SyntaxError, options[:locale].t("errors.syntax.cycle")
end end
end end
+1 -1
View File
@@ -21,7 +21,7 @@ module Liquid
# #
class Decrement < Tag class Decrement < Tag
def parse(_tokens) def parse(_tokens)
@variable = @markup.strip @variable = markup.strip
end end
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
+1 -1
View File
@@ -15,7 +15,7 @@ module Liquid
attr_reader :variable attr_reader :variable
def parse(_tokens) def parse(_tokens)
@variable = Variable.new(@markup, @parse_context) @variable = Variable.new(markup, options)
end end
def render(context) def render(context)
+1 -1
View File
@@ -54,7 +54,7 @@ module Liquid
@from = @limit = nil @from = @limit = nil
@for_block = BlockBody.new @for_block = BlockBody.new
@else_block = nil @else_block = nil
parse_with_selected_parser(@markup) parse_with_selected_parser(markup)
return unless parse_body(@for_block, tokens) return unless parse_body(@for_block, tokens)
parse_body(@else_block, tokens) parse_body(@else_block, tokens)
end end
+1 -1
View File
@@ -24,7 +24,7 @@ module Liquid
def parse(tokens) def parse(tokens)
@blocks = [] @blocks = []
push_block('if', @markup) push_block('if', markup)
while parse_body(@blocks.last.attachment, tokens) while parse_body(@blocks.last.attachment, tokens)
end end
end end
+3 -3
View File
@@ -22,7 +22,7 @@ module Liquid
attr_reader :template_name_expr, :variable_name_expr, :attributes attr_reader :template_name_expr, :variable_name_expr, :attributes
def parse(_tokens) def parse(_tokens)
if @markup =~ SYNTAX if markup =~ SYNTAX
template_name = Regexp.last_match(1) template_name = Regexp.last_match(1)
variable_name = Regexp.last_match(3) variable_name = Regexp.last_match(3)
@@ -32,12 +32,12 @@ module Liquid
@template_name_expr = Expression.parse(template_name) @template_name_expr = Expression.parse(template_name)
@attributes = {} @attributes = {}
@markup.scan(TagAttributes) do |key, value| markup.scan(TagAttributes) do |key, value|
@attributes[key] = Expression.parse(value) @attributes[key] = Expression.parse(value)
end end
else else
raise SyntaxError, @parse_context[:locale].t("errors.syntax.include") raise SyntaxError, options[:locale].t("errors.syntax.include")
end end
end end
+1 -1
View File
@@ -18,7 +18,7 @@ module Liquid
# #
class Increment < Tag class Increment < Tag
def parse(_tokens) def parse(_tokens)
@variable = @markup.strip @variable = markup.strip
end end
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
+2 -2
View File
@@ -6,7 +6,7 @@ module Liquid
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
def parse(tokens) def parse(tokens)
ensure_valid_markup(@tag_name, @markup, @parse_context) ensure_valid_markup(tag_name, markup, options)
@body = +'' @body = +''
while (token = tokens.shift) while (token = tokens.shift)
if token =~ FullTokenPossiblyInvalid if token =~ FullTokenPossiblyInvalid
@@ -16,7 +16,7 @@ module Liquid
@body << token unless token.empty? @body << token unless token.empty?
end end
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_never_closed", block_name: block_name) raise SyntaxError, options.locale.t("errors.syntax.tag_never_closed", block_name: block_name)
end end
def render_to_output_buffer(_context, output) def render_to_output_buffer(_context, output)
+2 -2
View File
@@ -9,7 +9,7 @@ module Liquid
attr_reader :template_name_expr, :attributes attr_reader :template_name_expr, :attributes
def parse(_tokens) def parse(_tokens)
raise SyntaxError, @parse_context[:locale].t("errors.syntax.render") unless @markup =~ SYNTAX raise SyntaxError, options[:locale].t("errors.syntax.render") unless markup =~ SYNTAX
template_name = Regexp.last_match(1) template_name = Regexp.last_match(1)
variable_name = Regexp.last_match(3) variable_name = Regexp.last_match(3)
@@ -19,7 +19,7 @@ module Liquid
@template_name_expr = Expression.parse(template_name) @template_name_expr = Expression.parse(template_name)
@attributes = {} @attributes = {}
@markup.scan(TagAttributes) do |key, value| markup.scan(TagAttributes) do |key, value|
@attributes[key] = Expression.parse(value) @attributes[key] = Expression.parse(value)
end end
end end
+3 -3
View File
@@ -7,15 +7,15 @@ module Liquid
attr_reader :variable_name, :collection_name, :attributes attr_reader :variable_name, :collection_name, :attributes
def parse(_tokens) def parse(_tokens)
if @markup =~ Syntax if markup =~ Syntax
@variable_name = Regexp.last_match(1) @variable_name = Regexp.last_match(1)
@collection_name = Expression.parse(Regexp.last_match(2)) @collection_name = Expression.parse(Regexp.last_match(2))
@attributes = {} @attributes = {}
@markup.scan(TagAttributes) do |key, value| markup.scan(TagAttributes) do |key, value|
@attributes[key] = Expression.parse(value) @attributes[key] = Expression.parse(value)
end end
else else
raise SyntaxError, @parse_context[:locale].t("errors.syntax.table_row") raise SyntaxError, options[:locale].t("errors.syntax.table_row")
end end
super super
end end