Use parse_context or options instead of @options.

This commit is contained in:
Dylan Thacker-Smith 2015-07-08 19:21:04 -04:00
parent 920e1df643
commit c45310170b
6 changed files with 18 additions and 16 deletions

View File

@ -26,14 +26,14 @@ module Liquid
def unknown_tag(tag, _params, _tokens)
case tag
when 'else'.freeze
raise SyntaxError.new(options[:locale].t("errors.syntax.unexpected_else".freeze,
raise SyntaxError.new(parse_context.locale.t("errors.syntax.unexpected_else".freeze,
block_name: block_name))
when 'end'.freeze
raise SyntaxError.new(options[:locale].t("errors.syntax.invalid_delimiter".freeze,
raise SyntaxError.new(parse_context.locale.t("errors.syntax.invalid_delimiter".freeze,
block_name: block_name,
block_delimiter: block_delimiter))
else
raise SyntaxError.new(options[:locale].t("errors.syntax.unknown_tag".freeze, tag: tag))
raise SyntaxError.new(parse_context.locale.t("errors.syntax.unknown_tag".freeze, tag: tag))
end
end
@ -48,12 +48,12 @@ module Liquid
protected
def parse_body(body, tokens)
body.parse(tokens, options) do |end_tag_name, end_tag_params|
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
@blank &&= body.blank?
return false if end_tag_name == block_delimiter
unless end_tag_name
raise SyntaxError.new(@options[:locale].t("errors.syntax.tag_never_closed".freeze, block_name: block_name))
raise SyntaxError.new(parse_context.locale.t("errors.syntax.tag_never_closed".freeze, block_name: block_name))
end
# this tag is not registered with the system

View File

@ -105,12 +105,12 @@ module Liquid
raise_missing_variable_terminator(token, parse_context)
end
def raise_missing_tag_terminator(token, options)
raise SyntaxError.new(options[:locale].t("errors.syntax.tag_termination".freeze, token: token, tag_end: TagEnd.inspect))
def raise_missing_tag_terminator(token, parse_context)
raise SyntaxError.new(parse_context.locale.t("errors.syntax.tag_termination".freeze, token: token, tag_end: TagEnd.inspect))
end
def raise_missing_variable_terminator(token, options)
raise SyntaxError.new(options[:locale].t("errors.syntax.variable_termination".freeze, token: token, tag_end: VariableEnd.inspect))
def raise_missing_variable_terminator(token, parse_context)
raise SyntaxError.new(parse_context.locale.t("errors.syntax.variable_termination".freeze, token: token, tag_end: VariableEnd.inspect))
end
def registered_tags

View File

@ -1,14 +1,14 @@
module Liquid
module ParserSwitching
def parse_with_selected_parser(markup)
case @options.error_mode
case parse_context.error_mode
when :strict then strict_parse_with_error_context(markup)
when :lax then lax_parse(markup)
when :warn
begin
return strict_parse_with_error_context(markup)
rescue SyntaxError => e
@options.warnings << e
parse_context.warnings << e
return lax_parse(markup)
end
end

View File

@ -1,7 +1,7 @@
module Liquid
class Tag
attr_accessor :options
attr_reader :nodelist, :tag_name, :line_number
attr_reader :nodelist, :tag_name, :line_number, :options
alias_method :parse_context, :options
include ParserSwitching
class << self

View File

@ -3,11 +3,11 @@ module Liquid
Syntax = /\A\s*\z/
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
def initialize(tag_name, markup, options)
def initialize(tag_name, markup, parse_context)
super
unless markup =~ Syntax
raise SyntaxError.new(@options[:locale].t("errors.syntax.tag_unexpected_args".freeze, tag: tag_name))
raise SyntaxError.new(parse_context.locale.t("errors.syntax.tag_unexpected_args".freeze, tag: tag_name))
end
end
@ -21,7 +21,7 @@ module Liquid
@body << token unless token.empty?
end
raise SyntaxError.new(@options[:locale].t("errors.syntax.tag_never_closed".freeze, block_name: block_name))
raise SyntaxError.new(parse_context.locale.t("errors.syntax.tag_never_closed".freeze, block_name: block_name))
end
def render(_context)

View File

@ -12,6 +12,8 @@ module Liquid
class Variable
FilterParser = /(?:\s+|#{QuotedFragment}|#{ArgumentSeparator})+/o
attr_accessor :filters, :name, :line_number
attr_reader :options
alias_method :parse_context, :options
include ParserSwitching
def initialize(markup, parse_context)