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

View File

@@ -2,7 +2,7 @@
module Liquid
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
include ParserSwitching

View File

@@ -19,11 +19,11 @@ module Liquid
attr_reader :to, :from
def parse(_tokens)
if @markup =~ Syntax
if markup =~ Syntax
@to = Regexp.last_match(1)
@from = Variable.new(Regexp.last_match(2), @parse_context)
@from = Variable.new(Regexp.last_match(2), options)
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

View File

@@ -16,10 +16,10 @@ module Liquid
Syntax = /(#{VariableSignature}+)/o
def parse(_tokens)
if @markup =~ Syntax
if markup =~ Syntax
@to = Regexp.last_match(1)
else
raise SyntaxError, @parse_context[:locale].t("errors.syntax.capture")
raise SyntaxError, options[:locale].t("errors.syntax.capture")
end
super
end

View File

@@ -10,10 +10,10 @@ module Liquid
def parse(tokens)
@blocks = []
if @markup =~ Syntax
if options =~ Syntax
@left = Expression.parse(Regexp.last_match(1))
else
raise SyntaxError, @parse_context[:locale].t("errors.syntax.case")
raise SyntaxError, options[:locale].t("errors.syntax.case")
end
body = BlockBody.new

View File

@@ -20,7 +20,7 @@ module Liquid
attr_reader :variables
def parse(_tokens)
case @markup
case markup
when NamedSyntax
@variables = variables_from_string(Regexp.last_match(2))
@name = Expression.parse(Regexp.last_match(1))
@@ -28,7 +28,7 @@ module Liquid
@variables = variables_from_string(@markup)
@name = @variables.to_s
else
raise SyntaxError, @parse_context[:locale].t("errors.syntax.cycle")
raise SyntaxError, options[:locale].t("errors.syntax.cycle")
end
end

View File

@@ -21,7 +21,7 @@ module Liquid
#
class Decrement < Tag
def parse(_tokens)
@variable = @markup.strip
@variable = markup.strip
end
def render_to_output_buffer(context, output)

View File

@@ -15,7 +15,7 @@ module Liquid
attr_reader :variable
def parse(_tokens)
@variable = Variable.new(@markup, @parse_context)
@variable = Variable.new(markup, options)
end
def render(context)

View File

@@ -54,7 +54,7 @@ module Liquid
@from = @limit = nil
@for_block = BlockBody.new
@else_block = nil
parse_with_selected_parser(@markup)
parse_with_selected_parser(markup)
return unless parse_body(@for_block, tokens)
parse_body(@else_block, tokens)
end

View File

@@ -24,7 +24,7 @@ module Liquid
def parse(tokens)
@blocks = []
push_block('if', @markup)
push_block('if', markup)
while parse_body(@blocks.last.attachment, tokens)
end
end

View File

@@ -22,7 +22,7 @@ module Liquid
attr_reader :template_name_expr, :variable_name_expr, :attributes
def parse(_tokens)
if @markup =~ SYNTAX
if markup =~ SYNTAX
template_name = Regexp.last_match(1)
variable_name = Regexp.last_match(3)
@@ -32,12 +32,12 @@ module Liquid
@template_name_expr = Expression.parse(template_name)
@attributes = {}
@markup.scan(TagAttributes) do |key, value|
markup.scan(TagAttributes) do |key, value|
@attributes[key] = Expression.parse(value)
end
else
raise SyntaxError, @parse_context[:locale].t("errors.syntax.include")
raise SyntaxError, options[:locale].t("errors.syntax.include")
end
end

View File

@@ -18,7 +18,7 @@ module Liquid
#
class Increment < Tag
def parse(_tokens)
@variable = @markup.strip
@variable = markup.strip
end
def render_to_output_buffer(context, output)

View File

@@ -6,7 +6,7 @@ module Liquid
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
def parse(tokens)
ensure_valid_markup(@tag_name, @markup, @parse_context)
ensure_valid_markup(tag_name, markup, options)
@body = +''
while (token = tokens.shift)
if token =~ FullTokenPossiblyInvalid
@@ -16,7 +16,7 @@ module Liquid
@body << token unless token.empty?
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
def render_to_output_buffer(_context, output)

View File

@@ -9,7 +9,7 @@ module Liquid
attr_reader :template_name_expr, :attributes
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)
variable_name = Regexp.last_match(3)
@@ -19,7 +19,7 @@ module Liquid
@template_name_expr = Expression.parse(template_name)
@attributes = {}
@markup.scan(TagAttributes) do |key, value|
markup.scan(TagAttributes) do |key, value|
@attributes[key] = Expression.parse(value)
end
end

View File

@@ -7,15 +7,15 @@ module Liquid
attr_reader :variable_name, :collection_name, :attributes
def parse(_tokens)
if @markup =~ Syntax
if markup =~ Syntax
@variable_name = Regexp.last_match(1)
@collection_name = Expression.parse(Regexp.last_match(2))
@attributes = {}
@markup.scan(TagAttributes) do |key, value|
markup.scan(TagAttributes) do |key, value|
@attributes[key] = Expression.parse(value)
end
else
raise SyntaxError, @parse_context[:locale].t("errors.syntax.table_row")
raise SyntaxError, options[:locale].t("errors.syntax.table_row")
end
super
end