From a4ec6a08cbb9bcab049da35849358b005fe5a88a Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Wed, 18 Sep 2019 15:01:00 +1000 Subject: [PATCH 1/6] Change all constants to screaming case --- .rubocop_todo.yml | 19 ------ lib/liquid.rb | 40 ++++++------ lib/liquid/block_body.rb | 34 +++++----- lib/liquid/legacy.rb | 79 +++++++++++++++++++++++ lib/liquid/tags/assign.rb | 4 +- lib/liquid/tags/capture.rb | 4 +- lib/liquid/tags/case.rb | 8 +-- lib/liquid/tags/cycle.rb | 10 +-- lib/liquid/tags/for.rb | 6 +- lib/liquid/tags/if.rb | 10 +-- lib/liquid/tags/include.rb | 6 +- lib/liquid/tags/raw.rb | 8 +-- lib/liquid/tags/render.rb | 4 +- lib/liquid/tags/table_row.rb | 6 +- lib/liquid/tokenizer.rb | 2 +- lib/liquid/variable.rb | 22 +++---- lib/liquid/variable_lookup.rb | 2 +- performance/shopify/comment_form.rb | 4 +- performance/shopify/paginate.rb | 6 +- test/integration/tags/include_tag_test.rb | 4 +- test/unit/regexp_unit_test.rb | 30 ++++----- 21 files changed, 185 insertions(+), 123 deletions(-) create mode 100644 lib/liquid/legacy.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 127162899..c1e39a411 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -52,25 +52,6 @@ Lint/Void: Metrics/LineLength: Max: 294 -# Offense count: 44 -Naming/ConstantName: - Exclude: - - 'lib/liquid.rb' - - 'lib/liquid/block_body.rb' - - 'lib/liquid/tags/assign.rb' - - 'lib/liquid/tags/capture.rb' - - 'lib/liquid/tags/case.rb' - - 'lib/liquid/tags/cycle.rb' - - 'lib/liquid/tags/for.rb' - - 'lib/liquid/tags/if.rb' - - 'lib/liquid/tags/include.rb' - - 'lib/liquid/tags/raw.rb' - - 'lib/liquid/tags/table_row.rb' - - 'lib/liquid/variable.rb' - - 'performance/shopify/comment_form.rb' - - 'performance/shopify/paginate.rb' - - 'test/integration/tags/include_tag_test.rb' - # Offense count: 5 Style/ClassVars: Exclude: diff --git a/lib/liquid.rb b/lib/liquid.rb index d102530cc..7b4f098e7 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -22,25 +22,25 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. module Liquid - FilterSeparator = /\|/ - ArgumentSeparator = ',' - FilterArgumentSeparator = ':' - VariableAttributeSeparator = '.' - WhitespaceControl = '-' - TagStart = /\{\%/ - TagEnd = /\%\}/ - VariableSignature = /\(?[\w\-\.\[\]]\)?/ - VariableSegment = /[\w\-]/ - VariableStart = /\{\{/ - VariableEnd = /\}\}/ - VariableIncompleteEnd = /\}\}?/ - QuotedString = /"[^"]*"|'[^']*'/ - QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o - TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o - AnyStartingTag = /#{TagStart}|#{VariableStart}/o - PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om - TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om - VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o + FILTER_SEPARATOR = /\|/ + ARGUMENT_SEPARATOR = ',' + FILTER_ARGUMENT_SEPARATOR = ':' + VARIABLE_ATTRIBUTE_SEPARATOR = '.' + WHITESPACE_CONTROL = '-' + TAG_START = /\{\%/ + TAG_END = /\%\}/ + VARIABLE_SIGNATURE = /\(?[\w\-\.\[\]]\)?/ + VARIABLE_SEGMENT = /[\w\-]/ + VARIABLE_START = /\{\{/ + VARIABLE_END = /\}\}/ + VARIABLE_INCOMPLETE_END = /\}\}?/ + QUOTED_STRING = /"[^"]*"|'[^']*'/ + QUOTED_FRAGMENT = /#{QUOTED_STRING}|(?:[^\s,\|'"]|#{QUOTED_STRING})+/o + TAG_ATTRIBUTES = /(\w+)\s*\:\s*(#{QUOTED_FRAGMENT})/o + ANY_STARTING_TAG = /#{TAG_START}|#{VARIABLE_START}/o + PARTIAL_TEMPLATE_PARSER = /#{TAG_START}.*?#{TAG_END}|#{VARIABLE_START}.*?#{VARIABLE_INCOMPLETE_END}/om + TEMPLATE_PARSER = /(#{PARTIAL_TEMPLATE_PARSER}|#{ANY_STARTING_TAG})/om + VARIABLE_PARSER = /\[[^\]]+\]|#{VARIABLE_SEGMENT}+\??/o singleton_class.send(:attr_accessor, :cache_classes) self.cache_classes = true @@ -83,3 +83,5 @@ module Liquid # Load all the tags of the standard library # Dir["#{__dir__}/liquid/tags/*.rb"].each { |f| require f } + +require 'liquid/legacy' diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index c4ce2671f..4faba0bd9 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -2,12 +2,12 @@ module Liquid class BlockBody - LiquidTagToken = /\A\s*(\w+)\s*(.*?)\z/o - FullToken = /\A#{TagStart}#{WhitespaceControl}?(\s*)(\w+)(\s*)(.*?)#{WhitespaceControl}?#{TagEnd}\z/om - ContentOfVariable = /\A#{VariableStart}#{WhitespaceControl}?(.*?)#{WhitespaceControl}?#{VariableEnd}\z/om - WhitespaceOrNothing = /\A\s*\z/ - TAGSTART = "{%" - VARSTART = "{{" + LIQUID_TAG_TOKEN = /\A\s*(\w+)\s*(.*?)\z/o + FULL_TOKEN = /\A#{TAG_START}#{WHITESPACE_CONTROL}?(\s*)(\w+)(\s*)(.*?)#{WHITESPACE_CONTROL}?#{TAG_END}\z/om + CONTENT_OF_VARIABLE = /\A#{VARIABLE_START}#{WHITESPACE_CONTROL}?(.*?)#{WHITESPACE_CONTROL}?#{VARIABLE_END}\z/om + WHITESPACE_OR_NOTHING = /\A\s*\z/ + TAG_START_STRING = "{%" + VAR_START_STRING = "{{" attr_reader :nodelist @@ -28,8 +28,8 @@ def parse(tokenizer, parse_context, &block) private def parse_for_liquid_tag(tokenizer, parse_context) while token = tokenizer.shift - unless token.empty? || token =~ WhitespaceOrNothing - unless token =~ LiquidTagToken + unless token.empty? || token =~ WHITESPACE_OR_NOTHING + unless token =~ LIQUID_TAG_TOKEN # line isn't empty but didn't match tag syntax, yield and let the # caller raise a syntax error return yield token, token @@ -55,9 +55,9 @@ def parse(tokenizer, parse_context, &block) while token = tokenizer.shift next if token.empty? case - when token.start_with?(TAGSTART) + when token.start_with?(TAG_START_STRING) whitespace_handler(token, parse_context) - unless token =~ FullToken + unless token =~ FULL_TOKEN raise_missing_tag_terminator(token, parse_context) end tag_name = Regexp.last_match(2) @@ -82,7 +82,7 @@ def parse(tokenizer, parse_context, &block) new_tag = tag.parse(tag_name, markup, tokenizer, parse_context) @blank &&= new_tag.blank? @nodelist << new_tag - when token.start_with?(VARSTART) + when token.start_with?(VAR_START_STRING) whitespace_handler(token, parse_context) @nodelist << create_variable(token, parse_context) @blank = false @@ -92,7 +92,7 @@ def parse(tokenizer, parse_context, &block) end parse_context.trim_whitespace = false @nodelist << token - @blank &&= !!(token =~ WhitespaceOrNothing) + @blank &&= !!(token =~ WHITESPACE_OR_NOTHING) end parse_context.line_number = tokenizer.line_number end @@ -101,13 +101,13 @@ def parse(tokenizer, parse_context, &block) end def whitespace_handler(token, parse_context) - if token[2] == WhitespaceControl + if token[2] == WHITESPACE_CONTROL previous_token = @nodelist.last if previous_token.is_a?(String) previous_token.rstrip! end end - parse_context.trim_whitespace = (token[-3] == WhitespaceControl) + parse_context.trim_whitespace = (token[-3] == WHITESPACE_CONTROL) end def blank? @@ -169,7 +169,7 @@ def raise_if_resource_limits_reached(context, length) end def create_variable(token, parse_context) - token.scan(ContentOfVariable) do |content| + token.scan(CONTENT_OF_VARIABLE) do |content| markup = content.first return Variable.new(markup, parse_context) end @@ -177,11 +177,11 @@ def create_variable(token, parse_context) end def raise_missing_tag_terminator(token, parse_context) - raise SyntaxError, parse_context.locale.t("errors.syntax.tag_termination", token: token, tag_end: TagEnd.inspect) + raise SyntaxError, parse_context.locale.t("errors.syntax.tag_termination", token: token, tag_end: TAG_END.inspect) end def raise_missing_variable_terminator(token, parse_context) - raise SyntaxError, parse_context.locale.t("errors.syntax.variable_termination", token: token, tag_end: VariableEnd.inspect) + raise SyntaxError, parse_context.locale.t("errors.syntax.variable_termination", token: token, tag_end: VARIABLE_END.inspect) end def registered_tags diff --git a/lib/liquid/legacy.rb b/lib/liquid/legacy.rb new file mode 100644 index 000000000..5cd66bc0b --- /dev/null +++ b/lib/liquid/legacy.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +module Liquid + FilterSeparator = FILTER_SEPARATOR + ArgumentSeparator = ARGUMENT_SEPARATOR + FilterArgumentSeparator = FILTER_ARGUMENT_SEPARATOR + VariableAttributeSeparator = VARIABLE_ATTRIBUTE_SEPARATOR + WhitespaceControl = WHITESPACE_CONTROL + TagStart = TAG_START + TagEnd = TAG_END + VariableSignature = VARIABLE_SIGNATURE + VariableSegment = VARIABLE_SEGMENT + VariableStart = VARIABLE_START + VariableEnd = VARIABLE_END + VariableIncompleteEnd = VARIABLE_INCOMPLETE_END + QuotedString = QUOTED_STRING + QuotedFragment = QUOTED_FRAGMENT + TagAttributes = TAG_ATTRIBUTES + AnyStartingTag = ANY_STARTING_TAG + PartialTemplateParser = PARTIAL_TEMPLATE_PARSER + TemplateParser = TEMPLATE_PARSER + VariableParser = VARIABLE_PARSER + + class BlockBody + FullToken = FULL_TOKEN + ContentOfVariable = CONTENT_OF_VARIABLE + WhitespaceOrNothing = WHITESPACE_OR_NOTHING + TAGSTART = TAG_START_STRING + VARSTART = VAR_START_STRING + end + + class Assign < Tag + Syntax = SYNTAX + end + + class Capture < Block + Syntax = SYNTAX + end + + class Case < Block + Syntax = SYNTAX + WhenSyntax = WHEN_SYNTAX + end + + class Cycle < Tag + SimpleSyntax = SIMPLE_SYNTAX + NamedSyntax = NAMED_SYNTAX + end + + class For < Block + Syntax = SYNTAX + end + + class If < Block + Syntax = SYNTAX + ExpressionsAndOperators = EXPRESSIONS_AND_OPERATORS + end + + class Include < Tag + Syntax = SYNTAX + end + + class Raw < Block + Syntax = SYNTAX + FullTokenPossiblyInvalid = FULL_TOKEN_POSSIBLY_INVALID + end + + class TableRow < Block + Syntax = SYNTAX + end + + class Variable + FilterMarkupRegex = FILTER_MARKUP_REGEX + FilterParser = FILTER_PARSER + FilterArgsRegex = FILTER_ARGS_REGEX + JustTagAttributes = JUST_TAG_ATTRIBUTES + MarkupWithQuotedFragment = MARKUP_WITH_QUOTED_FRAGMENT + end +end diff --git a/lib/liquid/tags/assign.rb b/lib/liquid/tags/assign.rb index aaad14cfd..332c605c8 100644 --- a/lib/liquid/tags/assign.rb +++ b/lib/liquid/tags/assign.rb @@ -10,7 +10,7 @@ module Liquid # {{ foo }} # class Assign < Tag - Syntax = /(#{VariableSignature}+)\s*=\s*(.*)\s*/om + SYNTAX = /(#{VARIABLE_SIGNATURE}+)\s*=\s*(.*)\s*/om def self.syntax_error_translation_key "errors.syntax.assign" @@ -20,7 +20,7 @@ def self.syntax_error_translation_key def initialize(tag_name, markup, options) super - if markup =~ Syntax + if markup =~ SYNTAX @to = Regexp.last_match(1) @from = Variable.new(Regexp.last_match(2), options) else diff --git a/lib/liquid/tags/capture.rb b/lib/liquid/tags/capture.rb index 1cace9c1c..ee6e6d005 100644 --- a/lib/liquid/tags/capture.rb +++ b/lib/liquid/tags/capture.rb @@ -13,11 +13,11 @@ module Liquid # in a sidebar or footer. # class Capture < Block - Syntax = /(#{VariableSignature}+)/o + SYNTAX = /(#{VARIABLE_SIGNATURE}+)/o def initialize(tag_name, markup, options) super - if markup =~ Syntax + if markup =~ SYNTAX @to = Regexp.last_match(1) else raise SyntaxError, options[:locale].t("errors.syntax.capture") diff --git a/lib/liquid/tags/case.rb b/lib/liquid/tags/case.rb index 30484c6d5..1f5196aeb 100644 --- a/lib/liquid/tags/case.rb +++ b/lib/liquid/tags/case.rb @@ -2,8 +2,8 @@ module Liquid class Case < Block - Syntax = /(#{QuotedFragment})/o - WhenSyntax = /(#{QuotedFragment})(?:(?:\s+or\s+|\s*\,\s*)(#{QuotedFragment}.*))?/om + SYNTAX = /(#{QUOTED_FRAGMENT})/o + WHEN_SYNTAX = /(#{QUOTED_FRAGMENT})(?:(?:\s+or\s+|\s*\,\s*)(#{QUOTED_FRAGMENT}.*))?/om attr_reader :blocks, :left @@ -11,7 +11,7 @@ def initialize(tag_name, markup, options) super @blocks = [] - if markup =~ Syntax + if markup =~ SYNTAX @left = Expression.parse(Regexp.last_match(1)) else raise SyntaxError, options[:locale].t("errors.syntax.case") @@ -59,7 +59,7 @@ def record_when_condition(markup) body = BlockBody.new while markup - unless markup =~ WhenSyntax + unless markup =~ WHEN_SYNTAX raise SyntaxError, options[:locale].t("errors.syntax.case_invalid_when") end diff --git a/lib/liquid/tags/cycle.rb b/lib/liquid/tags/cycle.rb index b203c785f..d6c490df8 100644 --- a/lib/liquid/tags/cycle.rb +++ b/lib/liquid/tags/cycle.rb @@ -14,18 +14,18 @@ module Liquid #
Item five
# class Cycle < Tag - SimpleSyntax = /\A#{QuotedFragment}+/o - NamedSyntax = /\A(#{QuotedFragment})\s*\:\s*(.*)/om + SIMPLE_SYNTAX = /\A#{QUOTED_FRAGMENT}+/o + NAMED_SYNTAX = /\A(#{QUOTED_FRAGMENT})\s*\:\s*(.*)/om attr_reader :variables def initialize(tag_name, markup, options) super case markup - when NamedSyntax + when NAMED_SYNTAX @variables = variables_from_string(Regexp.last_match(2)) @name = Expression.parse(Regexp.last_match(1)) - when SimpleSyntax + when SIMPLE_SYNTAX @variables = variables_from_string(markup) @name = @variables.to_s else @@ -60,7 +60,7 @@ def render_to_output_buffer(context, output) def variables_from_string(markup) markup.split(',').collect do |var| - var =~ /\s*(#{QuotedFragment})\s*/o + var =~ /\s*(#{QUOTED_FRAGMENT})\s*/o Regexp.last_match(1) ? Expression.parse(Regexp.last_match(1)) : nil end.compact end diff --git a/lib/liquid/tags/for.rb b/lib/liquid/tags/for.rb index d9613697f..2819337d3 100644 --- a/lib/liquid/tags/for.rb +++ b/lib/liquid/tags/for.rb @@ -46,7 +46,7 @@ module Liquid # forloop.parentloop:: Provides access to the parent loop, if present. # class For < Block - Syntax = /\A(#{VariableSegment}+)\s+in\s+(#{QuotedFragment}+)\s*(reversed)?/o + SYNTAX = /\A(#{VARIABLE_SEGMENT}+)\s+in\s+(#{QUOTED_FRAGMENT}+)\s*(reversed)?/o attr_reader :collection_name, :variable_name, :limit, :from @@ -87,13 +87,13 @@ def render_to_output_buffer(context, output) protected def lax_parse(markup) - if markup =~ Syntax + if markup =~ SYNTAX @variable_name = Regexp.last_match(1) collection_name = Regexp.last_match(2) @reversed = !!Regexp.last_match(3) @name = "#{@variable_name}-#{collection_name}" @collection_name = Expression.parse(collection_name) - markup.scan(TagAttributes) do |key, value| + markup.scan(TAG_ATTRIBUTES) do |key, value| set_attribute(key, value) end else diff --git a/lib/liquid/tags/if.rb b/lib/liquid/tags/if.rb index c3d1a777a..db1a28312 100644 --- a/lib/liquid/tags/if.rb +++ b/lib/liquid/tags/if.rb @@ -12,8 +12,8 @@ module Liquid # There are {% if count < 5 %} less {% else %} more {% endif %} items than you need. # class If < Block - Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/o - ExpressionsAndOperators = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QuotedFragment}|\S+)\s*)+)/o + SYNTAX = /(#{QUOTED_FRAGMENT})\s*([=!<>a-z_]+)?\s*(#{QUOTED_FRAGMENT})?/o + EXPRESSIONS_AND_OPERATORS = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QUOTED_FRAGMENT}|\S+)\s*)+)/o BOOLEAN_OPERATORS = %w(and or).freeze attr_reader :blocks @@ -65,15 +65,15 @@ def push_block(tag, markup) end def lax_parse(markup) - expressions = markup.scan(ExpressionsAndOperators) - raise SyntaxError, options[:locale].t("errors.syntax.if") unless expressions.pop =~ Syntax + expressions = markup.scan(EXPRESSIONS_AND_OPERATORS) + raise SyntaxError, options[:locale].t("errors.syntax.if") unless expressions.pop =~ SYNTAX condition = Condition.new(Expression.parse(Regexp.last_match(1)), Regexp.last_match(2), Expression.parse(Regexp.last_match(3))) until expressions.empty? operator = expressions.pop.to_s.strip - raise SyntaxError, options[:locale].t("errors.syntax.if") unless expressions.pop.to_s =~ Syntax + raise SyntaxError, options[:locale].t("errors.syntax.if") unless expressions.pop.to_s =~ SYNTAX new_condition = Condition.new(Expression.parse(Regexp.last_match(1)), Regexp.last_match(2), Expression.parse(Regexp.last_match(3))) raise SyntaxError, options[:locale].t("errors.syntax.if") unless BOOLEAN_OPERATORS.include?(operator) diff --git a/lib/liquid/tags/include.rb b/lib/liquid/tags/include.rb index bbcfb1cc4..379c6c1d6 100644 --- a/lib/liquid/tags/include.rb +++ b/lib/liquid/tags/include.rb @@ -16,14 +16,14 @@ module Liquid # {% include 'product' for products %} # class Include < Tag - Syntax = /(#{QuotedFragment}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?/o + SYNTAX = /(#{QUOTED_FRAGMENT}+)(\s+(?:with|for)\s+(#{QUOTED_FRAGMENT}+))?/o attr_reader :template_name_expr, :variable_name_expr, :attributes def initialize(tag_name, markup, options) super - if markup =~ Syntax + if markup =~ SYNTAX template_name = Regexp.last_match(1) variable_name = Regexp.last_match(3) @@ -32,7 +32,7 @@ def initialize(tag_name, markup, options) @template_name_expr = Expression.parse(template_name) @attributes = {} - markup.scan(TagAttributes) do |key, value| + markup.scan(TAG_ATTRIBUTES) do |key, value| @attributes[key] = Expression.parse(value) end diff --git a/lib/liquid/tags/raw.rb b/lib/liquid/tags/raw.rb index 093a37e17..996a34ce5 100644 --- a/lib/liquid/tags/raw.rb +++ b/lib/liquid/tags/raw.rb @@ -2,8 +2,8 @@ module Liquid class Raw < Block - Syntax = /\A\s*\z/ - FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om + SYNTAX = /\A\s*\z/ + FULL_TOKEN_POSSIBLY_INVALID = /\A(.*)#{TAG_START}\s*(\w+)\s*(.*)?#{TAG_END}\z/om def initialize(tag_name, markup, parse_context) super @@ -14,7 +14,7 @@ def initialize(tag_name, markup, parse_context) def parse(tokens) @body = +'' while token = tokens.shift - if token =~ FullTokenPossiblyInvalid + if token =~ FULL_TOKEN_POSSIBLY_INVALID @body << Regexp.last_match(1) if Regexp.last_match(1) != "" return if block_delimiter == Regexp.last_match(2) end @@ -40,7 +40,7 @@ def blank? protected def ensure_valid_markup(tag_name, markup, parse_context) - unless markup =~ Syntax + unless markup =~ SYNTAX raise SyntaxError, parse_context.locale.t("errors.syntax.tag_unexpected_args", tag: tag_name) end end diff --git a/lib/liquid/tags/render.rb b/lib/liquid/tags/render.rb index e6c622324..0516d7da8 100644 --- a/lib/liquid/tags/render.rb +++ b/lib/liquid/tags/render.rb @@ -2,7 +2,7 @@ module Liquid class Render < Tag - SYNTAX = /(#{QuotedString})#{QuotedFragment}*/o + SYNTAX = /(#{QUOTED_STRING})#{QUOTED_FRAGMENT}*/o attr_reader :template_name_expr, :attributes @@ -16,7 +16,7 @@ def initialize(tag_name, markup, options) @template_name_expr = Expression.parse(template_name) @attributes = {} - markup.scan(TagAttributes) do |key, value| + markup.scan(TAG_ATTRIBUTES) do |key, value| @attributes[key] = Expression.parse(value) end end diff --git a/lib/liquid/tags/table_row.rb b/lib/liquid/tags/table_row.rb index 7c59bd323..ec5f9dbd0 100644 --- a/lib/liquid/tags/table_row.rb +++ b/lib/liquid/tags/table_row.rb @@ -2,17 +2,17 @@ module Liquid class TableRow < Block - Syntax = /(\w+)\s+in\s+(#{QuotedFragment}+)/o + SYNTAX = /(\w+)\s+in\s+(#{QUOTED_FRAGMENT}+)/o attr_reader :variable_name, :collection_name, :attributes def initialize(tag_name, markup, options) super - 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(TAG_ATTRIBUTES) do |key, value| @attributes[key] = Expression.parse(value) end else diff --git a/lib/liquid/tokenizer.rb b/lib/liquid/tokenizer.rb index a89c7899c..5bffb9a87 100644 --- a/lib/liquid/tokenizer.rb +++ b/lib/liquid/tokenizer.rb @@ -28,7 +28,7 @@ def tokenize return @source.split("\n") if @for_liquid_tag - tokens = @source.split(TemplateParser) + tokens = @source.split(TEMPLATE_PARSER) # removes the rogue empty element at the beginning of the array tokens.shift if tokens[0]&.empty? diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index 2fc2ea858..d18c9d0c6 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -12,11 +12,11 @@ module Liquid # {{ user | link }} # class Variable - FilterMarkupRegex = /#{FilterSeparator}\s*(.*)/om - FilterParser = /(?:\s+|#{QuotedFragment}|#{ArgumentSeparator})+/o - FilterArgsRegex = /(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{QuotedFragment})/o - JustTagAttributes = /\A#{TagAttributes}\z/o - MarkupWithQuotedFragment = /(#{QuotedFragment})(.*)/om + FILTER_MARKUP_REGEX = /#{FILTER_SEPARATOR}\s*(.*)/om + FILTER_PARSER = /(?:\s+|#{QUOTED_FRAGMENT}|#{ARGUMENT_SEPARATOR})+/o + FILTER_ARGS_REGEX = /(?:#{FILTER_ARGUMENT_SEPARATOR}|#{ARGUMENT_SEPARATOR})\s*((?:\w+\s*\:\s*)?#{QUOTED_FRAGMENT})/o + JUST_TAG_ATTRIBUTES = /\A#{TAG_ATTRIBUTES}\z/o + MARKUP_WITH_QUOTED_FRAGMENT = /(#{QUOTED_FRAGMENT})(.*)/om attr_accessor :filters, :name, :line_number attr_reader :parse_context @@ -43,17 +43,17 @@ def markup_context(markup) def lax_parse(markup) @filters = [] - return unless markup =~ MarkupWithQuotedFragment + return unless markup =~ MARKUP_WITH_QUOTED_FRAGMENT name_markup = Regexp.last_match(1) filter_markup = Regexp.last_match(2) @name = Expression.parse(name_markup) - if filter_markup =~ FilterMarkupRegex - filters = Regexp.last_match(1).scan(FilterParser) + if filter_markup =~ FILTER_MARKUP_REGEX + filters = Regexp.last_match(1).scan(FILTER_PARSER) filters.each do |f| next unless f =~ /\w+/ filtername = Regexp.last_match(0) - filterargs = f.scan(FilterArgsRegex).flatten + filterargs = f.scan(FILTER_ARGS_REGEX).flatten @filters << parse_filter_expressions(filtername, filterargs) end end @@ -110,7 +110,7 @@ def parse_filter_expressions(filter_name, unparsed_args) filter_args = [] keyword_args = nil unparsed_args.each do |a| - if matches = a.match(JustTagAttributes) + if matches = a.match(JUST_TAG_ATTRIBUTES) keyword_args ||= {} keyword_args[matches[1]] = Expression.parse(matches[2]) else @@ -138,7 +138,7 @@ def taint_check(context, obj) return unless obj.tainted? return if Template.taint_mode == :lax - @markup =~ QuotedFragment + @markup =~ QUOTED_FRAGMENT name = Regexp.last_match(0) error = TaintedError.new("variable '#{name}' is tainted and was not escaped") diff --git a/lib/liquid/variable_lookup.rb b/lib/liquid/variable_lookup.rb index 112373d5c..c96a5233b 100644 --- a/lib/liquid/variable_lookup.rb +++ b/lib/liquid/variable_lookup.rb @@ -12,7 +12,7 @@ def self.parse(markup) end def initialize(markup) - lookups = markup.scan(VariableParser) + lookups = markup.scan(VARIABLE_PARSER) name = lookups.shift if name =~ SQUARE_BRACKETED diff --git a/performance/shopify/comment_form.rb b/performance/shopify/comment_form.rb index 7648e1a4c..0dabc4bde 100644 --- a/performance/shopify/comment_form.rb +++ b/performance/shopify/comment_form.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true class CommentForm < Liquid::Block - Syntax = /(#{Liquid::VariableSignature}+)/ + SYNTAX = /(#{Liquid::VariableSignature}+)/ def initialize(tag_name, markup, options) super - if markup =~ Syntax + if markup =~ SYNTAX @variable_name = Regexp.last_match(1) @attributes = {} else diff --git a/performance/shopify/paginate.rb b/performance/shopify/paginate.rb index f72382382..07f3cfced 100644 --- a/performance/shopify/paginate.rb +++ b/performance/shopify/paginate.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true class Paginate < Liquid::Block - Syntax = /(#{Liquid::QuotedFragment})\s*(by\s*(\d+))?/ + SYNTAX = /(#{Liquid::QUOTED_FRAGMENT})\s*(by\s*(\d+))?/ def initialize(tag_name, markup, options) super - if markup =~ Syntax + if markup =~ SYNTAX @collection_name = Regexp.last_match(1) @page_size = if Regexp.last_match(2) Regexp.last_match(3).to_i @@ -15,7 +15,7 @@ def initialize(tag_name, markup, options) end @attributes = { 'window_size' => 3 } - markup.scan(Liquid::TagAttributes) do |key, value| + markup.scan(Liquid::TAG_ATTRIBUTES) do |key, value| @attributes[key] = value end else diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index 45410a7a5..686d482e3 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -57,10 +57,10 @@ def read_template_file(_template_path) end class CustomInclude < Liquid::Tag - Syntax = /(#{Liquid::QuotedFragment}+)(\s+(?:with|for)\s+(#{Liquid::QuotedFragment}+))?/o + SYNTAX = /(#{Liquid::QUOTED_FRAGMENT}+)(\s+(?:with|for)\s+(#{Liquid::QUOTED_FRAGMENT}+))?/o def initialize(tag_name, markup, tokens) - markup =~ Syntax + markup =~ SYNTAX @template_name = Regexp.last_match(1) super end diff --git a/test/unit/regexp_unit_test.rb b/test/unit/regexp_unit_test.rb index 666bc6647..c6d1fe652 100644 --- a/test/unit/regexp_unit_test.rb +++ b/test/unit/regexp_unit_test.rb @@ -6,41 +6,41 @@ class RegexpUnitTest < Minitest::Test include Liquid def test_empty - assert_equal [], ''.scan(QuotedFragment) + assert_equal [], ''.scan(QUOTED_FRAGMENT) end def test_quote - assert_equal ['"arg 1"'], '"arg 1"'.scan(QuotedFragment) + assert_equal ['"arg 1"'], '"arg 1"'.scan(QUOTED_FRAGMENT) end def test_words - assert_equal ['arg1', 'arg2'], 'arg1 arg2'.scan(QuotedFragment) + assert_equal ['arg1', 'arg2'], 'arg1 arg2'.scan(QUOTED_FRAGMENT) end def test_tags - assert_equal ['', ''], ' '.scan(QuotedFragment) - assert_equal [''], ''.scan(QuotedFragment) - assert_equal ['', ''], %().scan(QuotedFragment) + assert_equal ['', ''], ' '.scan(QUOTED_FRAGMENT) + assert_equal [''], ''.scan(QUOTED_FRAGMENT) + assert_equal ['', ''], %().scan(QUOTED_FRAGMENT) end def test_double_quoted_words - assert_equal ['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QuotedFragment) + assert_equal ['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QUOTED_FRAGMENT) end def test_single_quoted_words - assert_equal ['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QuotedFragment) + assert_equal ['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QUOTED_FRAGMENT) end def test_quoted_words_in_the_middle - assert_equal ['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4 '.scan(QuotedFragment) + assert_equal ['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4 '.scan(QUOTED_FRAGMENT) end def test_variable_parser - assert_equal ['var'], 'var'.scan(VariableParser) - assert_equal ['var', 'method'], 'var.method'.scan(VariableParser) - assert_equal ['var', '[method]'], 'var[method]'.scan(VariableParser) - assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VariableParser) - assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser) - assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser) + assert_equal ['var'], 'var'.scan(VARIABLE_PARSER) + assert_equal ['var', 'method'], 'var.method'.scan(VARIABLE_PARSER) + assert_equal ['var', '[method]'], 'var[method]'.scan(VARIABLE_PARSER) + assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VARIABLE_PARSER) + assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VARIABLE_PARSER) + assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VARIABLE_PARSER) end end # RegexpTest From 26eb27f79f387a8355b0e0f14fa3c170c3b8c524 Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Fri, 20 Sep 2019 02:25:35 +1000 Subject: [PATCH 2/6] Fix spacing --- .rubocop.yml | 3 + Rakefile | 2 +- example/server/liquid_servlet.rb | 8 +-- lib/liquid.rb | 10 +-- lib/liquid/block_body.rb | 30 ++++----- lib/liquid/condition.rb | 16 ++--- lib/liquid/context.rb | 22 +++--- lib/liquid/errors.rb | 26 ++++---- lib/liquid/expression.rb | 2 +- lib/liquid/file_system.rb | 2 +- lib/liquid/forloop_drop.rb | 6 +- lib/liquid/legacy.rb | 56 ++++++++-------- lib/liquid/lexer.rb | 13 ++-- lib/liquid/parse_context.rb | 12 ++-- lib/liquid/parse_tree_visitor.rb | 8 +-- lib/liquid/parser.rb | 9 ++- lib/liquid/parser_switching.rb | 2 +- lib/liquid/partial_cache.rb | 8 +-- lib/liquid/profiler.rb | 8 +-- lib/liquid/range_lookup.rb | 6 +- lib/liquid/resource_limits.rb | 4 +- lib/liquid/standardfilters.rb | 21 +++--- lib/liquid/static_registers.rb | 2 +- lib/liquid/strainer.rb | 2 +- lib/liquid/tablerowloop_drop.rb | 10 +-- lib/liquid/tag.rb | 6 +- lib/liquid/tags/assign.rb | 8 +-- lib/liquid/tags/capture.rb | 4 +- lib/liquid/tags/case.rb | 2 +- lib/liquid/tags/cycle.rb | 10 +-- lib/liquid/tags/decrement.rb | 4 +- lib/liquid/tags/for.rb | 26 ++++---- lib/liquid/tags/if.rb | 16 ++--- lib/liquid/tags/include.rb | 8 +-- lib/liquid/tags/increment.rb | 2 +- lib/liquid/tags/raw.rb | 4 +- lib/liquid/tags/render.rb | 4 +- lib/liquid/tags/table_row.rb | 8 +-- lib/liquid/template.rb | 22 +++--- lib/liquid/tokenizer.rb | 6 +- lib/liquid/utils.rb | 2 +- lib/liquid/variable.rb | 30 ++++----- lib/liquid/variable_lookup.rb | 10 +-- performance/benchmark.rb | 4 +- performance/profile.rb | 2 +- performance/shopify/comment_form.rb | 2 +- performance/shopify/database.rb | 2 +- performance/shopify/paginate.rb | 2 +- performance/theme_runner.rb | 14 ++-- test/integration/assign_test.rb | 4 +- test/integration/capture_test.rb | 12 ++-- test/integration/drop_test.rb | 2 +- test/integration/error_handling_test.rb | 14 ++-- test/integration/filter_test.rb | 20 +++--- test/integration/output_test.rb | 18 ++--- test/integration/parsing_quirks_test.rb | 2 +- test/integration/security_test.rb | 12 ++-- test/integration/standard_filter_test.rb | 14 ++-- test/integration/tags/break_tag_test.rb | 4 +- test/integration/tags/continue_tag_test.rb | 4 +- test/integration/tags/for_tag_test.rb | 78 +++++++++++----------- test/integration/tags/if_else_tag_test.rb | 6 +- test/integration/tags/include_tag_test.rb | 6 +- test/integration/tags/render_tag_test.rb | 4 +- test/integration/tags/standard_tag_test.rb | 2 +- test/integration/template_test.rb | 64 +++++++++--------- test/integration/trim_mode_test.rb | 76 ++++++++++----------- test/integration/variable_test.rb | 12 ++-- test/test_helper.rb | 10 +-- test/unit/block_unit_test.rb | 4 +- test/unit/condition_unit_test.rb | 6 +- test/unit/context_unit_test.rb | 54 +++++++-------- test/unit/partial_cache_unit_test.rb | 10 +-- test/unit/static_registers_unit_test.rb | 60 ++++++++--------- test/unit/strainer_unit_test.rb | 10 +-- test/unit/tag_unit_test.rb | 4 +- test/unit/template_unit_test.rb | 4 +- test/unit/tokenizer_unit_test.rb | 6 +- 78 files changed, 508 insertions(+), 500 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1c0f83244..c10e4237d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,6 +7,9 @@ require: rubocop-performance Performance: Enabled: true +Layout/ExtraSpacing: + ForceEqualSignAlignment: true + AllCops: TargetRubyVersion: 2.4 Exclude: diff --git a/Rakefile b/Rakefile index 66ae0faee..780ec3535 100755 --- a/Rakefile +++ b/Rakefile @@ -11,7 +11,7 @@ desc('run test suite with default parser') Rake::TestTask.new(:base_test) do |t| t.libs << '.' << 'lib' << 'test' t.test_files = FileList['test/{integration,unit}/**/*_test.rb'] - t.verbose = false + t.verbose = false end desc('run test suite with warn error mode') diff --git a/example/server/liquid_servlet.rb b/example/server/liquid_servlet.rb index 55e21d215..4965fff9a 100644 --- a/example/server/liquid_servlet.rb +++ b/example/server/liquid_servlet.rb @@ -12,16 +12,16 @@ def do_POST(req, res) private def handle(_type, req, res) - @request = req + @request = req @response = res @request.path_info =~ /(\w+)\z/ - @action = Regexp.last_match(1) || 'index' + @action = Regexp.last_match(1) || 'index' @assigns = send(@action) if respond_to?(@action) @response['Content-Type'] = "text/html" - @response.status = 200 - @response.body = Liquid::Template.parse(read_template).render(@assigns, filters: [ProductsFilter]) + @response.status = 200 + @response.body = Liquid::Template.parse(read_template).render(@assigns, filters: [ProductsFilter]) end def read_template(filename = @action) diff --git a/lib/liquid.rb b/lib/liquid.rb index 7b4f098e7..ee7a4ef76 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -24,8 +24,8 @@ module Liquid FILTER_SEPARATOR = /\|/ ARGUMENT_SEPARATOR = ',' - FILTER_ARGUMENT_SEPARATOR = ':' - VARIABLE_ATTRIBUTE_SEPARATOR = '.' + FILTER_ARGUMENT_SEPARATOR = ':' + VARIABLE_ATTRIBUTE_SEPARATOR = '.' WHITESPACE_CONTROL = '-' TAG_START = /\{\%/ TAG_END = /\%\}/ @@ -33,12 +33,12 @@ module Liquid VARIABLE_SEGMENT = /[\w\-]/ VARIABLE_START = /\{\{/ VARIABLE_END = /\}\}/ - VARIABLE_INCOMPLETE_END = /\}\}?/ + VARIABLE_INCOMPLETE_END = /\}\}?/ QUOTED_STRING = /"[^"]*"|'[^']*'/ QUOTED_FRAGMENT = /#{QUOTED_STRING}|(?:[^\s,\|'"]|#{QUOTED_STRING})+/o TAG_ATTRIBUTES = /(\w+)\s*\:\s*(#{QUOTED_FRAGMENT})/o - ANY_STARTING_TAG = /#{TAG_START}|#{VARIABLE_START}/o - PARTIAL_TEMPLATE_PARSER = /#{TAG_START}.*?#{TAG_END}|#{VARIABLE_START}.*?#{VARIABLE_INCOMPLETE_END}/om + ANY_STARTING_TAG = /#{TAG_START}|#{VARIABLE_START}/o + PARTIAL_TEMPLATE_PARSER = /#{TAG_START}.*?#{TAG_END}|#{VARIABLE_START}.*?#{VARIABLE_INCOMPLETE_END}/om TEMPLATE_PARSER = /(#{PARTIAL_TEMPLATE_PARSER}|#{ANY_STARTING_TAG})/om VARIABLE_PARSER = /\[[^\]]+\]|#{VARIABLE_SEGMENT}+\??/o diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 2f3433e4c..0ede86568 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -2,18 +2,18 @@ module Liquid class BlockBody - LIQUID_TAG_TOKEN = /\A\s*(\w+)\s*(.*?)\z/o - FULL_TOKEN = /\A#{TAG_START}#{WHITESPACE_CONTROL}?(\s*)(\w+)(\s*)(.*?)#{WHITESPACE_CONTROL}?#{TAG_END}\z/om - CONTENT_OF_VARIABLE = /\A#{VARIABLE_START}#{WHITESPACE_CONTROL}?(.*?)#{WHITESPACE_CONTROL}?#{VARIABLE_END}\z/om + LIQUID_TAG_TOKEN = /\A\s*(\w+)\s*(.*?)\z/o + FULL_TOKEN = /\A#{TAG_START}#{WHITESPACE_CONTROL}?(\s*)(\w+)(\s*)(.*?)#{WHITESPACE_CONTROL}?#{TAG_END}\z/om + CONTENT_OF_VARIABLE = /\A#{VARIABLE_START}#{WHITESPACE_CONTROL}?(.*?)#{WHITESPACE_CONTROL}?#{VARIABLE_END}\z/om WHITESPACE_OR_NOTHING = /\A\s*\z/ - TAG_START_STRING = "{%" - VAR_START_STRING = "{{" + TAG_START_STRING = "{%" + VAR_START_STRING = "{{" attr_reader :nodelist def initialize @nodelist = [] - @blank = true + @blank = true end def parse(tokenizer, parse_context, &block) @@ -34,15 +34,15 @@ def parse(tokenizer, parse_context, &block) # caller raise a syntax error return yield token, token end - tag_name = Regexp.last_match(1) - markup = Regexp.last_match(2) + tag_name = Regexp.last_match(1) + markup = Regexp.last_match(2) unless (tag = registered_tags[tag_name]) # end parsing if we reach an unknown tag and let the caller decide # determine how to proceed return yield tag_name, markup end - new_tag = tag.parse(tag_name, markup, tokenizer, parse_context) - @blank &&= new_tag.blank? + new_tag = tag.parse(tag_name, markup, tokenizer, parse_context) + @blank &&= new_tag.blank? @nodelist << new_tag end parse_context.line_number = tokenizer.line_number @@ -61,7 +61,7 @@ def parse(tokenizer, parse_context, &block) raise_missing_tag_terminator(token, parse_context) end tag_name = Regexp.last_match(2) - markup = Regexp.last_match(4) + markup = Regexp.last_match(4) if parse_context.line_number # newlines inside the tag should increase the line number, @@ -79,8 +79,8 @@ def parse(tokenizer, parse_context, &block) # determine how to proceed return yield tag_name, markup end - new_tag = tag.parse(tag_name, markup, tokenizer, parse_context) - @blank &&= new_tag.blank? + new_tag = tag.parse(tag_name, markup, tokenizer, parse_context) + @blank &&= new_tag.blank? @nodelist << new_tag when token.start_with?(VAR_START_STRING) whitespace_handler(token, parse_context) @@ -92,7 +92,7 @@ def parse(tokenizer, parse_context, &block) end parse_context.trim_whitespace = false @nodelist << token - @blank &&= !!(token =~ WHITESPACE_OR_NOTHING) + @blank &&= !!(token =~ WHITESPACE_OR_NOTHING) end parse_context.line_number = tokenizer.line_number end @@ -121,7 +121,7 @@ def render(context) def render_to_output_buffer(context, output) context.resource_limits.render_score += @nodelist.length - idx = 0 + idx = 0 while (node = @nodelist[idx]) previous_output_size = output.bytesize diff --git a/lib/liquid/condition.rb b/lib/liquid/condition.rb index 93ec68b74..fab74d764 100644 --- a/lib/liquid/condition.rb +++ b/lib/liquid/condition.rb @@ -35,16 +35,16 @@ def self.operators attr_accessor :left, :operator, :right def initialize(left = nil, operator = nil, right = nil) - @left = left - @operator = operator - @right = right - @child_relation = nil + @left = left + @operator = operator + @right = right + @child_relation = nil @child_condition = nil end def evaluate(context = Context.new) condition = self - result = nil + result = nil loop do result = interpret_condition(condition.left, condition.right, condition.operator, context) @@ -62,12 +62,12 @@ def evaluate(context = Context.new) end def or(condition) - @child_relation = :or + @child_relation = :or @child_condition = condition end def and(condition) - @child_relation = :and + @child_relation = :and @child_condition = condition end @@ -115,7 +115,7 @@ def interpret_condition(left, right, op, context) # return this as the result. return context.evaluate(left) if op.nil? - left = context.evaluate(left) + left = context.evaluate(left) right = context.evaluate(right) operation = self.class.operators[op] || raise(Liquid::ArgumentError, "Unknown operator #{op}") diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 88e467134..397ae0f19 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -41,8 +41,8 @@ def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_erro self.exception_renderer = ->(_e) { raise } end - @interrupts = [] - @filters = [] + @interrupts = [] + @filters = [] @global_filter = nil end # rubocop:enable Metrics/ParameterLists @@ -60,7 +60,7 @@ def strainer # Note that this does not register the filters with the main Template object. see Template.register_filter # for that def add_filters(filters) - filters = [filters].flatten.compact + filters = [filters].flatten.compact @filters += filters @strainer = nil end @@ -85,9 +85,9 @@ def pop_interrupt end def handle_error(e, line_number = nil) - e = internal_error unless e.is_a?(Liquid::Error) + e = internal_error unless e.is_a?(Liquid::Error) e.template_name ||= template_name - e.line_number ||= line_number + e.line_number ||= line_number errors.push(e) exception_renderer.call(e).to_s end @@ -138,12 +138,12 @@ def new_isolated_subcontext static_environments: static_environments, registers: StaticRegisters.new(registers) ).tap do |subcontext| - subcontext.base_scope_depth = base_scope_depth + 1 + subcontext.base_scope_depth = base_scope_depth + 1 subcontext.exception_renderer = exception_renderer - subcontext.filters = @filters - subcontext.strainer = nil - subcontext.errors = errors - subcontext.warnings = warnings + subcontext.filters = @filters + subcontext.strainer = nil + subcontext.errors = errors + subcontext.warnings = warnings end end @@ -188,7 +188,7 @@ def find_variable(key, raise_on_not_found: true) try_variable_find_in_environments(key, raise_on_not_found: raise_on_not_found) end - variable = variable.to_liquid + variable = variable.to_liquid variable.context = self if variable.respond_to?(:context=) variable diff --git a/lib/liquid/errors.rb b/lib/liquid/errors.rb index eda0bd2a4..4937da380 100644 --- a/lib/liquid/errors.rb +++ b/lib/liquid/errors.rb @@ -40,19 +40,19 @@ def message_prefix end end - ArgumentError = Class.new(Error) - ContextError = Class.new(Error) - FileSystemError = Class.new(Error) - StandardError = Class.new(Error) - SyntaxError = Class.new(Error) - StackLevelError = Class.new(Error) - TaintedError = Class.new(Error) - MemoryError = Class.new(Error) - ZeroDivisionError = Class.new(Error) - FloatDomainError = Class.new(Error) - UndefinedVariable = Class.new(Error) + ArgumentError = Class.new(Error) + ContextError = Class.new(Error) + FileSystemError = Class.new(Error) + StandardError = Class.new(Error) + SyntaxError = Class.new(Error) + StackLevelError = Class.new(Error) + TaintedError = Class.new(Error) + MemoryError = Class.new(Error) + ZeroDivisionError = Class.new(Error) + FloatDomainError = Class.new(Error) + UndefinedVariable = Class.new(Error) UndefinedDropMethod = Class.new(Error) - UndefinedFilter = Class.new(Error) + UndefinedFilter = Class.new(Error) MethodOverrideError = Class.new(Error) - InternalError = Class.new(Error) + InternalError = Class.new(Error) end diff --git a/lib/liquid/expression.rb b/lib/liquid/expression.rb index 9670906b8..58633e1e5 100644 --- a/lib/liquid/expression.rb +++ b/lib/liquid/expression.rb @@ -7,7 +7,7 @@ class MethodLiteral def initialize(method_name, to_s) @method_name = method_name - @to_s = to_s + @to_s = to_s end def to_liquid diff --git a/lib/liquid/file_system.rb b/lib/liquid/file_system.rb index 27ab63257..67ba47cb1 100644 --- a/lib/liquid/file_system.rb +++ b/lib/liquid/file_system.rb @@ -47,7 +47,7 @@ class LocalFileSystem attr_accessor :root def initialize(root, pattern = "_%s.liquid") - @root = root + @root = root @pattern = pattern end diff --git a/lib/liquid/forloop_drop.rb b/lib/liquid/forloop_drop.rb index 0ffa25590..4685166f8 100644 --- a/lib/liquid/forloop_drop.rb +++ b/lib/liquid/forloop_drop.rb @@ -3,10 +3,10 @@ module Liquid class ForloopDrop < Drop def initialize(name, length, parentloop) - @name = name - @length = length + @name = name + @length = length @parentloop = parentloop - @index = 0 + @index = 0 end attr_reader :name, :length, :parentloop diff --git a/lib/liquid/legacy.rb b/lib/liquid/legacy.rb index 5cd66bc0b..70fb18670 100644 --- a/lib/liquid/legacy.rb +++ b/lib/liquid/legacy.rb @@ -1,32 +1,32 @@ # frozen_string_literal: true module Liquid - FilterSeparator = FILTER_SEPARATOR - ArgumentSeparator = ARGUMENT_SEPARATOR - FilterArgumentSeparator = FILTER_ARGUMENT_SEPARATOR + FilterSeparator = FILTER_SEPARATOR + ArgumentSeparator = ARGUMENT_SEPARATOR + FilterArgumentSeparator = FILTER_ARGUMENT_SEPARATOR VariableAttributeSeparator = VARIABLE_ATTRIBUTE_SEPARATOR - WhitespaceControl = WHITESPACE_CONTROL - TagStart = TAG_START - TagEnd = TAG_END - VariableSignature = VARIABLE_SIGNATURE - VariableSegment = VARIABLE_SEGMENT - VariableStart = VARIABLE_START - VariableEnd = VARIABLE_END - VariableIncompleteEnd = VARIABLE_INCOMPLETE_END - QuotedString = QUOTED_STRING - QuotedFragment = QUOTED_FRAGMENT - TagAttributes = TAG_ATTRIBUTES - AnyStartingTag = ANY_STARTING_TAG - PartialTemplateParser = PARTIAL_TEMPLATE_PARSER - TemplateParser = TEMPLATE_PARSER - VariableParser = VARIABLE_PARSER + WhitespaceControl = WHITESPACE_CONTROL + TagStart = TAG_START + TagEnd = TAG_END + VariableSignature = VARIABLE_SIGNATURE + VariableSegment = VARIABLE_SEGMENT + VariableStart = VARIABLE_START + VariableEnd = VARIABLE_END + VariableIncompleteEnd = VARIABLE_INCOMPLETE_END + QuotedString = QUOTED_STRING + QuotedFragment = QUOTED_FRAGMENT + TagAttributes = TAG_ATTRIBUTES + AnyStartingTag = ANY_STARTING_TAG + PartialTemplateParser = PARTIAL_TEMPLATE_PARSER + TemplateParser = TEMPLATE_PARSER + VariableParser = VARIABLE_PARSER class BlockBody - FullToken = FULL_TOKEN - ContentOfVariable = CONTENT_OF_VARIABLE + FullToken = FULL_TOKEN + ContentOfVariable = CONTENT_OF_VARIABLE WhitespaceOrNothing = WHITESPACE_OR_NOTHING - TAGSTART = TAG_START_STRING - VARSTART = VAR_START_STRING + TAGSTART = TAG_START_STRING + VARSTART = VAR_START_STRING end class Assign < Tag @@ -52,7 +52,7 @@ class For < Block end class If < Block - Syntax = SYNTAX + Syntax = SYNTAX ExpressionsAndOperators = EXPRESSIONS_AND_OPERATORS end @@ -61,7 +61,7 @@ class Include < Tag end class Raw < Block - Syntax = SYNTAX + Syntax = SYNTAX FullTokenPossiblyInvalid = FULL_TOKEN_POSSIBLY_INVALID end @@ -70,10 +70,10 @@ class TableRow < Block end class Variable - FilterMarkupRegex = FILTER_MARKUP_REGEX - FilterParser = FILTER_PARSER - FilterArgsRegex = FILTER_ARGS_REGEX - JustTagAttributes = JUST_TAG_ATTRIBUTES + FilterMarkupRegex = FILTER_MARKUP_REGEX + FilterParser = FILTER_PARSER + FilterArgsRegex = FILTER_ARGS_REGEX + JustTagAttributes = JUST_TAG_ATTRIBUTES MarkupWithQuotedFragment = MARKUP_WITH_QUOTED_FRAGMENT end end diff --git a/lib/liquid/lexer.rb b/lib/liquid/lexer.rb index a251c3e59..38cbe109c 100644 --- a/lib/liquid/lexer.rb +++ b/lib/liquid/lexer.rb @@ -15,12 +15,13 @@ class Lexer '?' => :question, '-' => :dash, }.freeze - IDENTIFIER = /[a-zA-Z_][\w-]*\??/ + + IDENTIFIER = /[a-zA-Z_][\w-]*\??/ SINGLE_STRING_LITERAL = /'[^\']*'/ DOUBLE_STRING_LITERAL = /"[^\"]*"/ - NUMBER_LITERAL = /-?\d+(\.\d+)?/ - DOTDOT = /\.\./ - COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/ + NUMBER_LITERAL = /-?\d+(\.\d+)?/ + DOTDOT = /\.\./ + COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/ WHITESPACE_OR_NOTHING = /\s*/ def initialize(input) @@ -33,7 +34,7 @@ def tokenize until @ss.eos? @ss.skip(WHITESPACE_OR_NOTHING) break if @ss.eos? - tok = if (t = @ss.scan(COMPARISON_OPERATOR)) + tok = if (t = @ss.scan(COMPARISON_OPERATOR)) [:comparison, t] elsif (t = @ss.scan(SINGLE_STRING_LITERAL)) [:string, t] @@ -46,7 +47,7 @@ def tokenize elsif (t = @ss.scan(DOTDOT)) [:dotdot, t] else - c = @ss.getch + c = @ss.getch if (s = SPECIALS[c]) [s, c] else diff --git a/lib/liquid/parse_context.rb b/lib/liquid/parse_context.rb index 4afdbe596..cdf50f68d 100644 --- a/lib/liquid/parse_context.rb +++ b/lib/liquid/parse_context.rb @@ -7,10 +7,10 @@ class ParseContext def initialize(options = {}) @template_options = options ? options.dup : {} - @locale = @template_options[:locale] ||= I18n.new - @warnings = [] - self.depth = 0 - self.partial = false + @locale = @template_options[:locale] ||= I18n.new + @warnings = [] + self.depth = 0 + self.partial = false end def [](option_key) @@ -18,8 +18,8 @@ def [](option_key) end def partial=(value) - @partial = value - @options = value ? partial_options : @template_options + @partial = value + @options = value ? partial_options : @template_options @error_mode = @options[:error_mode] || Template.error_mode end diff --git a/lib/liquid/parse_tree_visitor.rb b/lib/liquid/parse_tree_visitor.rb index d50943f30..8f5d27f38 100644 --- a/lib/liquid/parse_tree_visitor.rb +++ b/lib/liquid/parse_tree_visitor.rb @@ -11,14 +11,14 @@ def self.for(node, callbacks = Hash.new(proc {})) end def initialize(node, callbacks) - @node = node + @node = node @callbacks = callbacks end def add_callback_for(*classes, &block) - callback = block - callback = ->(node, _) { yield node } if block.arity.abs == 1 - callback = ->(_, _) { yield } if block.arity.zero? + callback = block + callback = ->(node, _) { yield node } if block.arity.abs == 1 + callback = ->(_, _) { yield } if block.arity.zero? classes.each { |klass| @callbacks[klass] = callback } self end diff --git a/lib/liquid/parser.rb b/lib/liquid/parser.rb index 6b9e83748..b33423186 100644 --- a/lib/liquid/parser.rb +++ b/lib/liquid/parser.rb @@ -3,9 +3,9 @@ module Liquid class Parser def initialize(input) - l = Lexer.new(input) + l = Lexer.new(input) @tokens = l.tokenize - @p = 0 # pointer to current location + @p = 0 # pointer to current location end def jump(point) @@ -14,6 +14,7 @@ def jump(point) def consume(type = nil) token = @tokens[@p] + if type && token[0] != type raise SyntaxError, "Expected #{type} but found #{@tokens[@p].first}" end @@ -26,6 +27,7 @@ def consume(type = nil) # or false otherwise. def consume?(type) token = @tokens[@p] + return false unless token && token[0] == type @p += 1 token[1] @@ -34,6 +36,7 @@ def consume?(type) # Like consume? Except for an :id token of a certain name def id?(str) token = @tokens[@p] + return false unless token && token[0] == :id return false unless token[1] == str @p += 1 @@ -59,7 +62,7 @@ def expression consume first = expression consume(:dotdot) - last = expression + last = expression consume(:close_round) "(#{first}..#{last})" else diff --git a/lib/liquid/parser_switching.rb b/lib/liquid/parser_switching.rb index 402b05663..e2f8546df 100644 --- a/lib/liquid/parser_switching.rb +++ b/lib/liquid/parser_switching.rb @@ -21,7 +21,7 @@ def parse_with_selected_parser(markup) def strict_parse_with_error_context(markup) strict_parse(markup) rescue SyntaxError => e - e.line_number = line_number + e.line_number = line_number e.markup_context = markup_context(markup) raise e end diff --git a/lib/liquid/partial_cache.rb b/lib/liquid/partial_cache.rb index 43c2e39b7..bc9aeb39d 100644 --- a/lib/liquid/partial_cache.rb +++ b/lib/liquid/partial_cache.rb @@ -4,14 +4,14 @@ module Liquid class PartialCache def self.load(template_name, context:, parse_context:) cached_partials = (context.registers[:cached_partials] ||= {}) - cached = cached_partials[template_name] + cached = cached_partials[template_name] return cached if cached - file_system = (context.registers[:file_system] ||= Liquid::Template.file_system) - source = file_system.read_template_file(template_name) + file_system = (context.registers[:file_system] ||= Liquid::Template.file_system) + source = file_system.read_template_file(template_name) parse_context.partial = true - partial = Liquid::Template.parse(source, parse_context) + partial = Liquid::Template.parse(source, parse_context) cached_partials[template_name] = partial ensure parse_context.partial = false diff --git a/lib/liquid/profiler.rb b/lib/liquid/profiler.rb index dc3f1db61..bec1842b1 100644 --- a/lib/liquid/profiler.rb +++ b/lib/liquid/profiler.rb @@ -101,21 +101,21 @@ def self.current_profile def initialize @partial_stack = [""] - @root_timing = Timing.new("", current_partial) + @root_timing = Timing.new("", current_partial) @timing_stack = [@root_timing] @render_start_at = Time.now - @render_end_at = @render_start_at + @render_end_at = @render_start_at end def start Thread.current[:liquid_profiler] = self - @render_start_at = Time.now + @render_start_at = Time.now end def stop Thread.current[:liquid_profiler] = nil - @render_end_at = Time.now + @render_end_at = Time.now end def total_render_time diff --git a/lib/liquid/range_lookup.rb b/lib/liquid/range_lookup.rb index 8e4d76522..57bccd00b 100644 --- a/lib/liquid/range_lookup.rb +++ b/lib/liquid/range_lookup.rb @@ -4,7 +4,7 @@ module Liquid class RangeLookup def self.parse(start_markup, end_markup) start_obj = Expression.parse(start_markup) - end_obj = Expression.parse(end_markup) + end_obj = Expression.parse(end_markup) if start_obj.respond_to?(:evaluate) || end_obj.respond_to?(:evaluate) new(start_obj, end_obj) else @@ -14,12 +14,12 @@ def self.parse(start_markup, end_markup) def initialize(start_obj, end_obj) @start_obj = start_obj - @end_obj = end_obj + @end_obj = end_obj end def evaluate(context) start_int = to_integer(context.evaluate(@start_obj)) - end_int = to_integer(context.evaluate(@end_obj)) + end_int = to_integer(context.evaluate(@end_obj)) start_int..end_int end diff --git a/lib/liquid/resource_limits.rb b/lib/liquid/resource_limits.rb index 5b7e8e463..9c898f003 100644 --- a/lib/liquid/resource_limits.rb +++ b/lib/liquid/resource_limits.rb @@ -7,8 +7,8 @@ class ResourceLimits def initialize(limits) @render_length_limit = limits[:render_length_limit] - @render_score_limit = limits[:render_score_limit] - @assign_score_limit = limits[:assign_score_limit] + @render_score_limit = limits[:render_score_limit] + @assign_score_limit = limits[:assign_score_limit] reset end diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 6855cd212..e245f97d9 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -12,13 +12,14 @@ module StandardFilters '"' => '"', "'" => ''', }.freeze + HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/ - STRIP_HTML_BLOCKS = Regexp.union( + STRIP_HTML_TAGS = /<.*?>/m + STRIP_HTML_BLOCKS = Regexp.union( %r{}m, //m, %r{}m ) - STRIP_HTML_TAGS = /<.*?>/m # Return the size of an array or of an string def size(input) @@ -76,20 +77,20 @@ def slice(input, offset, length = nil) # Truncate a string down to x characters def truncate(input, length = 50, truncate_string = "...") return if input.nil? - input_str = input.to_s - length = Utils.to_integer(length) + input_str = input.to_s + length = Utils.to_integer(length) truncate_string_str = truncate_string.to_s - l = length - truncate_string_str.length - l = 0 if l < 0 + l = length - truncate_string_str.length + l = 0 if l < 0 input_str.length > length ? input_str[0...l].concat(truncate_string_str) : input_str end def truncatewords(input, words = 15, truncate_string = "...") return if input.nil? wordlist = input.to_s.split - words = Utils.to_integer(words) - l = words - 1 - l = 0 if l < 0 + words = Utils.to_integer(words) + l = words - 1 + l = 0 if l < 0 wordlist.length > l ? wordlist[0..l].join(" ").concat(truncate_string.to_s) : input end @@ -115,7 +116,7 @@ def rstrip(input) end def strip_html(input) - empty = '' + empty = '' result = input.to_s.gsub(STRIP_HTML_BLOCKS, empty) result.gsub!(STRIP_HTML_TAGS, empty) result diff --git a/lib/liquid/static_registers.rb b/lib/liquid/static_registers.rb index 06c52ab01..da2c2c398 100644 --- a/lib/liquid/static_registers.rb +++ b/lib/liquid/static_registers.rb @@ -5,7 +5,7 @@ class StaticRegisters attr_reader :static, :registers def initialize(registers = {}) - @static = registers.is_a?(StaticRegisters) ? registers.static : registers + @static = registers.is_a?(StaticRegisters) ? registers.static : registers @registers = {} end diff --git a/lib/liquid/strainer.rb b/lib/liquid/strainer.rb index 3f3417e33..d3c7433b2 100644 --- a/lib/liquid/strainer.rb +++ b/lib/liquid/strainer.rb @@ -9,7 +9,7 @@ module Liquid # The Strainer only allows method calls defined in filters given to it via Strainer.global_filter, # Context#add_filters or Template.register_filter class Strainer #:nodoc: - @@global_strainer = Class.new(Strainer) do + @@global_strainer = Class.new(Strainer) do @filter_methods = Set.new end @@strainer_class_cache = Hash.new do |hash, filters| diff --git a/lib/liquid/tablerowloop_drop.rb b/lib/liquid/tablerowloop_drop.rb index 0d00b6f1a..628705278 100644 --- a/lib/liquid/tablerowloop_drop.rb +++ b/lib/liquid/tablerowloop_drop.rb @@ -4,10 +4,10 @@ module Liquid class TablerowloopDrop < Drop def initialize(length, cols) @length = length - @row = 1 - @col = 1 - @cols = cols - @index = 0 + @row = 1 + @col = 1 + @cols = cols + @index = 0 end attr_reader :length, :col, :row @@ -54,7 +54,7 @@ def increment! @index += 1 if @col == @cols - @col = 1 + @col = 1 @row += 1 else @col += 1 diff --git a/lib/liquid/tag.rb b/lib/liquid/tag.rb index 14606391d..562472b93 100644 --- a/lib/liquid/tag.rb +++ b/lib/liquid/tag.rb @@ -17,10 +17,10 @@ def parse(tag_name, markup, tokenizer, parse_context) end def initialize(tag_name, markup, parse_context) - @tag_name = tag_name - @markup = markup + @tag_name = tag_name + @markup = markup @parse_context = parse_context - @line_number = parse_context.line_number + @line_number = parse_context.line_number end def parse(_tokens) diff --git a/lib/liquid/tags/assign.rb b/lib/liquid/tags/assign.rb index 332c605c8..e0d512378 100644 --- a/lib/liquid/tags/assign.rb +++ b/lib/liquid/tags/assign.rb @@ -21,7 +21,7 @@ def self.syntax_error_translation_key def initialize(tag_name, markup, options) super if markup =~ SYNTAX - @to = Regexp.last_match(1) + @to = Regexp.last_match(1) @from = Variable.new(Regexp.last_match(2), options) else raise SyntaxError, options[:locale].t(self.class.syntax_error_translation_key) @@ -29,8 +29,8 @@ def initialize(tag_name, markup, options) end def render_to_output_buffer(context, output) - val = @from.render(context) - context.scopes.last[@to] = val + val = @from.render(context) + context.scopes.last[@to] = val context.resource_limits.assign_score += assign_score_of(val) output end @@ -45,7 +45,7 @@ def assign_score_of(val) if val.instance_of?(String) val.bytesize elsif val.instance_of?(Array) || val.instance_of?(Hash) - sum = 1 + sum = 1 # Uses #each to avoid extra allocations. val.each { |child| sum += assign_score_of(child) } sum diff --git a/lib/liquid/tags/capture.rb b/lib/liquid/tags/capture.rb index ee6e6d005..ddfe09433 100644 --- a/lib/liquid/tags/capture.rb +++ b/lib/liquid/tags/capture.rb @@ -25,9 +25,9 @@ def initialize(tag_name, markup, options) end def render_to_output_buffer(context, output) - previous_output_size = output.bytesize + previous_output_size = output.bytesize super - context.scopes.last[@to] = output + context.scopes.last[@to] = output context.resource_limits.assign_score += (output.bytesize - previous_output_size) output end diff --git a/lib/liquid/tags/case.rb b/lib/liquid/tags/case.rb index 1f5196aeb..c97a067ec 100644 --- a/lib/liquid/tags/case.rb +++ b/lib/liquid/tags/case.rb @@ -2,7 +2,7 @@ module Liquid class Case < Block - SYNTAX = /(#{QUOTED_FRAGMENT})/o + SYNTAX = /(#{QUOTED_FRAGMENT})/o WHEN_SYNTAX = /(#{QUOTED_FRAGMENT})(?:(?:\s+or\s+|\s*\,\s*)(#{QUOTED_FRAGMENT}.*))?/om attr_reader :blocks, :left diff --git a/lib/liquid/tags/cycle.rb b/lib/liquid/tags/cycle.rb index d6c490df8..9467f720f 100644 --- a/lib/liquid/tags/cycle.rb +++ b/lib/liquid/tags/cycle.rb @@ -24,10 +24,10 @@ def initialize(tag_name, markup, options) case markup when NAMED_SYNTAX @variables = variables_from_string(Regexp.last_match(2)) - @name = Expression.parse(Regexp.last_match(1)) + @name = Expression.parse(Regexp.last_match(1)) when SIMPLE_SYNTAX @variables = variables_from_string(markup) - @name = @variables.to_s + @name = @variables.to_s else raise SyntaxError, options[:locale].t("errors.syntax.cycle") end @@ -36,7 +36,7 @@ def initialize(tag_name, markup, options) def render_to_output_buffer(context, output) context.registers[:cycle] ||= {} - key = context.evaluate(@name) + key = context.evaluate(@name) iteration = context.registers[:cycle][key].to_i val = context.evaluate(@variables[iteration]) @@ -49,8 +49,8 @@ def render_to_output_buffer(context, output) output << val - iteration += 1 - iteration = 0 if iteration >= @variables.size + iteration += 1 + iteration = 0 if iteration >= @variables.size context.registers[:cycle][key] = iteration output diff --git a/lib/liquid/tags/decrement.rb b/lib/liquid/tags/decrement.rb index d761a0c3a..3ab7e420a 100644 --- a/lib/liquid/tags/decrement.rb +++ b/lib/liquid/tags/decrement.rb @@ -26,8 +26,8 @@ def initialize(tag_name, markup, options) end def render_to_output_buffer(context, output) - value = context.environments.first[@variable] ||= 0 - value -= 1 + value = context.environments.first[@variable] ||= 0 + value -= 1 context.environments.first[@variable] = value output << value.to_s output diff --git a/lib/liquid/tags/for.rb b/lib/liquid/tags/for.rb index b63b9e136..18c7e30ea 100644 --- a/lib/liquid/tags/for.rb +++ b/lib/liquid/tags/for.rb @@ -52,9 +52,9 @@ class For < Block def initialize(tag_name, markup, options) super - @from = @limit = nil + @from = @limit = nil parse_with_selected_parser(markup) - @for_block = BlockBody.new + @for_block = BlockBody.new @else_block = nil end @@ -88,10 +88,10 @@ def render_to_output_buffer(context, output) def lax_parse(markup) if markup =~ SYNTAX - @variable_name = Regexp.last_match(1) - collection_name = Regexp.last_match(2) - @reversed = !!Regexp.last_match(3) - @name = "#{@variable_name}-#{collection_name}" + @variable_name = Regexp.last_match(1) + collection_name = Regexp.last_match(2) + @reversed = !!Regexp.last_match(3) + @name = "#{@variable_name}-#{collection_name}" @collection_name = Expression.parse(collection_name) markup.scan(TAG_ATTRIBUTES) do |key, value| set_attribute(key, value) @@ -102,13 +102,13 @@ def lax_parse(markup) end def strict_parse(markup) - p = Parser.new(markup) - @variable_name = p.consume(:id) + p = Parser.new(markup) + @variable_name = p.consume(:id) raise SyntaxError, options[:locale].t("errors.syntax.for_invalid_in") unless p.id?('in') - collection_name = p.expression - @name = "#{@variable_name}-#{collection_name}" + collection_name = p.expression + @name = "#{@variable_name}-#{collection_name}" @collection_name = Expression.parse(collection_name) - @reversed = p.id?('reversed') + @reversed = p.id?('reversed') while p.look(:id) && p.look(:colon, 1) unless (attribute = p.id?('limit') || p.id?('offset')) @@ -140,7 +140,7 @@ def collection_segment(context) collection = collection.to_a if collection.is_a?(Range) limit_value = context.evaluate(@limit) - to = if limit_value.nil? + to = if limit_value.nil? nil else Utils.to_integer(limit_value) + from @@ -156,7 +156,7 @@ def collection_segment(context) def render_segment(context, output, segment) for_stack = context.registers[:for_stack] ||= [] - length = segment.length + length = segment.length context.stack do loop_vars = Liquid::ForloopDrop.new(@name, length, for_stack[-1]) diff --git a/lib/liquid/tags/if.rb b/lib/liquid/tags/if.rb index 50cb3341f..a54a18d4b 100644 --- a/lib/liquid/tags/if.rb +++ b/lib/liquid/tags/if.rb @@ -12,9 +12,9 @@ module Liquid # There are {% if count < 5 %} less {% else %} more {% endif %} items than you need. # class If < Block - SYNTAX = /(#{QUOTED_FRAGMENT})\s*([=!<>a-z_]+)?\s*(#{QUOTED_FRAGMENT})?/o + SYNTAX = /(#{QUOTED_FRAGMENT})\s*([=!<>a-z_]+)?\s*(#{QUOTED_FRAGMENT})?/o EXPRESSIONS_AND_OPERATORS = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QUOTED_FRAGMENT}|\S+)\s*)+)/o - BOOLEAN_OPERATORS = %w(and or).freeze + BOOLEAN_OPERATORS = %w(and or).freeze attr_reader :blocks @@ -78,32 +78,32 @@ def lax_parse(markup) new_condition = Condition.new(Expression.parse(Regexp.last_match(1)), Regexp.last_match(2), Expression.parse(Regexp.last_match(3))) raise SyntaxError, options[:locale].t("errors.syntax.if") unless BOOLEAN_OPERATORS.include?(operator) new_condition.send(operator, condition) - condition = new_condition + condition = new_condition end condition end def strict_parse(markup) - p = Parser.new(markup) + p = Parser.new(markup) condition = parse_binary_comparisons(p) p.consume(:end_of_string) condition end def parse_binary_comparisons(p) - condition = parse_comparison(p) + condition = parse_comparison(p) first_condition = condition - while (op = (p.id?('and') || p.id?('or'))) + while (op = (p.id?('and') || p.id?('or'))) child_condition = parse_comparison(p) condition.send(op, child_condition) - condition = child_condition + condition = child_condition end first_condition end def parse_comparison(p) - a = Expression.parse(p.expression) + a = Expression.parse(p.expression) if (op = p.consume?(:comparison)) b = Expression.parse(p.expression) Condition.new(a, op, b) diff --git a/lib/liquid/tags/include.rb b/lib/liquid/tags/include.rb index 379c6c1d6..e2a3ff346 100644 --- a/lib/liquid/tags/include.rb +++ b/lib/liquid/tags/include.rb @@ -30,7 +30,7 @@ def initialize(tag_name, markup, options) @variable_name_expr = variable_name ? Expression.parse(variable_name) : nil @template_name_expr = Expression.parse(template_name) - @attributes = {} + @attributes = {} markup.scan(TAG_ATTRIBUTES) do |key, value| @attributes[key] = Expression.parse(value) @@ -63,10 +63,10 @@ def render_to_output_buffer(context, output) end old_template_name = context.template_name - old_partial = context.partial + old_partial = context.partial begin context.template_name = template_name - context.partial = true + context.partial = true context.stack do @attributes.each do |key, value| context[key] = context.evaluate(value) @@ -84,7 +84,7 @@ def render_to_output_buffer(context, output) end ensure context.template_name = old_template_name - context.partial = old_partial + context.partial = old_partial end output diff --git a/lib/liquid/tags/increment.rb b/lib/liquid/tags/increment.rb index 241b316b3..0290f6959 100644 --- a/lib/liquid/tags/increment.rb +++ b/lib/liquid/tags/increment.rb @@ -23,7 +23,7 @@ def initialize(tag_name, markup, options) end def render_to_output_buffer(context, output) - value = context.environments.first[@variable] ||= 0 + value = context.environments.first[@variable] ||= 0 context.environments.first[@variable] = value + 1 output << value.to_s diff --git a/lib/liquid/tags/raw.rb b/lib/liquid/tags/raw.rb index e4b2a6a2e..5ba752c3d 100644 --- a/lib/liquid/tags/raw.rb +++ b/lib/liquid/tags/raw.rb @@ -2,7 +2,7 @@ module Liquid class Raw < Block - SYNTAX = /\A\s*\z/ + SYNTAX = /\A\s*\z/ FULL_TOKEN_POSSIBLY_INVALID = /\A(.*)#{TAG_START}\s*(\w+)\s*(.*)?#{TAG_END}\z/om def initialize(tag_name, markup, parse_context) @@ -12,7 +12,7 @@ def initialize(tag_name, markup, parse_context) end def parse(tokens) - @body = +'' + @body = +'' while (token = tokens.shift) if token =~ FULL_TOKEN_POSSIBLY_INVALID @body << Regexp.last_match(1) if Regexp.last_match(1) != "" diff --git a/lib/liquid/tags/render.rb b/lib/liquid/tags/render.rb index 0516d7da8..179084fe3 100644 --- a/lib/liquid/tags/render.rb +++ b/lib/liquid/tags/render.rb @@ -32,9 +32,9 @@ def render_to_output_buffer(context, output) parse_context: parse_context ) - inner_context = context.new_isolated_subcontext + inner_context = context.new_isolated_subcontext inner_context.template_name = template_name - inner_context.partial = true + inner_context.partial = true @attributes.each do |key, value| inner_context[key] = context.evaluate(value) end diff --git a/lib/liquid/tags/table_row.rb b/lib/liquid/tags/table_row.rb index ec5f9dbd0..f98bee513 100644 --- a/lib/liquid/tags/table_row.rb +++ b/lib/liquid/tags/table_row.rb @@ -9,9 +9,9 @@ class TableRow < Block def initialize(tag_name, markup, options) super if markup =~ SYNTAX - @variable_name = Regexp.last_match(1) + @variable_name = Regexp.last_match(1) @collection_name = Expression.parse(Regexp.last_match(2)) - @attributes = {} + @attributes = {} markup.scan(TAG_ATTRIBUTES) do |key, value| @attributes[key] = Expression.parse(value) end @@ -24,7 +24,7 @@ def render_to_output_buffer(context, output) (collection = context.evaluate(@collection_name)) || (return '') from = @attributes.key?('offset') ? context.evaluate(@attributes['offset']).to_i : 0 - to = @attributes.key?('limit') ? from + context.evaluate(@attributes['limit']).to_i : nil + to = @attributes.key?('limit') ? from + context.evaluate(@attributes['limit']).to_i : nil collection = Utils.slice_collection(collection, from, to) @@ -34,7 +34,7 @@ def render_to_output_buffer(context, output) output << "\n" context.stack do - tablerowloop = Liquid::TablerowloopDrop.new(length, cols) + tablerowloop = Liquid::TablerowloopDrop.new(length, cols) context['tablerowloop'] = tablerowloop collection.each do |item| diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index e77ba8aac..0df70d0ac 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -24,7 +24,7 @@ class TagRegistry include Enumerable def initialize - @tags = {} + @tags = {} @cache = {} end @@ -120,19 +120,19 @@ def parse(source, options = {}) end def initialize - @rethrow_errors = false + @rethrow_errors = false @resource_limits = ResourceLimits.new(self.class.default_resource_limits) end # Parse source code. # Returns self for easy chaining def parse(source, options = {}) - @options = options - @profiling = options[:profile] + @options = options + @profiling = options[:profile] @line_numbers = options[:line_numbers] || @profiling parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options) - @root = Document.parse(tokenize(source), parse_context) - @warnings = parse_context.warnings + @root = Document.parse(tokenize(source), parse_context) + @warnings = parse_context.warnings self end @@ -179,7 +179,7 @@ def render(*args) c when Liquid::Drop - drop = args.shift + drop = args.shift drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits) when Hash Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits) @@ -194,7 +194,7 @@ def render(*args) case args.last when Hash options = args.pop - output = options[:output] if options[:output] + output = options[:output] if options[:output] registers.merge!(options[:registers]) if options[:registers].is_a?(Hash) @@ -253,10 +253,10 @@ def with_profiling(context) def apply_options_to_context(context, options) context.add_filters(options[:filters]) if options[:filters] - context.global_filter = options[:global_filter] if options[:global_filter] + context.global_filter = options[:global_filter] if options[:global_filter] context.exception_renderer = options[:exception_renderer] if options[:exception_renderer] - context.strict_variables = options[:strict_variables] if options[:strict_variables] - context.strict_filters = options[:strict_filters] if options[:strict_filters] + context.strict_variables = options[:strict_variables] if options[:strict_variables] + context.strict_filters = options[:strict_filters] if options[:strict_filters] end end end diff --git a/lib/liquid/tokenizer.rb b/lib/liquid/tokenizer.rb index 5bffb9a87..93edd1856 100644 --- a/lib/liquid/tokenizer.rb +++ b/lib/liquid/tokenizer.rb @@ -5,10 +5,10 @@ class Tokenizer attr_reader :line_number, :for_liquid_tag def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false) - @source = source - @line_number = line_number || (line_numbers ? 1 : nil) + @source = source + @line_number = line_number || (line_numbers ? 1 : nil) @for_liquid_tag = for_liquid_tag - @tokens = tokenize + @tokens = tokenize end def shift diff --git a/lib/liquid/utils.rb b/lib/liquid/utils.rb index 709fb0026..15a513ff7 100644 --- a/lib/liquid/utils.rb +++ b/lib/liquid/utils.rb @@ -12,7 +12,7 @@ def self.slice_collection(collection, from, to) def self.slice_collection_using_each(collection, from, to) segments = [] - index = 0 + index = 0 # Maintains Ruby 1.8.7 String#each behaviour on 1.9 if collection.is_a?(String) diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index 2ede9e8cb..7bcd7246f 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -12,10 +12,10 @@ module Liquid # {{ user | link }} # class Variable - FILTER_MARKUP_REGEX = /#{FILTER_SEPARATOR}\s*(.*)/om - FILTER_PARSER = /(?:\s+|#{QUOTED_FRAGMENT}|#{ARGUMENT_SEPARATOR})+/o - FILTER_ARGS_REGEX = /(?:#{FILTER_ARGUMENT_SEPARATOR}|#{ARGUMENT_SEPARATOR})\s*((?:\w+\s*\:\s*)?#{QUOTED_FRAGMENT})/o - JUST_TAG_ATTRIBUTES = /\A#{TAG_ATTRIBUTES}\z/o + FILTER_MARKUP_REGEX = /#{FILTER_SEPARATOR}\s*(.*)/om + FILTER_PARSER = /(?:\s+|#{QUOTED_FRAGMENT}|#{ARGUMENT_SEPARATOR})+/o + FILTER_ARGS_REGEX = /(?:#{FILTER_ARGUMENT_SEPARATOR}|#{ARGUMENT_SEPARATOR})\s*((?:\w+\s*\:\s*)?#{QUOTED_FRAGMENT})/o + JUST_TAG_ATTRIBUTES = /\A#{TAG_ATTRIBUTES}\z/o MARKUP_WITH_QUOTED_FRAGMENT = /(#{QUOTED_FRAGMENT})(.*)/om attr_accessor :filters, :name, :line_number @@ -25,10 +25,10 @@ class Variable include ParserSwitching def initialize(markup, parse_context) - @markup = markup - @name = nil + @markup = markup + @name = nil @parse_context = parse_context - @line_number = parse_context.line_number + @line_number = parse_context.line_number parse_with_selected_parser(markup) end @@ -45,9 +45,9 @@ def lax_parse(markup) @filters = [] return unless markup =~ MARKUP_WITH_QUOTED_FRAGMENT - name_markup = Regexp.last_match(1) + name_markup = Regexp.last_match(1) filter_markup = Regexp.last_match(2) - @name = Expression.parse(name_markup) + @name = Expression.parse(name_markup) if filter_markup =~ FILTER_MARKUP_REGEX filters = Regexp.last_match(1).scan(FILTER_PARSER) filters.each do |f| @@ -61,7 +61,7 @@ def lax_parse(markup) def strict_parse(markup) @filters = [] - p = Parser.new(markup) + p = Parser.new(markup) @name = Expression.parse(p.expression) while p.consume?(:pipe) @@ -107,17 +107,17 @@ def render_to_output_buffer(context, output) private def parse_filter_expressions(filter_name, unparsed_args) - filter_args = [] + filter_args = [] keyword_args = nil unparsed_args.each do |a| if (matches = a.match(JUST_TAG_ATTRIBUTES)) - keyword_args ||= {} + keyword_args ||= {} keyword_args[matches[1]] = Expression.parse(matches[2]) else filter_args << Expression.parse(a) end end - result = [filter_name, filter_args] + result = [filter_name, filter_args] result << keyword_args if keyword_args result end @@ -141,8 +141,8 @@ def taint_check(context, obj) @markup =~ QUOTED_FRAGMENT name = Regexp.last_match(0) - error = TaintedError.new("variable '#{name}' is tainted and was not escaped") - error.line_number = line_number + error = TaintedError.new("variable '#{name}' is tainted and was not escaped") + error.line_number = line_number error.template_name = context.template_name case Template.taint_mode diff --git a/lib/liquid/variable_lookup.rb b/lib/liquid/variable_lookup.rb index c96a5233b..fb2acc679 100644 --- a/lib/liquid/variable_lookup.rb +++ b/lib/liquid/variable_lookup.rb @@ -3,7 +3,7 @@ module Liquid class VariableLookup SQUARE_BRACKETED = /\A\[(.*)\]\z/m - COMMAND_METHODS = ['size', 'first', 'last'].freeze + COMMAND_METHODS = ['size', 'first', 'last'].freeze attr_reader :name, :lookups @@ -14,13 +14,13 @@ def self.parse(markup) def initialize(markup) lookups = markup.scan(VARIABLE_PARSER) - name = lookups.shift + name = lookups.shift if name =~ SQUARE_BRACKETED name = Expression.parse(Regexp.last_match(1)) end @name = name - @lookups = lookups + @lookups = lookups @command_flags = 0 @lookups.each_index do |i| @@ -34,7 +34,7 @@ def initialize(markup) end def evaluate(context) - name = context.evaluate(@name) + name = context.evaluate(@name) object = context.find_variable(name) @lookups.each_index do |i| @@ -47,7 +47,7 @@ def evaluate(context) (object.respond_to?(:fetch) && key.is_a?(Integer))) # if its a proc we will replace the entry with the proc - res = context.lookup_and_evaluate(object, key) + res = context.lookup_and_evaluate(object, key) object = res.to_liquid # Some special cases. If the part wasn't in square brackets and diff --git a/performance/benchmark.rb b/performance/benchmark.rb index 4d28b9acf..993cc933e 100644 --- a/performance/benchmark.rb +++ b/performance/benchmark.rb @@ -4,10 +4,10 @@ require_relative 'theme_runner' Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first -profiler = ThemeRunner.new +profiler = ThemeRunner.new Benchmark.ips do |x| - x.time = 10 + x.time = 10 x.warmup = 5 puts diff --git a/performance/profile.rb b/performance/profile.rb index 70740778d..de4ee2aac 100644 --- a/performance/profile.rb +++ b/performance/profile.rb @@ -4,7 +4,7 @@ require_relative 'theme_runner' Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first -profiler = ThemeRunner.new +profiler = ThemeRunner.new profiler.run [:cpu, :object].each do |profile_type| diff --git a/performance/shopify/comment_form.rb b/performance/shopify/comment_form.rb index 0dabc4bde..cb09d0e7e 100644 --- a/performance/shopify/comment_form.rb +++ b/performance/shopify/comment_form.rb @@ -8,7 +8,7 @@ def initialize(tag_name, markup, options) if markup =~ SYNTAX @variable_name = Regexp.last_match(1) - @attributes = {} + @attributes = {} else raise SyntaxError, "Syntax Error in 'comment_form' - Valid syntax: comment_form [article]" end diff --git a/performance/shopify/database.rb b/performance/shopify/database.rb index 2db6d300c..35a403807 100644 --- a/performance/shopify/database.rb +++ b/performance/shopify/database.rb @@ -11,7 +11,7 @@ def self.tables # From vision source db['products'].each do |product| - collections = db['collections'].find_all do |collection| + collections = db['collections'].find_all do |collection| collection['products'].any? { |p| p['id'].to_i == product['id'].to_i } end product['collections'] = collections diff --git a/performance/shopify/paginate.rb b/performance/shopify/paginate.rb index 07f3cfced..acd7036af 100644 --- a/performance/shopify/paginate.rb +++ b/performance/shopify/paginate.rb @@ -8,7 +8,7 @@ def initialize(tag_name, markup, options) if markup =~ SYNTAX @collection_name = Regexp.last_match(1) - @page_size = if Regexp.last_match(2) + @page_size = if Regexp.last_match(2) Regexp.last_match(3).to_i else 20 diff --git a/performance/theme_runner.rb b/performance/theme_runner.rb index 5ad01c554..d8d093661 100644 --- a/performance/theme_runner.rb +++ b/performance/theme_runner.rb @@ -58,9 +58,9 @@ def run # `render` is called to benchmark just the render portion of liquid def render @compiled_tests.each do |test| - tmpl = test[:tmpl] + tmpl = test[:tmpl] assigns = test[:assigns] - layout = test[:layout] + layout = test[:layout] if layout assigns['content_for_layout'] = tmpl.render!(assigns) @@ -74,7 +74,7 @@ def render private def compile_and_render(template, layout, assigns, page_template, template_file) - compiled_test = compile_test(template, layout, assigns, page_template, template_file) + compiled_test = compile_test(template, layout, assigns, page_template, template_file) assigns['content_for_layout'] = compiled_test[:tmpl].render!(assigns) compiled_test[:layout].render!(assigns) if layout end @@ -88,7 +88,7 @@ def compile_all_tests end def compile_test(template, layout, assigns, page_template, template_file) - tmpl = init_template(page_template, template_file) + tmpl = init_template(page_template, template_file) parsed_template = tmpl.parse(template).dup if layout @@ -113,9 +113,9 @@ def each_test # set up a new Liquid::Template object for use in `compile_and_render` and `compile_test` def init_template(page_template, template_file) - tmpl = Liquid::Template.new - tmpl.assigns['page_title'] = 'Page title' - tmpl.assigns['template'] = page_template + tmpl = Liquid::Template.new + tmpl.assigns['page_title'] = 'Page title' + tmpl.assigns['template'] = page_template tmpl.registers[:file_system] = ThemeRunner::FileSystem.new(File.dirname(template_file)) tmpl end diff --git a/test/integration/assign_test.rb b/test/integration/assign_test.rb index ffcb8a3f0..ce86c7a9e 100644 --- a/test/integration/assign_test.rb +++ b/test/integration/assign_test.rb @@ -10,8 +10,8 @@ def test_assign_with_hyphen_in_variable_name {% assign this-thing = 'Print this-thing' %} {{ this-thing }} END_TEMPLATE - template = Template.parse(template_source) - rendered = template.render! + template = Template.parse(template_source) + rendered = template.render! assert_equal "Print this-thing", rendered.strip end diff --git a/test/integration/capture_test.rb b/test/integration/capture_test.rb index f28e1b1b3..6743cd838 100644 --- a/test/integration/capture_test.rb +++ b/test/integration/capture_test.rb @@ -14,8 +14,8 @@ def test_capture_with_hyphen_in_variable_name {% capture this-thing %}Print this-thing{% endcapture %} {{ this-thing }} END_TEMPLATE - template = Template.parse(template_source) - rendered = template.render! + template = Template.parse(template_source) + rendered = template.render! assert_equal "Print this-thing", rendered.strip end @@ -30,8 +30,8 @@ def test_capture_to_variable_from_outer_scope_if_existing {% endif %} {{var}} END_TEMPLATE - template = Template.parse(template_source) - rendered = template.render! + template = Template.parse(template_source) + rendered = template.render! assert_equal "test-string", rendered.gsub(/\s/, '') end @@ -45,8 +45,8 @@ def test_assigning_from_capture {% endfor %} {{ first }}-{{ second }} END_TEMPLATE - template = Template.parse(template_source) - rendered = template.render! + template = Template.parse(template_source) + rendered = template.render! assert_equal "3-3", rendered.gsub(/\s/, '') end end # CaptureTest diff --git a/test/integration/drop_test.rb b/test/integration/drop_test.rb index 3fe61750d..34702d415 100644 --- a/test/integration/drop_test.rb +++ b/test/integration/drop_test.rb @@ -125,7 +125,7 @@ def test_rendering_raises_on_tainted_attr def test_rendering_warns_on_tainted_attr with_taint_mode(:warn) do - tpl = Liquid::Template.parse('{{ product.user_input }}') + tpl = Liquid::Template.parse('{{ product.user_input }}') context = Context.new('product' => ProductDrop.new) tpl.render!(context) assert_equal [Liquid::TaintedError], context.warnings.map(&:class) diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index 7abaec040..9f7d92023 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -209,13 +209,13 @@ def test_default_exception_renderer_with_internal_error end def test_setting_default_exception_renderer - old_exception_renderer = Liquid::Template.default_exception_renderer - exceptions = [] + old_exception_renderer = Liquid::Template.default_exception_renderer + exceptions = [] Liquid::Template.default_exception_renderer = ->(e) { exceptions << e '' } - template = Liquid::Template.parse('This is a runtime error: {{ errors.argument_error }}') + template = Liquid::Template.parse('This is a runtime error: {{ errors.argument_error }}') output = template.render('errors' => ErrorDrop.new) @@ -226,9 +226,9 @@ def test_setting_default_exception_renderer end def test_exception_renderer_exposing_non_liquid_error - template = Liquid::Template.parse('This is a runtime error: {{ errors.runtime_error }}', line_numbers: true) + template = Liquid::Template.parse('This is a runtime error: {{ errors.runtime_error }}', line_numbers: true) exceptions = [] - handler = ->(e) { + handler = ->(e) { exceptions << e e.cause } @@ -252,8 +252,8 @@ def test_included_template_name_with_line_numbers begin Liquid::Template.file_system = TestFileSystem.new - template = Liquid::Template.parse("Argument error:\n{% include 'product' %}", line_numbers: true) - page = template.render('errors' => ErrorDrop.new) + template = Liquid::Template.parse("Argument error:\n{% include 'product' %}", line_numbers: true) + page = template.render('errors' => ErrorDrop.new) ensure Liquid::Template.file_system = old_file_system end diff --git a/test/integration/filter_test.rb b/test/integration/filter_test.rb index 270477e68..976c34bbe 100644 --- a/test/integration/filter_test.rb +++ b/test/integration/filter_test.rb @@ -72,10 +72,10 @@ def test_join end def test_sort - @context['value'] = 3 - @context['numbers'] = [2, 1, 4, 3] - @context['words'] = ['expected', 'as', 'alphabetic'] - @context['arrays'] = ['flower', 'are'] + @context['value'] = 3 + @context['numbers'] = [2, 1, 4, 3] + @context['words'] = ['expected', 'as', 'alphabetic'] + @context['arrays'] = ['flower', 'are'] @context['case_sensitive'] = ['sensitive', 'Expected', 'case'] assert_equal '1 2 3 4', Template.parse("{{numbers | sort | join}}").render(@context) @@ -86,8 +86,8 @@ def test_sort end def test_sort_natural - @context['words'] = ['case', 'Assert', 'Insensitive'] - @context['hashes'] = [{ 'a' => 'A' }, { 'a' => 'b' }, { 'a' => 'C' }] + @context['words'] = ['case', 'Assert', 'Insensitive'] + @context['hashes'] = [{ 'a' => 'A' }, { 'a' => 'b' }, { 'a' => 'C' }] @context['objects'] = [TestObject.new('A'), TestObject.new('b'), TestObject.new('C')] # Test strings @@ -101,8 +101,8 @@ def test_sort_natural end def test_compact - @context['words'] = ['a', nil, 'b', nil, 'c'] - @context['hashes'] = [{ 'a' => 'A' }, { 'a' => nil }, { 'a' => 'C' }] + @context['words'] = ['a', nil, 'b', nil, 'c'] + @context['hashes'] = [{ 'a' => 'A' }, { 'a' => nil }, { 'a' => 'C' }] @context['objects'] = [TestObject.new('A'), TestObject.new(nil), TestObject.new('C')] # Test strings @@ -141,9 +141,9 @@ def test_nonexistent_filter_is_ignored def test_filter_with_keyword_arguments @context['surname'] = 'john' - @context['input'] = 'hello %{first_name}, %{last_name}' + @context['input'] = 'hello %{first_name}, %{last_name}' @context.add_filters(SubstituteFilter) - output = Template.parse(%({{ input | substitute: first_name: surname, last_name: 'doe' }})).render(@context) + output = Template.parse(%({{ input | substitute: first_name: surname, last_name: 'doe' }})).render(@context) assert_equal 'hello john, doe', output end diff --git a/test/integration/output_test.rb b/test/integration/output_test.rb index 687cad873..05f9bb1d6 100644 --- a/test/integration/output_test.rb +++ b/test/integration/output_test.rb @@ -61,63 +61,63 @@ def test_variable_traversing end def test_variable_piping - text = %( {{ car.gm | make_funny }} ) + text = %( {{ car.gm | make_funny }} ) expected = %( LOL ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_variable_piping_with_input - text = %( {{ car.gm | cite_funny }} ) + text = %( {{ car.gm | cite_funny }} ) expected = %( LOL: bad ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_variable_piping_with_args - text = %! {{ car.gm | add_smiley : ':-(' }} ! + text = %! {{ car.gm | add_smiley : ':-(' }} ! expected = %| bad :-( | assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_variable_piping_with_no_args - text = %( {{ car.gm | add_smiley }} ) + text = %( {{ car.gm | add_smiley }} ) expected = %| bad :-) | assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_multiple_variable_piping_with_args - text = %! {{ car.gm | add_smiley : ':-(' | add_smiley : ':-('}} ! + text = %! {{ car.gm | add_smiley : ':-(' | add_smiley : ':-('}} ! expected = %| bad :-( :-( | assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_variable_piping_with_multiple_args - text = %( {{ car.gm | add_tag : 'span', 'bar'}} ) + text = %( {{ car.gm | add_tag : 'span', 'bar'}} ) expected = %( bad ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_variable_piping_with_variable_args - text = %( {{ car.gm | add_tag : 'span', car.bmw}} ) + text = %( {{ car.gm | add_tag : 'span', car.bmw}} ) expected = %( bad ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_multiple_pipings - text = %( {{ best_cars | cite_funny | paragraph }} ) + text = %( {{ best_cars | cite_funny | paragraph }} ) expected = %(

LOL: bmw

) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_link_to - text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} ) + text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} ) expected = %( Typo ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) diff --git a/test/integration/parsing_quirks_test.rb b/test/integration/parsing_quirks_test.rb index c210b486b..58ca3f347 100644 --- a/test/integration/parsing_quirks_test.rb +++ b/test/integration/parsing_quirks_test.rb @@ -72,7 +72,7 @@ def test_no_error_on_lax_empty_filter def test_meaningless_parens_lax with_error_mode(:lax) do assigns = { 'b' => 'bar', 'c' => 'baz' } - markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" + markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" assert_template_result(' YES ', "{% if #{markup} %} YES {% endif %}", assigns) end end diff --git a/test/integration/security_test.rb b/test/integration/security_test.rb index 28e9d3928..dec33df36 100644 --- a/test/integration/security_test.rb +++ b/test/integration/security_test.rb @@ -16,28 +16,28 @@ def setup end def test_no_instance_eval - text = %( {{ '1+1' | instance_eval }} ) + text = %( {{ '1+1' | instance_eval }} ) expected = %( 1+1 ) assert_equal expected, Template.parse(text).render!(@assigns) end def test_no_existing_instance_eval - text = %( {{ '1+1' | __instance_eval__ }} ) + text = %( {{ '1+1' | __instance_eval__ }} ) expected = %( 1+1 ) assert_equal expected, Template.parse(text).render!(@assigns) end def test_no_instance_eval_after_mixing_in_new_filter - text = %( {{ '1+1' | instance_eval }} ) + text = %( {{ '1+1' | instance_eval }} ) expected = %( 1+1 ) assert_equal expected, Template.parse(text).render!(@assigns) end def test_no_instance_eval_later_in_chain - text = %( {{ '1+1' | add_one | instance_eval }} ) + text = %( {{ '1+1' | add_one | instance_eval }} ) expected = %( 1+1 + 1 ) assert_equal expected, Template.parse(text).render!(@assigns, filters: SecurityFilter) @@ -68,13 +68,13 @@ def test_does_not_add_drop_methods_to_symbol_table def test_max_depth_nested_blocks_does_not_raise_exception depth = Liquid::Block::MAX_DEPTH - code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth + code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth assert_equal "rendered", Template.parse(code).render! end def test_more_than_max_depth_nested_blocks_raises_exception depth = Liquid::Block::MAX_DEPTH + 1 - code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth + code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth assert_raises(Liquid::StackLevelError) do Template.parse(code).render! end diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index bf285399e..7a4bf835a 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -204,7 +204,7 @@ def test_sort_with_nils end def test_sort_when_property_is_sometimes_missing_puts_nils_last - input = [ + input = [ { "price" => 4, "handle" => "alpha" }, { "handle" => "beta" }, { "price" => 1, "handle" => "gamma" }, @@ -232,7 +232,7 @@ def test_sort_natural_with_nils end def test_sort_natural_when_property_is_sometimes_missing_puts_nils_last - input = [ + input = [ { "price" => "4", "handle" => "alpha" }, { "handle" => "beta" }, { "price" => "1", "handle" => "gamma" }, @@ -250,7 +250,7 @@ def test_sort_natural_when_property_is_sometimes_missing_puts_nils_last end def test_sort_natural_case_check - input = [ + input = [ { "key" => "X" }, { "key" => "Y" }, { "key" => "Z" }, @@ -386,7 +386,7 @@ def test_map_on_hashes def test_legacy_map_on_hashes_with_dynamic_key template = "{% assign key = 'foo' %}{{ thing | map: key | map: 'bar' }}" - hash = { "foo" => { "bar" => 42 } } + hash = { "foo" => { "bar" => 42 } } assert_template_result "42", template, "thing" => hash end @@ -397,8 +397,8 @@ def test_sort_calls_to_liquid end def test_map_over_proc - drop = TestDrop.new - p = proc { drop } + drop = TestDrop.new + p = proc { drop } templ = '{{ procs | map: "test" }}' assert_template_result "testfoo", templ, "procs" => [p] end @@ -768,7 +768,7 @@ def test_where_no_target_value private def with_timezone(tz) - old_tz = ENV['TZ'] + old_tz = ENV['TZ'] ENV['TZ'] = tz yield ensure diff --git a/test/integration/tags/break_tag_test.rb b/test/integration/tags/break_tag_test.rb index c3a467918..a67a8b535 100644 --- a/test/integration/tags/break_tag_test.rb +++ b/test/integration/tags/break_tag_test.rb @@ -8,8 +8,8 @@ class BreakTagTest < Minitest::Test # tests that no weird errors are raised if break is called outside of a # block def test_break_with_no_block - assigns = { 'i' => 1 } - markup = '{% break %}' + assigns = { 'i' => 1 } + markup = '{% break %}' expected = '' assert_template_result(expected, markup, assigns) diff --git a/test/integration/tags/continue_tag_test.rb b/test/integration/tags/continue_tag_test.rb index 00cca17c1..0530a718f 100644 --- a/test/integration/tags/continue_tag_test.rb +++ b/test/integration/tags/continue_tag_test.rb @@ -8,8 +8,8 @@ class ContinueTagTest < Minitest::Test # tests that no weird errors are raised if continue is called outside of a # block def test_continue_with_no_block - assigns = {} - markup = '{% continue %}' + assigns = {} + markup = '{% continue %}' expected = '' assert_template_result(expected, markup, assigns) diff --git a/test/integration/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb index 667efac0c..0377fcf2c 100644 --- a/test/integration/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -106,7 +106,7 @@ def test_limiting end def test_limiting_with_invalid_limit - assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } + assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } template = <<-MKUP {% for i in array limit: true offset: 1 %} {{ i }} @@ -120,7 +120,7 @@ def test_limiting_with_invalid_limit end def test_limiting_with_invalid_offset - assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } + assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } template = <<-MKUP {% for i in array limit: 1 offset: true %} {{ i }} @@ -134,8 +134,8 @@ def test_limiting_with_invalid_offset end def test_dynamic_variable_limiting - assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } - assigns['limit'] = 2 + assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } + assigns['limit'] = 2 assigns['offset'] = 2 assert_template_result('34', '{%for i in array limit: limit offset: offset %}{{ i }}{%endfor%}', assigns) @@ -152,8 +152,8 @@ def test_offset_only end def test_pause_resume - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = <<-MKUP + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = <<-MKUP {%for i in array.items limit: 3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit: 3 %}{{i}}{%endfor%} @@ -171,8 +171,8 @@ def test_pause_resume end def test_pause_resume_limit - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = <<-MKUP + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = <<-MKUP {%for i in array.items limit:3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%} @@ -190,8 +190,8 @@ def test_pause_resume_limit end def test_pause_resume_big_limit - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = <<-MKUP + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = <<-MKUP {%for i in array.items limit:3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%} @@ -209,8 +209,8 @@ def test_pause_resume_big_limit end def test_pause_resume_big_offset - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = '{%for i in array.items limit:3 %}{{i}}{%endfor%} + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = '{%for i in array.items limit:3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%} next @@ -226,26 +226,26 @@ def test_pause_resume_big_offset def test_for_with_break assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } } - markup = '{% for i in array.items %}{% break %}{% endfor %}' + markup = '{% for i in array.items %}{% break %}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{{ i }}{% break %}{% endfor %}' + markup = '{% for i in array.items %}{{ i }}{% break %}{% endfor %}' expected = "1" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% break %}{{ i }}{% endfor %}' + markup = '{% for i in array.items %}{% break %}{{ i }}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{{ i }}{% if i > 3 %}{% break %}{% endif %}{% endfor %}' + markup = '{% for i in array.items %}{{ i }}{% if i > 3 %}{% break %}{% endif %}{% endfor %}' expected = "1234" assert_template_result(expected, markup, assigns) # tests to ensure it only breaks out of the local for loop # and not all of them. - assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } - markup = '{% for item in array %}' \ + assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } + markup = '{% for item in array %}' \ '{% for i in item %}' \ '{% if i == 1 %}' \ '{% break %}' \ @@ -257,8 +257,8 @@ def test_for_with_break assert_template_result(expected, markup, assigns) # test break does nothing when unreached - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } - markup = '{% for i in array.items %}{% if i == 9999 %}{% break %}{% endif %}{{ i }}{% endfor %}' + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } + markup = '{% for i in array.items %}{% if i == 9999 %}{% break %}{% endif %}{{ i }}{% endfor %}' expected = '12345' assert_template_result(expected, markup, assigns) end @@ -266,29 +266,29 @@ def test_for_with_break def test_for_with_continue assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } - markup = '{% for i in array.items %}{% continue %}{% endfor %}' + markup = '{% for i in array.items %}{% continue %}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{{ i }}{% continue %}{% endfor %}' + markup = '{% for i in array.items %}{{ i }}{% continue %}{% endfor %}' expected = "12345" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% continue %}{{ i }}{% endfor %}' + markup = '{% for i in array.items %}{% continue %}{{ i }}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% if i > 3 %}{% continue %}{% endif %}{{ i }}{% endfor %}' + markup = '{% for i in array.items %}{% if i > 3 %}{% continue %}{% endif %}{{ i }}{% endfor %}' expected = "123" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% if i == 3 %}{% continue %}{% else %}{{ i }}{% endif %}{% endfor %}' + markup = '{% for i in array.items %}{% if i == 3 %}{% continue %}{% else %}{{ i }}{% endif %}{% endfor %}' expected = "1245" assert_template_result(expected, markup, assigns) # tests to ensure it only continues the local for loop and not all of them. - assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } - markup = '{% for item in array %}' \ + assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } + markup = '{% for item in array %}' \ '{% for i in item %}' \ '{% if i == 1 %}' \ '{% continue %}' \ @@ -300,8 +300,8 @@ def test_for_with_continue assert_template_result(expected, markup, assigns) # test continue does nothing when unreached - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } - markup = '{% for i in array.items %}{% if i == 9999 %}{% continue %}{% endif %}{{ i }}{% endfor %}' + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } + markup = '{% for i in array.items %}{% if i == 9999 %}{% continue %}{% endif %}{{ i }}{% endfor %}' expected = '12345' assert_template_result(expected, markup, assigns) end @@ -389,8 +389,8 @@ def load_slice(from, to) end def test_iterate_with_each_when_no_limit_applied - loader = LoaderDrop.new([1, 2, 3, 4, 5]) - assigns = { 'items' => loader } + loader = LoaderDrop.new([1, 2, 3, 4, 5]) + assigns = { 'items' => loader } expected = '12345' template = '{% for item in items %}{{item}}{% endfor %}' assert_template_result(expected, template, assigns) @@ -399,8 +399,8 @@ def test_iterate_with_each_when_no_limit_applied end def test_iterate_with_load_slice_when_limit_applied - loader = LoaderDrop.new([1, 2, 3, 4, 5]) - assigns = { 'items' => loader } + loader = LoaderDrop.new([1, 2, 3, 4, 5]) + assigns = { 'items' => loader } expected = '1' template = '{% for item in items limit:1 %}{{item}}{% endfor %}' assert_template_result(expected, template, assigns) @@ -409,8 +409,8 @@ def test_iterate_with_load_slice_when_limit_applied end def test_iterate_with_load_slice_when_limit_and_offset_applied - loader = LoaderDrop.new([1, 2, 3, 4, 5]) - assigns = { 'items' => loader } + loader = LoaderDrop.new([1, 2, 3, 4, 5]) + assigns = { 'items' => loader } expected = '34' template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}' assert_template_result(expected, template, assigns) @@ -419,11 +419,11 @@ def test_iterate_with_load_slice_when_limit_and_offset_applied end def test_iterate_with_load_slice_returns_same_results_as_without - loader = LoaderDrop.new([1, 2, 3, 4, 5]) + loader = LoaderDrop.new([1, 2, 3, 4, 5]) loader_assigns = { 'items' => loader } - array_assigns = { 'items' => [1, 2, 3, 4, 5] } - expected = '34' - template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}' + array_assigns = { 'items' => [1, 2, 3, 4, 5] } + expected = '34' + template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}' assert_template_result(expected, template, loader_assigns) assert_template_result(expected, template, array_assigns) end diff --git a/test/integration/tags/if_else_tag_test.rb b/test/integration/tags/if_else_tag_test.rb index d54b2fb8d..dfbc537d6 100644 --- a/test/integration/tags/if_else_tag_test.rb +++ b/test/integration/tags/if_else_tag_test.rb @@ -45,7 +45,7 @@ def test_if_or_with_operators def test_comparison_of_strings_containing_and_or_or awful_markup = "a == 'and' and b == 'or' and c == 'foo and bar' and d == 'bar or baz' and e == 'foo' and foo and bar" - assigns = { 'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true } + assigns = { 'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true } assert_template_result(' YES ', "{% if #{awful_markup} %} YES {% endif %}", assigns) end @@ -142,7 +142,7 @@ def test_syntax_error_no_expression end def test_if_with_custom_condition - original_op = Condition.operators['contains'] + original_op = Condition.operators['contains'] Condition.operators['contains'] = :[] assert_template_result('yes', %({% if 'bob' contains 'o' %}yes{% endif %})) @@ -152,7 +152,7 @@ def test_if_with_custom_condition end def test_operators_are_ignored_unless_isolated - original_op = Condition.operators['contains'] + original_op = Condition.operators['contains'] Condition.operators['contains'] = :[] assert_template_result('yes', diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index 686d482e3..ef9608188 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -51,7 +51,7 @@ class CountingFileSystem attr_reader :count def read_template_file(_template_path) @count ||= 0 - @count += 1 + @count += 1 'from CountingFileSystem' end end @@ -179,7 +179,7 @@ def test_include_tag_within_if_statement end def test_custom_include_tag - original_tag = Liquid::Template.tags['include'] + original_tag = Liquid::Template.tags['include'] Liquid::Template.tags['include'] = CustomInclude begin assert_equal "custom_foo", @@ -190,7 +190,7 @@ def test_custom_include_tag end def test_custom_include_tag_within_if_statement - original_tag = Liquid::Template.tags['include'] + original_tag = Liquid::Template.tags['include'] Liquid::Template.tags['include'] = CustomInclude begin assert_equal "custom_foo_if_true", diff --git a/test/integration/tags/render_tag_test.rb b/test/integration/tags/render_tag_test.rb index 154783ad3..656ec8e55 100644 --- a/test/integration/tags/render_tag_test.rb +++ b/test/integration/tags/render_tag_test.rb @@ -47,7 +47,7 @@ def test_render_sets_the_correct_template_name_for_errors with_taint_mode :error do template = Liquid::Template.parse('{% render "snippet", unsafe: unsafe %}') - context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) + context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) template.render(context) assert_equal [Liquid::TaintedError], template.errors.map(&:class) @@ -60,7 +60,7 @@ def test_render_sets_the_correct_template_name_for_warnings with_taint_mode :warn do template = Liquid::Template.parse('{% render "snippet", unsafe: unsafe %}') - context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) + context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) template.render(context) assert_equal [Liquid::TaintedError], context.warnings.map(&:class) diff --git a/test/integration/tags/standard_tag_test.rb b/test/integration/tags/standard_tag_test.rb index 7939cd36a..72b5a3730 100644 --- a/test/integration/tags/standard_tag_test.rb +++ b/test/integration/tags/standard_tag_test.rb @@ -174,7 +174,7 @@ def test_case_on_length_with_else def test_assign_from_case # Example from the shopify forums - code = "{% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }}" + code = "{% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }}" template = Liquid::Template.parse(code) assert_equal "menswear", template.render!("collection" => { 'handle' => 'menswear-jackets' }) assert_equal "menswear", template.render!("collection" => { 'handle' => 'menswear-t-shirts' }) diff --git a/test/integration/template_test.rb b/test/integration/template_test.rb index 48549f55a..9f21d39d6 100644 --- a/test/integration/template_test.rb +++ b/test/integration/template_test.rb @@ -73,29 +73,29 @@ def test_custom_assigns_squash_instance_assigns end def test_persistent_assigns_squash_instance_assigns - t = Template.new + t = Template.new assert_equal 'from instance assigns', t.parse("{% assign foo = 'from instance assigns' %}{{ foo }}").render! t.assigns['foo'] = 'from persistent assigns' assert_equal 'from persistent assigns', t.parse("{{ foo }}").render! end def test_lambda_is_called_once_from_persistent_assigns_over_multiple_parses_and_renders - t = Template.new + t = Template.new t.assigns['number'] = -> { @global ||= 0 - @global += 1 + @global += 1 } assert_equal '1', t.parse("{{number}}").render! assert_equal '1', t.parse("{{number}}").render! assert_equal '1', t.render! - @global = nil + @global = nil end def test_lambda_is_called_once_from_custom_assigns_over_multiple_parses_and_renders - t = Template.new + t = Template.new assigns = { 'number' => -> { @global ||= 0 - @global += 1 + @global += 1 } } assert_equal '1', t.parse("{{number}}").render!(assigns) assert_equal '1', t.parse("{{number}}").render!(assigns) @@ -104,13 +104,13 @@ def test_lambda_is_called_once_from_custom_assigns_over_multiple_parses_and_rend end def test_resource_limits_works_with_custom_length_method - t = Template.parse("{% assign foo = bar %}") + t = Template.parse("{% assign foo = bar %}") t.resource_limits.render_length_limit = 42 assert_equal "", t.render!("bar" => SomethingWithLength.new) end def test_resource_limits_render_length - t = Template.parse("0123456789") + t = Template.parse("0123456789") t.resource_limits.render_length_limit = 5 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -121,12 +121,12 @@ def test_resource_limits_render_length end def test_resource_limits_render_score - t = Template.parse("{% for a in (1..10) %} {% for a in (1..10) %} foo {% endfor %} {% endfor %}") + t = Template.parse("{% for a in (1..10) %} {% for a in (1..10) %} foo {% endfor %} {% endfor %}") t.resource_limits.render_score_limit = 50 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? - t = Template.parse("{% for a in (1..100) %} foo {% endfor %}") + t = Template.parse("{% for a in (1..100) %} foo {% endfor %}") t.resource_limits.render_score_limit = 50 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -137,7 +137,7 @@ def test_resource_limits_render_score end def test_resource_limits_assign_score - t = Template.parse("{% assign foo = 42 %}{% assign bar = 23 %}") + t = Template.parse("{% assign foo = 42 %}{% assign bar = 23 %}") t.resource_limits.assign_score_limit = 1 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -169,7 +169,7 @@ def test_resource_limits_assign_score_nested end def test_resource_limits_aborts_rendering_after_first_error - t = Template.parse("{% for a in (1..100) %} foo1 {% endfor %} bar {% for a in (1..100) %} foo2 {% endfor %}") + t = Template.parse("{% for a in (1..100) %} foo1 {% endfor %} bar {% for a in (1..100) %} foo2 {% endfor %}") t.resource_limits.render_score_limit = 50 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -184,19 +184,19 @@ def test_resource_limits_hash_in_template_gets_updated_even_if_no_limits_are_set end def test_render_length_persists_between_blocks - t = Template.parse("{% if true %}aaaa{% endif %}") + t = Template.parse("{% if true %}aaaa{% endif %}") t.resource_limits.render_length_limit = 7 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 8 assert_equal "aaaa", t.render - t = Template.parse("{% if true %}aaaa{% endif %}{% if true %}bbb{% endif %}") + t = Template.parse("{% if true %}aaaa{% endif %}{% if true %}bbb{% endif %}") t.resource_limits.render_length_limit = 13 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 14 assert_equal "aaaabbb", t.render - t = Template.parse("{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}") + t = Template.parse("{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}") t.resource_limits.render_length_limit = 5 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 11 @@ -206,7 +206,7 @@ def test_render_length_persists_between_blocks end def test_render_length_uses_number_of_bytes_not_characters - t = Template.parse("{% if true %}すごい{% endif %}") + t = Template.parse("{% if true %}すごい{% endif %}") t.resource_limits.render_length_limit = 10 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 18 @@ -215,7 +215,7 @@ def test_render_length_uses_number_of_bytes_not_characters def test_default_resource_limits_unaffected_by_render_with_context context = Context.new - t = Template.parse("{% for a in (1..100) %} {% assign foo = 1 %} {% endfor %}") + t = Template.parse("{% for a in (1..100) %} {% assign foo = 1 %} {% endfor %}") t.render!(context) assert context.resource_limits.assign_score > 0 assert context.resource_limits.render_score > 0 @@ -223,9 +223,9 @@ def test_default_resource_limits_unaffected_by_render_with_context end def test_can_use_drop_as_context - t = Template.new + t = Template.new t.registers['lulz'] = 'haha' - drop = TemplateContextDrop.new + drop = TemplateContextDrop.new assert_equal 'fizzbuzz', t.parse('{{foo}}').render!(drop) assert_equal 'bar', t.parse('{{bar}}').render!(drop) assert_equal 'haha', t.parse("{{baz}}").render!(drop) @@ -233,7 +233,7 @@ def test_can_use_drop_as_context def test_render_bang_force_rethrow_errors_on_passed_context context = Context.new('drop' => ErroneousDrop.new) - t = Template.new.parse('{{ drop.bad_method }}') + t = Template.new.parse('{{ drop.bad_method }}') e = assert_raises RuntimeError do t.render!(context) @@ -243,7 +243,7 @@ def test_render_bang_force_rethrow_errors_on_passed_context def test_exception_renderer_that_returns_string exception = nil - handler = ->(e) { + handler = ->(e) { exception = e '' } @@ -267,20 +267,20 @@ def test_exception_renderer_that_raises def test_global_filter_option_on_render global_filter_proc = ->(output) { "#{output} filtered" } - rendered_template = Template.parse("{{name}}").render({ "name" => "bob" }, global_filter: global_filter_proc) + rendered_template = Template.parse("{{name}}").render({ "name" => "bob" }, global_filter: global_filter_proc) assert_equal 'bob filtered', rendered_template end def test_global_filter_option_when_native_filters_exist global_filter_proc = ->(output) { "#{output} filtered" } - rendered_template = Template.parse("{{name | upcase}}").render({ "name" => "bob" }, global_filter: global_filter_proc) + rendered_template = Template.parse("{{name | upcase}}").render({ "name" => "bob" }, global_filter: global_filter_proc) assert_equal 'BOB filtered', rendered_template end def test_undefined_variables - t = Template.parse("{{x}} {{y}} {{z.a}} {{z.b}} {{z.c.d}}") + t = Template.parse("{{x}} {{y}} {{z.a}} {{z.b}} {{z.c.d}}") result = t.render({ 'x' => 33, 'z' => { 'a' => 32, 'c' => { 'e' => 31 } } }, strict_variables: true) assert_equal '33 32 ', result @@ -295,8 +295,8 @@ def test_undefined_variables def test_nil_value_does_not_raise Liquid::Template.error_mode = :strict - t = Template.parse("some{{x}}thing") - result = t.render!({ 'x' => nil }, strict_variables: true) + t = Template.parse("some{{x}}thing") + result = t.render!({ 'x' => nil }, strict_variables: true) assert_equal 0, t.errors.count assert_equal 'something', result @@ -311,8 +311,8 @@ def test_undefined_variables_raise end def test_undefined_drop_methods - d = DropWithUndefinedMethod.new - t = Template.new.parse('{{ foo }} {{ woot }}') + d = DropWithUndefinedMethod.new + t = Template.new.parse('{{ foo }} {{ woot }}') result = t.render(d, strict_variables: true) assert_equal 'foo ', result @@ -330,13 +330,13 @@ def test_undefined_drop_methods_raise end def test_undefined_filters - t = Template.parse("{{a}} {{x | upcase | somefilter1 | somefilter2 | somefilter3}}") + t = Template.parse("{{a}} {{x | upcase | somefilter1 | somefilter2 | somefilter3}}") filters = Module.new do def somefilter3(v) "-#{v}-" end end - result = t.render({ 'a' => 123, 'x' => 'foo' }, filters: [filters], strict_filters: true) + result = t.render({ 'a' => 123, 'x' => 'foo' }, filters: [filters], strict_filters: true) assert_equal '123 ', result assert_equal 1, t.errors.count @@ -353,11 +353,11 @@ def test_undefined_filters_raise end def test_using_range_literal_works_as_expected - t = Template.parse("{% assign foo = (x..y) %}{{ foo }}") + t = Template.parse("{% assign foo = (x..y) %}{{ foo }}") result = t.render('x' => 1, 'y' => 5) assert_equal '1..5', result - t = Template.parse("{% assign nums = (x..y) %}{% for num in nums %}{{ num }}{% endfor %}") + t = Template.parse("{% assign nums = (x..y) %}{% for num in nums %}{{ num }}{% endfor %}") result = t.render('x' => 1, 'y' => 5) assert_equal '12345', result end diff --git a/test/integration/trim_mode_test.rb b/test/integration/trim_mode_test.rb index 438f86b5d..4c4d4c831 100644 --- a/test/integration/trim_mode_test.rb +++ b/test/integration/trim_mode_test.rb @@ -7,7 +7,7 @@ class TrimModeTest < Minitest::Test # Make sure the trim isn't applied to standard output def test_standard_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{ 'John' }} @@ -25,7 +25,7 @@ def test_standard_output end def test_variable_output_with_multiple_blank_lines - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

@@ -45,7 +45,7 @@ def test_variable_output_with_multiple_blank_lines end def test_tag_output_with_multiple_blank_lines - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

@@ -69,7 +69,7 @@ def test_tag_output_with_multiple_blank_lines # Make sure the trim isn't applied to standard tags def test_standard_tags whitespace = ' ' - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if true %} @@ -78,7 +78,7 @@ def test_standard_tags

END_TEMPLATE - expected = <<~END_EXPECTED + expected = <<~END_EXPECTED

#{whitespace} @@ -89,7 +89,7 @@ def test_standard_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if false %} @@ -110,64 +110,64 @@ def test_standard_tags # Make sure the trim isn't too agressive def test_no_trim_output - text = '

{{- \'John\' -}}

' + text = '

{{- \'John\' -}}

' expected = '

John

' assert_template_result(expected, text) end # Make sure the trim isn't too agressive def test_no_trim_tags - text = '

{%- if true -%}yes{%- endif -%}

' + text = '

{%- if true -%}yes{%- endif -%}

' expected = '

yes

' assert_template_result(expected, text) - text = '

{%- if false -%}no{%- endif -%}

' + text = '

{%- if false -%}no{%- endif -%}

' expected = '

' assert_template_result(expected, text) end def test_single_line_outer_tag - text = '

{%- if true %} yes {% endif -%}

' + text = '

{%- if true %} yes {% endif -%}

' expected = '

yes

' assert_template_result(expected, text) - text = '

{%- if false %} no {% endif -%}

' + text = '

{%- if false %} no {% endif -%}

' expected = '

' assert_template_result(expected, text) end def test_single_line_inner_tag - text = '

{% if true -%} yes {%- endif %}

' + text = '

{% if true -%} yes {%- endif %}

' expected = '

yes

' assert_template_result(expected, text) - text = '

{% if false -%} no {%- endif %}

' + text = '

{% if false -%} no {%- endif %}

' expected = '

' assert_template_result(expected, text) end def test_single_line_post_tag - text = '

{% if true -%} yes {% endif -%}

' + text = '

{% if true -%} yes {% endif -%}

' expected = '

yes

' assert_template_result(expected, text) - text = '

{% if false -%} no {% endif -%}

' + text = '

{% if false -%} no {% endif -%}

' expected = '

' assert_template_result(expected, text) end def test_single_line_pre_tag - text = '

{%- if true %} yes {%- endif %}

' + text = '

{%- if true %} yes {%- endif %}

' expected = '

yes

' assert_template_result(expected, text) - text = '

{%- if false %} no {%- endif %}

' + text = '

{%- if false %} no {%- endif %}

' expected = '

' assert_template_result(expected, text) end def test_pre_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{- 'John' }} @@ -184,7 +184,7 @@ def test_pre_trim_output end def test_pre_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if true %} @@ -202,7 +202,7 @@ def test_pre_trim_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if false %} @@ -221,7 +221,7 @@ def test_pre_trim_tags end def test_post_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{ 'John' -}} @@ -238,7 +238,7 @@ def test_post_trim_output end def test_post_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if true -%} @@ -256,7 +256,7 @@ def test_post_trim_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if false -%} @@ -275,7 +275,7 @@ def test_post_trim_tags end def test_pre_and_post_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if true %} @@ -293,7 +293,7 @@ def test_pre_and_post_trim_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if false %} @@ -311,7 +311,7 @@ def test_pre_and_post_trim_tags end def test_post_and_pre_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if true -%} @@ -330,7 +330,7 @@ def test_post_and_pre_trim_tags assert_template_result(expected, text) whitespace = ' ' - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if false -%} @@ -339,7 +339,7 @@ def test_post_and_pre_trim_tags

END_TEMPLATE - expected = <<~END_EXPECTED + expected = <<~END_EXPECTED

#{whitespace} @@ -350,7 +350,7 @@ def test_post_and_pre_trim_tags end def test_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{- 'John' -}} @@ -366,7 +366,7 @@ def test_trim_output end def test_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if true -%} @@ -382,7 +382,7 @@ def test_trim_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if false -%} @@ -400,7 +400,7 @@ def test_trim_tags end def test_whitespace_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{- 'John' -}}, @@ -417,7 +417,7 @@ def test_whitespace_trim_output end def test_whitespace_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if true -%} @@ -433,7 +433,7 @@ def test_whitespace_trim_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if false -%} @@ -451,7 +451,7 @@ def test_whitespace_trim_tags end def test_complex_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{- 'John' -}} @@ -481,7 +481,7 @@ def test_complex_trim_output end def test_complex_trim - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if true -%} {%- if true -%} @@ -504,7 +504,7 @@ def test_right_trim_followed_by_tag def test_raw_output whitespace = ' ' - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{% raw %} {%- if true -%} @@ -515,7 +515,7 @@ def test_raw_output {% endraw %}
END_TEMPLATE - expected = <<~END_EXPECTED + expected = <<~END_EXPECTED
#{whitespace} {%- if true -%} diff --git a/test/integration/variable_test.rb b/test/integration/variable_test.rb index 94ed1eca9..af8a4cca4 100644 --- a/test/integration/variable_test.rb +++ b/test/integration/variable_test.rb @@ -52,13 +52,13 @@ def test_nil_renders_as_empty_string end def test_preset_assigns - template = Template.parse(%({{ test }})) + template = Template.parse(%({{ test }})) template.assigns['test'] = 'worked' assert_equal 'worked', template.render! end def test_reuse_parsed_template - template = Template.parse(%({{ greeting }} {{ name }})) + template = Template.parse(%({{ greeting }} {{ name }})) template.assigns['greeting'] = 'Goodbye' assert_equal 'Hello Tobi', template.render!('greeting' => 'Hello', 'name' => 'Tobi') assert_equal 'Hello ', template.render!('greeting' => 'Hello', 'unknown' => 'Tobi') @@ -68,7 +68,7 @@ def test_reuse_parsed_template end def test_assigns_not_polluted_from_template - template = Template.parse(%({{ test }}{% assign test = 'bar' %}{{ test }})) + template = Template.parse(%({{ test }}{% assign test = 'bar' %}{{ test }})) template.assigns['test'] = 'baz' assert_equal 'bazbar', template.render! assert_equal 'bazbar', template.render! @@ -77,12 +77,12 @@ def test_assigns_not_polluted_from_template end def test_hash_with_default_proc - template = Template.parse(%(Hello {{ test }})) - assigns = Hash.new { |_h, k| raise "Unknown variable '#{k}'" } + template = Template.parse(%(Hello {{ test }})) + assigns = Hash.new { |_h, k| raise "Unknown variable '#{k}'" } assigns['test'] = 'Tobi' assert_equal 'Hello Tobi', template.render!(assigns) assigns.delete('test') - e = assert_raises(RuntimeError) do + e = assert_raises(RuntimeError) do template.render!(assigns) end assert_equal "Unknown variable 'test'", e.message diff --git a/test/test_helper.rb b/test/test_helper.rb index 9606ef8fb..0f00effb2 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,8 +8,8 @@ require 'liquid.rb' require 'liquid/profiler' -mode = :strict -if (env_mode = ENV['LIQUID_PARSER_MODE']) +mode = :strict +if (env_mode = ENV['LIQUID_PARSER_MODE']) puts "-- #{env_mode.upcase} ERROR MODE" mode = env_mode.to_sym end @@ -71,7 +71,7 @@ def with_global_filter(*globals) end def with_taint_mode(mode) - old_mode = Liquid::Template.taint_mode + old_mode = Liquid::Template.taint_mode Liquid::Template.taint_mode = mode yield ensure @@ -79,7 +79,7 @@ def with_taint_mode(mode) end def with_error_mode(mode) - old_mode = Liquid::Template.error_mode + old_mode = Liquid::Template.error_mode Liquid::Template.error_mode = mode yield ensure @@ -128,7 +128,7 @@ class StubFileSystem def initialize(values) @file_read_count = 0 - @values = values + @values = values end def read_template_file(template_path) diff --git a/test/unit/block_unit_test.rb b/test/unit/block_unit_test.rb index fa06a8774..0f79a51f0 100644 --- a/test/unit/block_unit_test.rb +++ b/test/unit/block_unit_test.rb @@ -63,7 +63,7 @@ def render(*) assert_equal 'hello', template.render - buf = +'' + buf = +'' output = template.render({}, output: buf) assert_equal 'hello', output assert_equal 'hello', buf @@ -81,7 +81,7 @@ def render(*) assert_equal 'foohellobar', template.render - buf = +'' + buf = +'' output = template.render({}, output: buf) assert_equal 'foohellobar', output assert_equal 'foohellobar', buf diff --git a/test/unit/condition_unit_test.rb b/test/unit/condition_unit_test.rb index 8d4e02f9d..e79c86351 100644 --- a/test/unit/condition_unit_test.rb +++ b/test/unit/condition_unit_test.rb @@ -75,9 +75,9 @@ def test_hash_compare_backwards_compatibility end def test_contains_works_on_arrays - @context = Liquid::Context.new + @context = Liquid::Context.new @context['array'] = [1, 2, 3, 4, 5] - array_expr = VariableLookup.new("array") + array_expr = VariableLookup.new("array") assert_evaluates_false array_expr, 'contains', 0 assert_evaluates_true array_expr, 'contains', 1 @@ -142,7 +142,7 @@ def test_should_allow_custom_proc_operator end def test_left_or_right_may_contain_operators - @context = Liquid::Context.new + @context = Liquid::Context.new @context['one'] = @context['another'] = "gnomeslab-and-or-liquid" assert_evaluates_true VariableLookup.new("one"), '==', VariableLookup.new("another") diff --git a/test/unit/context_unit_test.rb b/test/unit/context_unit_test.rb index 3b460d7a3..8b132a1df 100644 --- a/test/unit/context_unit_test.rb +++ b/test/unit/context_unit_test.rb @@ -46,7 +46,7 @@ def initialize(category) class CounterDrop < Liquid::Drop def count @count ||= 0 - @count += 1 + @count += 1 end end @@ -55,9 +55,9 @@ def fetch(index) end def [](index) - @counts ||= [] + @counts ||= [] @counts[index] ||= 0 - @counts[index] += 1 + @counts[index] += 1 end def to_liquid @@ -85,7 +85,7 @@ def test_variables @context['date'] = Date.today assert_equal Date.today, @context['date'] - now = Time.now + now = Time.now @context['datetime'] = now assert_equal now, @context['datetime'] @@ -265,7 +265,7 @@ def test_try_first def test_access_hashes_with_hash_notation @context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] } - @context['product'] = { 'variants' => [{ 'title' => 'draft151cm' }, { 'title' => 'element151cm' }] } + @context['product'] = { 'variants' => [{ 'title' => 'draft151cm' }, { 'title' => 'element151cm' }] } assert_equal 5, @context['products["count"]'] assert_equal 'deepsnow', @context['products["tags"][0]'] @@ -285,8 +285,8 @@ def test_access_variable_with_hash_notation end def test_access_hashes_with_hash_access_variables - @context['var'] = 'tags' - @context['nested'] = { 'var' => 'tags' } + @context['var'] = 'tags' + @context['nested'] = { 'var' => 'tags' } @context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] } assert_equal 'deepsnow', @context['products[var].first'] @@ -295,7 +295,7 @@ def test_access_hashes_with_hash_access_variables def test_hash_notation_only_for_hash_access @context['array'] = [1, 2, 3, 4, 5] - @context['hash'] = { 'first' => 'Hello' } + @context['hash'] = { 'first' => 'Hello' } assert_equal 1, @context['array.first'] assert_nil @context['array["first"]'] @@ -407,7 +407,7 @@ def test_array_containing_lambda_as_variable def test_lambda_is_called_once @context['callcount'] = proc { @global ||= 0 - @global += 1 + @global += 1 @global.to_s } @@ -421,7 +421,7 @@ def test_lambda_is_called_once def test_nested_lambda_is_called_once @context['callcount'] = { "lambda" => proc { @global ||= 0 - @global += 1 + @global += 1 @global.to_s } } @@ -435,7 +435,7 @@ def test_nested_lambda_is_called_once def test_lambda_in_array_is_called_once @context['callcount'] = [1, 2, proc { @global ||= 0 - @global += 1 + @global += 1 @global.to_s }, 4, 5] @@ -476,7 +476,7 @@ def test_context_initialization_with_a_proc_in_environment def test_apply_global_filter global_filter_proc = ->(output) { "#{output} filtered" } - context = Context.new + context = Context.new context.global_filter = global_filter_proc assert_equal 'hi filtered', context.apply_global_filter('hi') @@ -498,53 +498,53 @@ def test_apply_global_filter_when_no_global_filter_exist end def test_new_isolated_subcontext_does_not_inherit_variables - super_context = Context.new + super_context = Context.new super_context['my_variable'] = 'some value' - subcontext = super_context.new_isolated_subcontext + subcontext = super_context.new_isolated_subcontext assert_nil subcontext['my_variable'] end def test_new_isolated_subcontext_inherits_static_environment super_context = Context.build(static_environments: { 'my_environment_value' => 'my value' }) - subcontext = super_context.new_isolated_subcontext + subcontext = super_context.new_isolated_subcontext assert_equal 'my value', subcontext['my_environment_value'] end def test_new_isolated_subcontext_inherits_resource_limits resource_limits = ResourceLimits.new({}) - super_context = Context.new({}, {}, {}, false, resource_limits) - subcontext = super_context.new_isolated_subcontext + super_context = Context.new({}, {}, {}, false, resource_limits) + subcontext = super_context.new_isolated_subcontext assert_equal resource_limits, subcontext.resource_limits end def test_new_isolated_subcontext_inherits_exception_renderer - super_context = Context.new + super_context = Context.new super_context.exception_renderer = ->(_e) { 'my exception message' } - subcontext = super_context.new_isolated_subcontext + subcontext = super_context.new_isolated_subcontext assert_equal 'my exception message', subcontext.handle_error(Liquid::Error.new) end def test_new_isolated_subcontext_does_not_inherit_non_static_registers - registers = { + registers = { my_register: :my_value, } - super_context = Context.new({}, {}, StaticRegisters.new(registers)) + super_context = Context.new({}, {}, StaticRegisters.new(registers)) super_context.registers[:my_register] = :my_alt_value - subcontext = super_context.new_isolated_subcontext + subcontext = super_context.new_isolated_subcontext assert_equal :my_value, subcontext.registers[:my_register] end def test_new_isolated_subcontext_inherits_static_registers super_context = Context.build(registers: { my_register: :my_value }) - subcontext = super_context.new_isolated_subcontext + subcontext = super_context.new_isolated_subcontext assert_equal :my_value, subcontext.registers[:my_register] end def test_new_isolated_subcontext_registers_do_not_pollute_context - super_context = Context.build(registers: { my_register: :my_value }) - subcontext = super_context.new_isolated_subcontext + super_context = Context.build(registers: { my_register: :my_value }) + subcontext = super_context.new_isolated_subcontext subcontext.registers[:my_register] = :my_alt_value assert_equal :my_value, super_context.registers[:my_register] end @@ -558,8 +558,8 @@ def my_filter(*) super_context = Context.new super_context.add_filters([my_filter]) - subcontext = super_context.new_isolated_subcontext - template = Template.parse('{{ 123 | my_filter }}') + subcontext = super_context.new_isolated_subcontext + template = Template.parse('{{ 123 | my_filter }}') assert_equal 'my filter result', template.render(subcontext) end diff --git a/test/unit/partial_cache_unit_test.rb b/test/unit/partial_cache_unit_test.rb index dd4318530..145c27d1f 100644 --- a/test/unit/partial_cache_unit_test.rb +++ b/test/unit/partial_cache_unit_test.rb @@ -21,7 +21,7 @@ def test_uses_the_file_system_register_if_present def test_reads_from_the_file_system_only_once_per_file file_system = StubFileSystem.new('my_partial' => 'some partial body') - context = Liquid::Context.build( + context = Liquid::Context.build( registers: { file_system: file_system } ) @@ -37,16 +37,16 @@ def test_reads_from_the_file_system_only_once_per_file end def test_cache_state_is_stored_per_context - parse_context = Liquid::ParseContext.new + parse_context = Liquid::ParseContext.new shared_file_system = StubFileSystem.new( 'my_partial' => 'my shared value' ) - context_one = Liquid::Context.build( + context_one = Liquid::Context.build( registers: { file_system: shared_file_system, } ) - context_two = Liquid::Context.build( + context_two = Liquid::Context.build( registers: { file_system: shared_file_system, } @@ -71,7 +71,7 @@ def test_cache_state_is_stored_per_context def test_cache_is_not_broken_when_a_different_parse_context_is_used file_system = StubFileSystem.new('my_partial' => 'some partial body') - context = Liquid::Context.build( + context = Liquid::Context.build( registers: { file_system: file_system } ) diff --git a/test/unit/static_registers_unit_test.rb b/test/unit/static_registers_unit_test.rb index 125440f21..620375bf3 100644 --- a/test/unit/static_registers_unit_test.rb +++ b/test/unit/static_registers_unit_test.rb @@ -6,10 +6,10 @@ class StaticRegistersUnitTest < Minitest::Test include Liquid def set - static_register = StaticRegisters.new - static_register[nil] = true - static_register[1] = :one - static_register[:one] = "one" + static_register = StaticRegisters.new + static_register[nil] = true + static_register[1] = :one + static_register[:one] = "one" static_register["two"] = "three" static_register["two"] = 3 static_register[false] = nil @@ -77,10 +77,10 @@ def test_key end def set_with_static - static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) - static_register[nil] = false + static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) + static_register[nil] = false static_register["two"] = 4 - static_register[true] = "foo" + static_register[true] = "foo" assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static) assert_equal({ nil => false, "two" => 4, true => "foo" }, static_register.registers) @@ -154,23 +154,23 @@ def test_static_register_can_be_frozen end def test_new_static_retains_static - static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) - static_register["one"] = 1 - static_register["two"] = 2 + static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) + static_register["one"] = 1 + static_register["two"] = 2 static_register["three"] = 3 new_register = StaticRegisters.new(static_register) assert_equal({}, new_register.registers) - new_register["one"] = 4 - new_register["two"] = 5 + new_register["one"] = 4 + new_register["two"] = 5 new_register["three"] = 6 newest_register = StaticRegisters.new(new_register) assert_equal({}, newest_register.registers) - newest_register["one"] = 7 - newest_register["two"] = 8 + newest_register["one"] = 7 + newest_register["two"] = 8 newest_register["three"] = 9 assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers) @@ -182,23 +182,23 @@ def test_new_static_retains_static end def test_multiple_instances_are_unique - static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) - static_register["one"] = 1 - static_register["two"] = 2 + static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) + static_register["one"] = 1 + static_register["two"] = 2 static_register["three"] = 3 new_register = StaticRegisters.new(foo: :bar) assert_equal({}, new_register.registers) - new_register["one"] = 4 - new_register["two"] = 5 + new_register["one"] = 4 + new_register["two"] = 5 new_register["three"] = 6 newest_register = StaticRegisters.new(bar: :foo) assert_equal({}, newest_register.registers) - newest_register["one"] = 7 - newest_register["two"] = 8 + newest_register["one"] = 7 + newest_register["two"] = 8 newest_register["three"] = 9 assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers) @@ -210,9 +210,9 @@ def test_multiple_instances_are_unique end def test_can_update_static_directly_and_updates_all_instances - static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) - static_register["one"] = 1 - static_register["two"] = 2 + static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) + static_register["one"] = 1 + static_register["two"] = 2 static_register["three"] = 3 new_register = StaticRegisters.new(static_register) @@ -220,9 +220,9 @@ def test_can_update_static_directly_and_updates_all_instances assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static) - new_register["one"] = 4 - new_register["two"] = 5 - new_register["three"] = 6 + new_register["one"] = 4 + new_register["two"] = 5 + new_register["three"] = 6 new_register.static["four"] = 10 newest_register = StaticRegisters.new(new_register) @@ -230,9 +230,9 @@ def test_can_update_static_directly_and_updates_all_instances assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil, "four" => 10 }, new_register.static) - newest_register["one"] = 7 - newest_register["two"] = 8 - newest_register["three"] = 9 + newest_register["one"] = 7 + newest_register["two"] = 8 + newest_register["three"] = 9 new_register.static["four"] = 5 new_register.static["five"] = 15 diff --git a/test/unit/strainer_unit_test.rb b/test/unit/strainer_unit_test.rb index 2fb9ad440..b2d393aa4 100644 --- a/test/unit/strainer_unit_test.rb +++ b/test/unit/strainer_unit_test.rb @@ -72,8 +72,8 @@ def test_strainer_only_allows_methods_defined_in_filters end def test_strainer_uses_a_class_cache_to_avoid_method_cache_invalidation - a = Module.new - b = Module.new + a = Module.new + b = Module.new strainer = Strainer.create(nil, [a, b]) assert_kind_of Strainer, strainer assert_kind_of a, strainer @@ -82,8 +82,8 @@ def test_strainer_uses_a_class_cache_to_avoid_method_cache_invalidation end def test_add_filter_when_wrong_filter_class - c = Context.new - s = c.strainer + c = Context.new + s = c.strainer wrong_filter = ->(v) { v.reverse } assert_raises ArgumentError do @@ -150,7 +150,7 @@ def test_global_filter_clears_cache end def test_add_filter_does_not_include_already_included_module - mod = Module.new do + mod = Module.new do class << self attr_accessor :include_count def included(_mod) diff --git a/test/unit/tag_unit_test.rb b/test/unit/tag_unit_test.rb index c9543e921..c5de4ad45 100644 --- a/test/unit/tag_unit_test.rb +++ b/test/unit/tag_unit_test.rb @@ -33,7 +33,7 @@ def render(*) assert_equal 'hello', template.render - buf = +'' + buf = +'' output = template.render({}, output: buf) assert_equal 'hello', output assert_equal 'hello', buf @@ -51,7 +51,7 @@ def render(*) assert_equal 'foohellobar', template.render - buf = +'' + buf = +'' output = template.render({}, output: buf) assert_equal 'foohellobar', output assert_equal 'foohellobar', buf diff --git a/test/unit/template_unit_test.rb b/test/unit/template_unit_test.rb index bc02896d7..deb4f25ab 100644 --- a/test/unit/template_unit_test.rb +++ b/test/unit/template_unit_test.rb @@ -22,7 +22,7 @@ def test_sets_default_localization_in_context_with_quick_initialization def test_with_cache_classes_tags_returns_the_same_class original_cache_setting = Liquid.cache_classes - Liquid.cache_classes = true + Liquid.cache_classes = true original_klass = Class.new Object.send(:const_set, :CustomTag, original_klass) @@ -42,7 +42,7 @@ def test_with_cache_classes_tags_returns_the_same_class def test_without_cache_classes_tags_reloads_the_class original_cache_setting = Liquid.cache_classes - Liquid.cache_classes = false + Liquid.cache_classes = false original_klass = Class.new Object.send(:const_set, :CustomTag, original_klass) diff --git a/test/unit/tokenizer_unit_test.rb b/test/unit/tokenizer_unit_test.rb index 44342d6c1..092c743da 100644 --- a/test/unit/tokenizer_unit_test.rb +++ b/test/unit/tokenizer_unit_test.rb @@ -34,15 +34,15 @@ def test_calculate_line_numbers_per_token_with_profiling def tokenize(source) tokenizer = Liquid::Tokenizer.new(source) - tokens = [] - while (t = tokenizer.shift) + tokens = [] + while (t = tokenizer.shift) tokens << t end tokens end def tokenize_line_numbers(source) - tokenizer = Liquid::Tokenizer.new(source, true) + tokenizer = Liquid::Tokenizer.new(source, true) line_numbers = [] loop do line_number = tokenizer.line_number From 00c8ca559a5352ad8fcc12d90185fee68737f88f Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Fri, 20 Sep 2019 02:42:21 +1000 Subject: [PATCH 3/6] Revert "Fix spacing" This reverts commit 26eb27f79f387a8355b0e0f14fa3c170c3b8c524. --- .rubocop.yml | 3 - Rakefile | 2 +- example/server/liquid_servlet.rb | 8 +-- lib/liquid.rb | 10 +-- lib/liquid/block_body.rb | 30 ++++----- lib/liquid/condition.rb | 16 ++--- lib/liquid/context.rb | 22 +++--- lib/liquid/errors.rb | 26 ++++---- lib/liquid/expression.rb | 2 +- lib/liquid/file_system.rb | 2 +- lib/liquid/forloop_drop.rb | 6 +- lib/liquid/legacy.rb | 56 ++++++++-------- lib/liquid/lexer.rb | 13 ++-- lib/liquid/parse_context.rb | 12 ++-- lib/liquid/parse_tree_visitor.rb | 8 +-- lib/liquid/parser.rb | 9 +-- lib/liquid/parser_switching.rb | 2 +- lib/liquid/partial_cache.rb | 8 +-- lib/liquid/profiler.rb | 8 +-- lib/liquid/range_lookup.rb | 6 +- lib/liquid/resource_limits.rb | 4 +- lib/liquid/standardfilters.rb | 21 +++--- lib/liquid/static_registers.rb | 2 +- lib/liquid/strainer.rb | 2 +- lib/liquid/tablerowloop_drop.rb | 10 +-- lib/liquid/tag.rb | 6 +- lib/liquid/tags/assign.rb | 8 +-- lib/liquid/tags/capture.rb | 4 +- lib/liquid/tags/case.rb | 2 +- lib/liquid/tags/cycle.rb | 10 +-- lib/liquid/tags/decrement.rb | 4 +- lib/liquid/tags/for.rb | 26 ++++---- lib/liquid/tags/if.rb | 16 ++--- lib/liquid/tags/include.rb | 8 +-- lib/liquid/tags/increment.rb | 2 +- lib/liquid/tags/raw.rb | 4 +- lib/liquid/tags/render.rb | 4 +- lib/liquid/tags/table_row.rb | 8 +-- lib/liquid/template.rb | 22 +++--- lib/liquid/tokenizer.rb | 6 +- lib/liquid/utils.rb | 2 +- lib/liquid/variable.rb | 30 ++++----- lib/liquid/variable_lookup.rb | 10 +-- performance/benchmark.rb | 4 +- performance/profile.rb | 2 +- performance/shopify/comment_form.rb | 2 +- performance/shopify/database.rb | 2 +- performance/shopify/paginate.rb | 2 +- performance/theme_runner.rb | 14 ++-- test/integration/assign_test.rb | 4 +- test/integration/capture_test.rb | 12 ++-- test/integration/drop_test.rb | 2 +- test/integration/error_handling_test.rb | 14 ++-- test/integration/filter_test.rb | 20 +++--- test/integration/output_test.rb | 18 ++--- test/integration/parsing_quirks_test.rb | 2 +- test/integration/security_test.rb | 12 ++-- test/integration/standard_filter_test.rb | 14 ++-- test/integration/tags/break_tag_test.rb | 4 +- test/integration/tags/continue_tag_test.rb | 4 +- test/integration/tags/for_tag_test.rb | 78 +++++++++++----------- test/integration/tags/if_else_tag_test.rb | 6 +- test/integration/tags/include_tag_test.rb | 6 +- test/integration/tags/render_tag_test.rb | 4 +- test/integration/tags/standard_tag_test.rb | 2 +- test/integration/template_test.rb | 64 +++++++++--------- test/integration/trim_mode_test.rb | 76 ++++++++++----------- test/integration/variable_test.rb | 12 ++-- test/test_helper.rb | 10 +-- test/unit/block_unit_test.rb | 4 +- test/unit/condition_unit_test.rb | 6 +- test/unit/context_unit_test.rb | 54 +++++++-------- test/unit/partial_cache_unit_test.rb | 10 +-- test/unit/static_registers_unit_test.rb | 60 ++++++++--------- test/unit/strainer_unit_test.rb | 10 +-- test/unit/tag_unit_test.rb | 4 +- test/unit/template_unit_test.rb | 4 +- test/unit/tokenizer_unit_test.rb | 6 +- 78 files changed, 500 insertions(+), 508 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c10e4237d..1c0f83244 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,9 +7,6 @@ require: rubocop-performance Performance: Enabled: true -Layout/ExtraSpacing: - ForceEqualSignAlignment: true - AllCops: TargetRubyVersion: 2.4 Exclude: diff --git a/Rakefile b/Rakefile index 780ec3535..66ae0faee 100755 --- a/Rakefile +++ b/Rakefile @@ -11,7 +11,7 @@ desc('run test suite with default parser') Rake::TestTask.new(:base_test) do |t| t.libs << '.' << 'lib' << 'test' t.test_files = FileList['test/{integration,unit}/**/*_test.rb'] - t.verbose = false + t.verbose = false end desc('run test suite with warn error mode') diff --git a/example/server/liquid_servlet.rb b/example/server/liquid_servlet.rb index 4965fff9a..55e21d215 100644 --- a/example/server/liquid_servlet.rb +++ b/example/server/liquid_servlet.rb @@ -12,16 +12,16 @@ def do_POST(req, res) private def handle(_type, req, res) - @request = req + @request = req @response = res @request.path_info =~ /(\w+)\z/ - @action = Regexp.last_match(1) || 'index' + @action = Regexp.last_match(1) || 'index' @assigns = send(@action) if respond_to?(@action) @response['Content-Type'] = "text/html" - @response.status = 200 - @response.body = Liquid::Template.parse(read_template).render(@assigns, filters: [ProductsFilter]) + @response.status = 200 + @response.body = Liquid::Template.parse(read_template).render(@assigns, filters: [ProductsFilter]) end def read_template(filename = @action) diff --git a/lib/liquid.rb b/lib/liquid.rb index ee7a4ef76..7b4f098e7 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -24,8 +24,8 @@ module Liquid FILTER_SEPARATOR = /\|/ ARGUMENT_SEPARATOR = ',' - FILTER_ARGUMENT_SEPARATOR = ':' - VARIABLE_ATTRIBUTE_SEPARATOR = '.' + FILTER_ARGUMENT_SEPARATOR = ':' + VARIABLE_ATTRIBUTE_SEPARATOR = '.' WHITESPACE_CONTROL = '-' TAG_START = /\{\%/ TAG_END = /\%\}/ @@ -33,12 +33,12 @@ module Liquid VARIABLE_SEGMENT = /[\w\-]/ VARIABLE_START = /\{\{/ VARIABLE_END = /\}\}/ - VARIABLE_INCOMPLETE_END = /\}\}?/ + VARIABLE_INCOMPLETE_END = /\}\}?/ QUOTED_STRING = /"[^"]*"|'[^']*'/ QUOTED_FRAGMENT = /#{QUOTED_STRING}|(?:[^\s,\|'"]|#{QUOTED_STRING})+/o TAG_ATTRIBUTES = /(\w+)\s*\:\s*(#{QUOTED_FRAGMENT})/o - ANY_STARTING_TAG = /#{TAG_START}|#{VARIABLE_START}/o - PARTIAL_TEMPLATE_PARSER = /#{TAG_START}.*?#{TAG_END}|#{VARIABLE_START}.*?#{VARIABLE_INCOMPLETE_END}/om + ANY_STARTING_TAG = /#{TAG_START}|#{VARIABLE_START}/o + PARTIAL_TEMPLATE_PARSER = /#{TAG_START}.*?#{TAG_END}|#{VARIABLE_START}.*?#{VARIABLE_INCOMPLETE_END}/om TEMPLATE_PARSER = /(#{PARTIAL_TEMPLATE_PARSER}|#{ANY_STARTING_TAG})/om VARIABLE_PARSER = /\[[^\]]+\]|#{VARIABLE_SEGMENT}+\??/o diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 0ede86568..2f3433e4c 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -2,18 +2,18 @@ module Liquid class BlockBody - LIQUID_TAG_TOKEN = /\A\s*(\w+)\s*(.*?)\z/o - FULL_TOKEN = /\A#{TAG_START}#{WHITESPACE_CONTROL}?(\s*)(\w+)(\s*)(.*?)#{WHITESPACE_CONTROL}?#{TAG_END}\z/om - CONTENT_OF_VARIABLE = /\A#{VARIABLE_START}#{WHITESPACE_CONTROL}?(.*?)#{WHITESPACE_CONTROL}?#{VARIABLE_END}\z/om + LIQUID_TAG_TOKEN = /\A\s*(\w+)\s*(.*?)\z/o + FULL_TOKEN = /\A#{TAG_START}#{WHITESPACE_CONTROL}?(\s*)(\w+)(\s*)(.*?)#{WHITESPACE_CONTROL}?#{TAG_END}\z/om + CONTENT_OF_VARIABLE = /\A#{VARIABLE_START}#{WHITESPACE_CONTROL}?(.*?)#{WHITESPACE_CONTROL}?#{VARIABLE_END}\z/om WHITESPACE_OR_NOTHING = /\A\s*\z/ - TAG_START_STRING = "{%" - VAR_START_STRING = "{{" + TAG_START_STRING = "{%" + VAR_START_STRING = "{{" attr_reader :nodelist def initialize @nodelist = [] - @blank = true + @blank = true end def parse(tokenizer, parse_context, &block) @@ -34,15 +34,15 @@ def parse(tokenizer, parse_context, &block) # caller raise a syntax error return yield token, token end - tag_name = Regexp.last_match(1) - markup = Regexp.last_match(2) + tag_name = Regexp.last_match(1) + markup = Regexp.last_match(2) unless (tag = registered_tags[tag_name]) # end parsing if we reach an unknown tag and let the caller decide # determine how to proceed return yield tag_name, markup end - new_tag = tag.parse(tag_name, markup, tokenizer, parse_context) - @blank &&= new_tag.blank? + new_tag = tag.parse(tag_name, markup, tokenizer, parse_context) + @blank &&= new_tag.blank? @nodelist << new_tag end parse_context.line_number = tokenizer.line_number @@ -61,7 +61,7 @@ def parse(tokenizer, parse_context, &block) raise_missing_tag_terminator(token, parse_context) end tag_name = Regexp.last_match(2) - markup = Regexp.last_match(4) + markup = Regexp.last_match(4) if parse_context.line_number # newlines inside the tag should increase the line number, @@ -79,8 +79,8 @@ def parse(tokenizer, parse_context, &block) # determine how to proceed return yield tag_name, markup end - new_tag = tag.parse(tag_name, markup, tokenizer, parse_context) - @blank &&= new_tag.blank? + new_tag = tag.parse(tag_name, markup, tokenizer, parse_context) + @blank &&= new_tag.blank? @nodelist << new_tag when token.start_with?(VAR_START_STRING) whitespace_handler(token, parse_context) @@ -92,7 +92,7 @@ def parse(tokenizer, parse_context, &block) end parse_context.trim_whitespace = false @nodelist << token - @blank &&= !!(token =~ WHITESPACE_OR_NOTHING) + @blank &&= !!(token =~ WHITESPACE_OR_NOTHING) end parse_context.line_number = tokenizer.line_number end @@ -121,7 +121,7 @@ def render(context) def render_to_output_buffer(context, output) context.resource_limits.render_score += @nodelist.length - idx = 0 + idx = 0 while (node = @nodelist[idx]) previous_output_size = output.bytesize diff --git a/lib/liquid/condition.rb b/lib/liquid/condition.rb index fab74d764..93ec68b74 100644 --- a/lib/liquid/condition.rb +++ b/lib/liquid/condition.rb @@ -35,16 +35,16 @@ def self.operators attr_accessor :left, :operator, :right def initialize(left = nil, operator = nil, right = nil) - @left = left - @operator = operator - @right = right - @child_relation = nil + @left = left + @operator = operator + @right = right + @child_relation = nil @child_condition = nil end def evaluate(context = Context.new) condition = self - result = nil + result = nil loop do result = interpret_condition(condition.left, condition.right, condition.operator, context) @@ -62,12 +62,12 @@ def evaluate(context = Context.new) end def or(condition) - @child_relation = :or + @child_relation = :or @child_condition = condition end def and(condition) - @child_relation = :and + @child_relation = :and @child_condition = condition end @@ -115,7 +115,7 @@ def interpret_condition(left, right, op, context) # return this as the result. return context.evaluate(left) if op.nil? - left = context.evaluate(left) + left = context.evaluate(left) right = context.evaluate(right) operation = self.class.operators[op] || raise(Liquid::ArgumentError, "Unknown operator #{op}") diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 397ae0f19..88e467134 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -41,8 +41,8 @@ def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_erro self.exception_renderer = ->(_e) { raise } end - @interrupts = [] - @filters = [] + @interrupts = [] + @filters = [] @global_filter = nil end # rubocop:enable Metrics/ParameterLists @@ -60,7 +60,7 @@ def strainer # Note that this does not register the filters with the main Template object. see Template.register_filter # for that def add_filters(filters) - filters = [filters].flatten.compact + filters = [filters].flatten.compact @filters += filters @strainer = nil end @@ -85,9 +85,9 @@ def pop_interrupt end def handle_error(e, line_number = nil) - e = internal_error unless e.is_a?(Liquid::Error) + e = internal_error unless e.is_a?(Liquid::Error) e.template_name ||= template_name - e.line_number ||= line_number + e.line_number ||= line_number errors.push(e) exception_renderer.call(e).to_s end @@ -138,12 +138,12 @@ def new_isolated_subcontext static_environments: static_environments, registers: StaticRegisters.new(registers) ).tap do |subcontext| - subcontext.base_scope_depth = base_scope_depth + 1 + subcontext.base_scope_depth = base_scope_depth + 1 subcontext.exception_renderer = exception_renderer - subcontext.filters = @filters - subcontext.strainer = nil - subcontext.errors = errors - subcontext.warnings = warnings + subcontext.filters = @filters + subcontext.strainer = nil + subcontext.errors = errors + subcontext.warnings = warnings end end @@ -188,7 +188,7 @@ def find_variable(key, raise_on_not_found: true) try_variable_find_in_environments(key, raise_on_not_found: raise_on_not_found) end - variable = variable.to_liquid + variable = variable.to_liquid variable.context = self if variable.respond_to?(:context=) variable diff --git a/lib/liquid/errors.rb b/lib/liquid/errors.rb index 4937da380..eda0bd2a4 100644 --- a/lib/liquid/errors.rb +++ b/lib/liquid/errors.rb @@ -40,19 +40,19 @@ def message_prefix end end - ArgumentError = Class.new(Error) - ContextError = Class.new(Error) - FileSystemError = Class.new(Error) - StandardError = Class.new(Error) - SyntaxError = Class.new(Error) - StackLevelError = Class.new(Error) - TaintedError = Class.new(Error) - MemoryError = Class.new(Error) - ZeroDivisionError = Class.new(Error) - FloatDomainError = Class.new(Error) - UndefinedVariable = Class.new(Error) + ArgumentError = Class.new(Error) + ContextError = Class.new(Error) + FileSystemError = Class.new(Error) + StandardError = Class.new(Error) + SyntaxError = Class.new(Error) + StackLevelError = Class.new(Error) + TaintedError = Class.new(Error) + MemoryError = Class.new(Error) + ZeroDivisionError = Class.new(Error) + FloatDomainError = Class.new(Error) + UndefinedVariable = Class.new(Error) UndefinedDropMethod = Class.new(Error) - UndefinedFilter = Class.new(Error) + UndefinedFilter = Class.new(Error) MethodOverrideError = Class.new(Error) - InternalError = Class.new(Error) + InternalError = Class.new(Error) end diff --git a/lib/liquid/expression.rb b/lib/liquid/expression.rb index 58633e1e5..9670906b8 100644 --- a/lib/liquid/expression.rb +++ b/lib/liquid/expression.rb @@ -7,7 +7,7 @@ class MethodLiteral def initialize(method_name, to_s) @method_name = method_name - @to_s = to_s + @to_s = to_s end def to_liquid diff --git a/lib/liquid/file_system.rb b/lib/liquid/file_system.rb index 67ba47cb1..27ab63257 100644 --- a/lib/liquid/file_system.rb +++ b/lib/liquid/file_system.rb @@ -47,7 +47,7 @@ class LocalFileSystem attr_accessor :root def initialize(root, pattern = "_%s.liquid") - @root = root + @root = root @pattern = pattern end diff --git a/lib/liquid/forloop_drop.rb b/lib/liquid/forloop_drop.rb index 4685166f8..0ffa25590 100644 --- a/lib/liquid/forloop_drop.rb +++ b/lib/liquid/forloop_drop.rb @@ -3,10 +3,10 @@ module Liquid class ForloopDrop < Drop def initialize(name, length, parentloop) - @name = name - @length = length + @name = name + @length = length @parentloop = parentloop - @index = 0 + @index = 0 end attr_reader :name, :length, :parentloop diff --git a/lib/liquid/legacy.rb b/lib/liquid/legacy.rb index 70fb18670..5cd66bc0b 100644 --- a/lib/liquid/legacy.rb +++ b/lib/liquid/legacy.rb @@ -1,32 +1,32 @@ # frozen_string_literal: true module Liquid - FilterSeparator = FILTER_SEPARATOR - ArgumentSeparator = ARGUMENT_SEPARATOR - FilterArgumentSeparator = FILTER_ARGUMENT_SEPARATOR + FilterSeparator = FILTER_SEPARATOR + ArgumentSeparator = ARGUMENT_SEPARATOR + FilterArgumentSeparator = FILTER_ARGUMENT_SEPARATOR VariableAttributeSeparator = VARIABLE_ATTRIBUTE_SEPARATOR - WhitespaceControl = WHITESPACE_CONTROL - TagStart = TAG_START - TagEnd = TAG_END - VariableSignature = VARIABLE_SIGNATURE - VariableSegment = VARIABLE_SEGMENT - VariableStart = VARIABLE_START - VariableEnd = VARIABLE_END - VariableIncompleteEnd = VARIABLE_INCOMPLETE_END - QuotedString = QUOTED_STRING - QuotedFragment = QUOTED_FRAGMENT - TagAttributes = TAG_ATTRIBUTES - AnyStartingTag = ANY_STARTING_TAG - PartialTemplateParser = PARTIAL_TEMPLATE_PARSER - TemplateParser = TEMPLATE_PARSER - VariableParser = VARIABLE_PARSER + WhitespaceControl = WHITESPACE_CONTROL + TagStart = TAG_START + TagEnd = TAG_END + VariableSignature = VARIABLE_SIGNATURE + VariableSegment = VARIABLE_SEGMENT + VariableStart = VARIABLE_START + VariableEnd = VARIABLE_END + VariableIncompleteEnd = VARIABLE_INCOMPLETE_END + QuotedString = QUOTED_STRING + QuotedFragment = QUOTED_FRAGMENT + TagAttributes = TAG_ATTRIBUTES + AnyStartingTag = ANY_STARTING_TAG + PartialTemplateParser = PARTIAL_TEMPLATE_PARSER + TemplateParser = TEMPLATE_PARSER + VariableParser = VARIABLE_PARSER class BlockBody - FullToken = FULL_TOKEN - ContentOfVariable = CONTENT_OF_VARIABLE + FullToken = FULL_TOKEN + ContentOfVariable = CONTENT_OF_VARIABLE WhitespaceOrNothing = WHITESPACE_OR_NOTHING - TAGSTART = TAG_START_STRING - VARSTART = VAR_START_STRING + TAGSTART = TAG_START_STRING + VARSTART = VAR_START_STRING end class Assign < Tag @@ -52,7 +52,7 @@ class For < Block end class If < Block - Syntax = SYNTAX + Syntax = SYNTAX ExpressionsAndOperators = EXPRESSIONS_AND_OPERATORS end @@ -61,7 +61,7 @@ class Include < Tag end class Raw < Block - Syntax = SYNTAX + Syntax = SYNTAX FullTokenPossiblyInvalid = FULL_TOKEN_POSSIBLY_INVALID end @@ -70,10 +70,10 @@ class TableRow < Block end class Variable - FilterMarkupRegex = FILTER_MARKUP_REGEX - FilterParser = FILTER_PARSER - FilterArgsRegex = FILTER_ARGS_REGEX - JustTagAttributes = JUST_TAG_ATTRIBUTES + FilterMarkupRegex = FILTER_MARKUP_REGEX + FilterParser = FILTER_PARSER + FilterArgsRegex = FILTER_ARGS_REGEX + JustTagAttributes = JUST_TAG_ATTRIBUTES MarkupWithQuotedFragment = MARKUP_WITH_QUOTED_FRAGMENT end end diff --git a/lib/liquid/lexer.rb b/lib/liquid/lexer.rb index 38cbe109c..a251c3e59 100644 --- a/lib/liquid/lexer.rb +++ b/lib/liquid/lexer.rb @@ -15,13 +15,12 @@ class Lexer '?' => :question, '-' => :dash, }.freeze - - IDENTIFIER = /[a-zA-Z_][\w-]*\??/ + IDENTIFIER = /[a-zA-Z_][\w-]*\??/ SINGLE_STRING_LITERAL = /'[^\']*'/ DOUBLE_STRING_LITERAL = /"[^\"]*"/ - NUMBER_LITERAL = /-?\d+(\.\d+)?/ - DOTDOT = /\.\./ - COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/ + NUMBER_LITERAL = /-?\d+(\.\d+)?/ + DOTDOT = /\.\./ + COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/ WHITESPACE_OR_NOTHING = /\s*/ def initialize(input) @@ -34,7 +33,7 @@ def tokenize until @ss.eos? @ss.skip(WHITESPACE_OR_NOTHING) break if @ss.eos? - tok = if (t = @ss.scan(COMPARISON_OPERATOR)) + tok = if (t = @ss.scan(COMPARISON_OPERATOR)) [:comparison, t] elsif (t = @ss.scan(SINGLE_STRING_LITERAL)) [:string, t] @@ -47,7 +46,7 @@ def tokenize elsif (t = @ss.scan(DOTDOT)) [:dotdot, t] else - c = @ss.getch + c = @ss.getch if (s = SPECIALS[c]) [s, c] else diff --git a/lib/liquid/parse_context.rb b/lib/liquid/parse_context.rb index cdf50f68d..4afdbe596 100644 --- a/lib/liquid/parse_context.rb +++ b/lib/liquid/parse_context.rb @@ -7,10 +7,10 @@ class ParseContext def initialize(options = {}) @template_options = options ? options.dup : {} - @locale = @template_options[:locale] ||= I18n.new - @warnings = [] - self.depth = 0 - self.partial = false + @locale = @template_options[:locale] ||= I18n.new + @warnings = [] + self.depth = 0 + self.partial = false end def [](option_key) @@ -18,8 +18,8 @@ def [](option_key) end def partial=(value) - @partial = value - @options = value ? partial_options : @template_options + @partial = value + @options = value ? partial_options : @template_options @error_mode = @options[:error_mode] || Template.error_mode end diff --git a/lib/liquid/parse_tree_visitor.rb b/lib/liquid/parse_tree_visitor.rb index 8f5d27f38..d50943f30 100644 --- a/lib/liquid/parse_tree_visitor.rb +++ b/lib/liquid/parse_tree_visitor.rb @@ -11,14 +11,14 @@ def self.for(node, callbacks = Hash.new(proc {})) end def initialize(node, callbacks) - @node = node + @node = node @callbacks = callbacks end def add_callback_for(*classes, &block) - callback = block - callback = ->(node, _) { yield node } if block.arity.abs == 1 - callback = ->(_, _) { yield } if block.arity.zero? + callback = block + callback = ->(node, _) { yield node } if block.arity.abs == 1 + callback = ->(_, _) { yield } if block.arity.zero? classes.each { |klass| @callbacks[klass] = callback } self end diff --git a/lib/liquid/parser.rb b/lib/liquid/parser.rb index b33423186..6b9e83748 100644 --- a/lib/liquid/parser.rb +++ b/lib/liquid/parser.rb @@ -3,9 +3,9 @@ module Liquid class Parser def initialize(input) - l = Lexer.new(input) + l = Lexer.new(input) @tokens = l.tokenize - @p = 0 # pointer to current location + @p = 0 # pointer to current location end def jump(point) @@ -14,7 +14,6 @@ def jump(point) def consume(type = nil) token = @tokens[@p] - if type && token[0] != type raise SyntaxError, "Expected #{type} but found #{@tokens[@p].first}" end @@ -27,7 +26,6 @@ def consume(type = nil) # or false otherwise. def consume?(type) token = @tokens[@p] - return false unless token && token[0] == type @p += 1 token[1] @@ -36,7 +34,6 @@ def consume?(type) # Like consume? Except for an :id token of a certain name def id?(str) token = @tokens[@p] - return false unless token && token[0] == :id return false unless token[1] == str @p += 1 @@ -62,7 +59,7 @@ def expression consume first = expression consume(:dotdot) - last = expression + last = expression consume(:close_round) "(#{first}..#{last})" else diff --git a/lib/liquid/parser_switching.rb b/lib/liquid/parser_switching.rb index e2f8546df..402b05663 100644 --- a/lib/liquid/parser_switching.rb +++ b/lib/liquid/parser_switching.rb @@ -21,7 +21,7 @@ def parse_with_selected_parser(markup) def strict_parse_with_error_context(markup) strict_parse(markup) rescue SyntaxError => e - e.line_number = line_number + e.line_number = line_number e.markup_context = markup_context(markup) raise e end diff --git a/lib/liquid/partial_cache.rb b/lib/liquid/partial_cache.rb index bc9aeb39d..43c2e39b7 100644 --- a/lib/liquid/partial_cache.rb +++ b/lib/liquid/partial_cache.rb @@ -4,14 +4,14 @@ module Liquid class PartialCache def self.load(template_name, context:, parse_context:) cached_partials = (context.registers[:cached_partials] ||= {}) - cached = cached_partials[template_name] + cached = cached_partials[template_name] return cached if cached - file_system = (context.registers[:file_system] ||= Liquid::Template.file_system) - source = file_system.read_template_file(template_name) + file_system = (context.registers[:file_system] ||= Liquid::Template.file_system) + source = file_system.read_template_file(template_name) parse_context.partial = true - partial = Liquid::Template.parse(source, parse_context) + partial = Liquid::Template.parse(source, parse_context) cached_partials[template_name] = partial ensure parse_context.partial = false diff --git a/lib/liquid/profiler.rb b/lib/liquid/profiler.rb index bec1842b1..dc3f1db61 100644 --- a/lib/liquid/profiler.rb +++ b/lib/liquid/profiler.rb @@ -101,21 +101,21 @@ def self.current_profile def initialize @partial_stack = [""] - @root_timing = Timing.new("", current_partial) + @root_timing = Timing.new("", current_partial) @timing_stack = [@root_timing] @render_start_at = Time.now - @render_end_at = @render_start_at + @render_end_at = @render_start_at end def start Thread.current[:liquid_profiler] = self - @render_start_at = Time.now + @render_start_at = Time.now end def stop Thread.current[:liquid_profiler] = nil - @render_end_at = Time.now + @render_end_at = Time.now end def total_render_time diff --git a/lib/liquid/range_lookup.rb b/lib/liquid/range_lookup.rb index 57bccd00b..8e4d76522 100644 --- a/lib/liquid/range_lookup.rb +++ b/lib/liquid/range_lookup.rb @@ -4,7 +4,7 @@ module Liquid class RangeLookup def self.parse(start_markup, end_markup) start_obj = Expression.parse(start_markup) - end_obj = Expression.parse(end_markup) + end_obj = Expression.parse(end_markup) if start_obj.respond_to?(:evaluate) || end_obj.respond_to?(:evaluate) new(start_obj, end_obj) else @@ -14,12 +14,12 @@ def self.parse(start_markup, end_markup) def initialize(start_obj, end_obj) @start_obj = start_obj - @end_obj = end_obj + @end_obj = end_obj end def evaluate(context) start_int = to_integer(context.evaluate(@start_obj)) - end_int = to_integer(context.evaluate(@end_obj)) + end_int = to_integer(context.evaluate(@end_obj)) start_int..end_int end diff --git a/lib/liquid/resource_limits.rb b/lib/liquid/resource_limits.rb index 9c898f003..5b7e8e463 100644 --- a/lib/liquid/resource_limits.rb +++ b/lib/liquid/resource_limits.rb @@ -7,8 +7,8 @@ class ResourceLimits def initialize(limits) @render_length_limit = limits[:render_length_limit] - @render_score_limit = limits[:render_score_limit] - @assign_score_limit = limits[:assign_score_limit] + @render_score_limit = limits[:render_score_limit] + @assign_score_limit = limits[:assign_score_limit] reset end diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index e245f97d9..6855cd212 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -12,14 +12,13 @@ module StandardFilters '"' => '"', "'" => ''', }.freeze - HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/ - STRIP_HTML_TAGS = /<.*?>/m - STRIP_HTML_BLOCKS = Regexp.union( + STRIP_HTML_BLOCKS = Regexp.union( %r{}m, //m, %r{}m ) + STRIP_HTML_TAGS = /<.*?>/m # Return the size of an array or of an string def size(input) @@ -77,20 +76,20 @@ def slice(input, offset, length = nil) # Truncate a string down to x characters def truncate(input, length = 50, truncate_string = "...") return if input.nil? - input_str = input.to_s - length = Utils.to_integer(length) + input_str = input.to_s + length = Utils.to_integer(length) truncate_string_str = truncate_string.to_s - l = length - truncate_string_str.length - l = 0 if l < 0 + l = length - truncate_string_str.length + l = 0 if l < 0 input_str.length > length ? input_str[0...l].concat(truncate_string_str) : input_str end def truncatewords(input, words = 15, truncate_string = "...") return if input.nil? wordlist = input.to_s.split - words = Utils.to_integer(words) - l = words - 1 - l = 0 if l < 0 + words = Utils.to_integer(words) + l = words - 1 + l = 0 if l < 0 wordlist.length > l ? wordlist[0..l].join(" ").concat(truncate_string.to_s) : input end @@ -116,7 +115,7 @@ def rstrip(input) end def strip_html(input) - empty = '' + empty = '' result = input.to_s.gsub(STRIP_HTML_BLOCKS, empty) result.gsub!(STRIP_HTML_TAGS, empty) result diff --git a/lib/liquid/static_registers.rb b/lib/liquid/static_registers.rb index da2c2c398..06c52ab01 100644 --- a/lib/liquid/static_registers.rb +++ b/lib/liquid/static_registers.rb @@ -5,7 +5,7 @@ class StaticRegisters attr_reader :static, :registers def initialize(registers = {}) - @static = registers.is_a?(StaticRegisters) ? registers.static : registers + @static = registers.is_a?(StaticRegisters) ? registers.static : registers @registers = {} end diff --git a/lib/liquid/strainer.rb b/lib/liquid/strainer.rb index d3c7433b2..3f3417e33 100644 --- a/lib/liquid/strainer.rb +++ b/lib/liquid/strainer.rb @@ -9,7 +9,7 @@ module Liquid # The Strainer only allows method calls defined in filters given to it via Strainer.global_filter, # Context#add_filters or Template.register_filter class Strainer #:nodoc: - @@global_strainer = Class.new(Strainer) do + @@global_strainer = Class.new(Strainer) do @filter_methods = Set.new end @@strainer_class_cache = Hash.new do |hash, filters| diff --git a/lib/liquid/tablerowloop_drop.rb b/lib/liquid/tablerowloop_drop.rb index 628705278..0d00b6f1a 100644 --- a/lib/liquid/tablerowloop_drop.rb +++ b/lib/liquid/tablerowloop_drop.rb @@ -4,10 +4,10 @@ module Liquid class TablerowloopDrop < Drop def initialize(length, cols) @length = length - @row = 1 - @col = 1 - @cols = cols - @index = 0 + @row = 1 + @col = 1 + @cols = cols + @index = 0 end attr_reader :length, :col, :row @@ -54,7 +54,7 @@ def increment! @index += 1 if @col == @cols - @col = 1 + @col = 1 @row += 1 else @col += 1 diff --git a/lib/liquid/tag.rb b/lib/liquid/tag.rb index 562472b93..14606391d 100644 --- a/lib/liquid/tag.rb +++ b/lib/liquid/tag.rb @@ -17,10 +17,10 @@ def parse(tag_name, markup, tokenizer, parse_context) end def initialize(tag_name, markup, parse_context) - @tag_name = tag_name - @markup = markup + @tag_name = tag_name + @markup = markup @parse_context = parse_context - @line_number = parse_context.line_number + @line_number = parse_context.line_number end def parse(_tokens) diff --git a/lib/liquid/tags/assign.rb b/lib/liquid/tags/assign.rb index e0d512378..332c605c8 100644 --- a/lib/liquid/tags/assign.rb +++ b/lib/liquid/tags/assign.rb @@ -21,7 +21,7 @@ def self.syntax_error_translation_key def initialize(tag_name, markup, options) super if markup =~ SYNTAX - @to = Regexp.last_match(1) + @to = Regexp.last_match(1) @from = Variable.new(Regexp.last_match(2), options) else raise SyntaxError, options[:locale].t(self.class.syntax_error_translation_key) @@ -29,8 +29,8 @@ def initialize(tag_name, markup, options) end def render_to_output_buffer(context, output) - val = @from.render(context) - context.scopes.last[@to] = val + val = @from.render(context) + context.scopes.last[@to] = val context.resource_limits.assign_score += assign_score_of(val) output end @@ -45,7 +45,7 @@ def assign_score_of(val) if val.instance_of?(String) val.bytesize elsif val.instance_of?(Array) || val.instance_of?(Hash) - sum = 1 + sum = 1 # Uses #each to avoid extra allocations. val.each { |child| sum += assign_score_of(child) } sum diff --git a/lib/liquid/tags/capture.rb b/lib/liquid/tags/capture.rb index ddfe09433..ee6e6d005 100644 --- a/lib/liquid/tags/capture.rb +++ b/lib/liquid/tags/capture.rb @@ -25,9 +25,9 @@ def initialize(tag_name, markup, options) end def render_to_output_buffer(context, output) - previous_output_size = output.bytesize + previous_output_size = output.bytesize super - context.scopes.last[@to] = output + context.scopes.last[@to] = output context.resource_limits.assign_score += (output.bytesize - previous_output_size) output end diff --git a/lib/liquid/tags/case.rb b/lib/liquid/tags/case.rb index c97a067ec..1f5196aeb 100644 --- a/lib/liquid/tags/case.rb +++ b/lib/liquid/tags/case.rb @@ -2,7 +2,7 @@ module Liquid class Case < Block - SYNTAX = /(#{QUOTED_FRAGMENT})/o + SYNTAX = /(#{QUOTED_FRAGMENT})/o WHEN_SYNTAX = /(#{QUOTED_FRAGMENT})(?:(?:\s+or\s+|\s*\,\s*)(#{QUOTED_FRAGMENT}.*))?/om attr_reader :blocks, :left diff --git a/lib/liquid/tags/cycle.rb b/lib/liquid/tags/cycle.rb index 9467f720f..d6c490df8 100644 --- a/lib/liquid/tags/cycle.rb +++ b/lib/liquid/tags/cycle.rb @@ -24,10 +24,10 @@ def initialize(tag_name, markup, options) case markup when NAMED_SYNTAX @variables = variables_from_string(Regexp.last_match(2)) - @name = Expression.parse(Regexp.last_match(1)) + @name = Expression.parse(Regexp.last_match(1)) when SIMPLE_SYNTAX @variables = variables_from_string(markup) - @name = @variables.to_s + @name = @variables.to_s else raise SyntaxError, options[:locale].t("errors.syntax.cycle") end @@ -36,7 +36,7 @@ def initialize(tag_name, markup, options) def render_to_output_buffer(context, output) context.registers[:cycle] ||= {} - key = context.evaluate(@name) + key = context.evaluate(@name) iteration = context.registers[:cycle][key].to_i val = context.evaluate(@variables[iteration]) @@ -49,8 +49,8 @@ def render_to_output_buffer(context, output) output << val - iteration += 1 - iteration = 0 if iteration >= @variables.size + iteration += 1 + iteration = 0 if iteration >= @variables.size context.registers[:cycle][key] = iteration output diff --git a/lib/liquid/tags/decrement.rb b/lib/liquid/tags/decrement.rb index 3ab7e420a..d761a0c3a 100644 --- a/lib/liquid/tags/decrement.rb +++ b/lib/liquid/tags/decrement.rb @@ -26,8 +26,8 @@ def initialize(tag_name, markup, options) end def render_to_output_buffer(context, output) - value = context.environments.first[@variable] ||= 0 - value -= 1 + value = context.environments.first[@variable] ||= 0 + value -= 1 context.environments.first[@variable] = value output << value.to_s output diff --git a/lib/liquid/tags/for.rb b/lib/liquid/tags/for.rb index 18c7e30ea..b63b9e136 100644 --- a/lib/liquid/tags/for.rb +++ b/lib/liquid/tags/for.rb @@ -52,9 +52,9 @@ class For < Block def initialize(tag_name, markup, options) super - @from = @limit = nil + @from = @limit = nil parse_with_selected_parser(markup) - @for_block = BlockBody.new + @for_block = BlockBody.new @else_block = nil end @@ -88,10 +88,10 @@ def render_to_output_buffer(context, output) def lax_parse(markup) if markup =~ SYNTAX - @variable_name = Regexp.last_match(1) - collection_name = Regexp.last_match(2) - @reversed = !!Regexp.last_match(3) - @name = "#{@variable_name}-#{collection_name}" + @variable_name = Regexp.last_match(1) + collection_name = Regexp.last_match(2) + @reversed = !!Regexp.last_match(3) + @name = "#{@variable_name}-#{collection_name}" @collection_name = Expression.parse(collection_name) markup.scan(TAG_ATTRIBUTES) do |key, value| set_attribute(key, value) @@ -102,13 +102,13 @@ def lax_parse(markup) end def strict_parse(markup) - p = Parser.new(markup) - @variable_name = p.consume(:id) + p = Parser.new(markup) + @variable_name = p.consume(:id) raise SyntaxError, options[:locale].t("errors.syntax.for_invalid_in") unless p.id?('in') - collection_name = p.expression - @name = "#{@variable_name}-#{collection_name}" + collection_name = p.expression + @name = "#{@variable_name}-#{collection_name}" @collection_name = Expression.parse(collection_name) - @reversed = p.id?('reversed') + @reversed = p.id?('reversed') while p.look(:id) && p.look(:colon, 1) unless (attribute = p.id?('limit') || p.id?('offset')) @@ -140,7 +140,7 @@ def collection_segment(context) collection = collection.to_a if collection.is_a?(Range) limit_value = context.evaluate(@limit) - to = if limit_value.nil? + to = if limit_value.nil? nil else Utils.to_integer(limit_value) + from @@ -156,7 +156,7 @@ def collection_segment(context) def render_segment(context, output, segment) for_stack = context.registers[:for_stack] ||= [] - length = segment.length + length = segment.length context.stack do loop_vars = Liquid::ForloopDrop.new(@name, length, for_stack[-1]) diff --git a/lib/liquid/tags/if.rb b/lib/liquid/tags/if.rb index a54a18d4b..50cb3341f 100644 --- a/lib/liquid/tags/if.rb +++ b/lib/liquid/tags/if.rb @@ -12,9 +12,9 @@ module Liquid # There are {% if count < 5 %} less {% else %} more {% endif %} items than you need. # class If < Block - SYNTAX = /(#{QUOTED_FRAGMENT})\s*([=!<>a-z_]+)?\s*(#{QUOTED_FRAGMENT})?/o + SYNTAX = /(#{QUOTED_FRAGMENT})\s*([=!<>a-z_]+)?\s*(#{QUOTED_FRAGMENT})?/o EXPRESSIONS_AND_OPERATORS = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QUOTED_FRAGMENT}|\S+)\s*)+)/o - BOOLEAN_OPERATORS = %w(and or).freeze + BOOLEAN_OPERATORS = %w(and or).freeze attr_reader :blocks @@ -78,32 +78,32 @@ def lax_parse(markup) new_condition = Condition.new(Expression.parse(Regexp.last_match(1)), Regexp.last_match(2), Expression.parse(Regexp.last_match(3))) raise SyntaxError, options[:locale].t("errors.syntax.if") unless BOOLEAN_OPERATORS.include?(operator) new_condition.send(operator, condition) - condition = new_condition + condition = new_condition end condition end def strict_parse(markup) - p = Parser.new(markup) + p = Parser.new(markup) condition = parse_binary_comparisons(p) p.consume(:end_of_string) condition end def parse_binary_comparisons(p) - condition = parse_comparison(p) + condition = parse_comparison(p) first_condition = condition - while (op = (p.id?('and') || p.id?('or'))) + while (op = (p.id?('and') || p.id?('or'))) child_condition = parse_comparison(p) condition.send(op, child_condition) - condition = child_condition + condition = child_condition end first_condition end def parse_comparison(p) - a = Expression.parse(p.expression) + a = Expression.parse(p.expression) if (op = p.consume?(:comparison)) b = Expression.parse(p.expression) Condition.new(a, op, b) diff --git a/lib/liquid/tags/include.rb b/lib/liquid/tags/include.rb index e2a3ff346..379c6c1d6 100644 --- a/lib/liquid/tags/include.rb +++ b/lib/liquid/tags/include.rb @@ -30,7 +30,7 @@ def initialize(tag_name, markup, options) @variable_name_expr = variable_name ? Expression.parse(variable_name) : nil @template_name_expr = Expression.parse(template_name) - @attributes = {} + @attributes = {} markup.scan(TAG_ATTRIBUTES) do |key, value| @attributes[key] = Expression.parse(value) @@ -63,10 +63,10 @@ def render_to_output_buffer(context, output) end old_template_name = context.template_name - old_partial = context.partial + old_partial = context.partial begin context.template_name = template_name - context.partial = true + context.partial = true context.stack do @attributes.each do |key, value| context[key] = context.evaluate(value) @@ -84,7 +84,7 @@ def render_to_output_buffer(context, output) end ensure context.template_name = old_template_name - context.partial = old_partial + context.partial = old_partial end output diff --git a/lib/liquid/tags/increment.rb b/lib/liquid/tags/increment.rb index 0290f6959..241b316b3 100644 --- a/lib/liquid/tags/increment.rb +++ b/lib/liquid/tags/increment.rb @@ -23,7 +23,7 @@ def initialize(tag_name, markup, options) end def render_to_output_buffer(context, output) - value = context.environments.first[@variable] ||= 0 + value = context.environments.first[@variable] ||= 0 context.environments.first[@variable] = value + 1 output << value.to_s diff --git a/lib/liquid/tags/raw.rb b/lib/liquid/tags/raw.rb index 5ba752c3d..e4b2a6a2e 100644 --- a/lib/liquid/tags/raw.rb +++ b/lib/liquid/tags/raw.rb @@ -2,7 +2,7 @@ module Liquid class Raw < Block - SYNTAX = /\A\s*\z/ + SYNTAX = /\A\s*\z/ FULL_TOKEN_POSSIBLY_INVALID = /\A(.*)#{TAG_START}\s*(\w+)\s*(.*)?#{TAG_END}\z/om def initialize(tag_name, markup, parse_context) @@ -12,7 +12,7 @@ def initialize(tag_name, markup, parse_context) end def parse(tokens) - @body = +'' + @body = +'' while (token = tokens.shift) if token =~ FULL_TOKEN_POSSIBLY_INVALID @body << Regexp.last_match(1) if Regexp.last_match(1) != "" diff --git a/lib/liquid/tags/render.rb b/lib/liquid/tags/render.rb index 179084fe3..0516d7da8 100644 --- a/lib/liquid/tags/render.rb +++ b/lib/liquid/tags/render.rb @@ -32,9 +32,9 @@ def render_to_output_buffer(context, output) parse_context: parse_context ) - inner_context = context.new_isolated_subcontext + inner_context = context.new_isolated_subcontext inner_context.template_name = template_name - inner_context.partial = true + inner_context.partial = true @attributes.each do |key, value| inner_context[key] = context.evaluate(value) end diff --git a/lib/liquid/tags/table_row.rb b/lib/liquid/tags/table_row.rb index f98bee513..ec5f9dbd0 100644 --- a/lib/liquid/tags/table_row.rb +++ b/lib/liquid/tags/table_row.rb @@ -9,9 +9,9 @@ class TableRow < Block def initialize(tag_name, markup, options) super if markup =~ SYNTAX - @variable_name = Regexp.last_match(1) + @variable_name = Regexp.last_match(1) @collection_name = Expression.parse(Regexp.last_match(2)) - @attributes = {} + @attributes = {} markup.scan(TAG_ATTRIBUTES) do |key, value| @attributes[key] = Expression.parse(value) end @@ -24,7 +24,7 @@ def render_to_output_buffer(context, output) (collection = context.evaluate(@collection_name)) || (return '') from = @attributes.key?('offset') ? context.evaluate(@attributes['offset']).to_i : 0 - to = @attributes.key?('limit') ? from + context.evaluate(@attributes['limit']).to_i : nil + to = @attributes.key?('limit') ? from + context.evaluate(@attributes['limit']).to_i : nil collection = Utils.slice_collection(collection, from, to) @@ -34,7 +34,7 @@ def render_to_output_buffer(context, output) output << "\n" context.stack do - tablerowloop = Liquid::TablerowloopDrop.new(length, cols) + tablerowloop = Liquid::TablerowloopDrop.new(length, cols) context['tablerowloop'] = tablerowloop collection.each do |item| diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index 0df70d0ac..e77ba8aac 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -24,7 +24,7 @@ class TagRegistry include Enumerable def initialize - @tags = {} + @tags = {} @cache = {} end @@ -120,19 +120,19 @@ def parse(source, options = {}) end def initialize - @rethrow_errors = false + @rethrow_errors = false @resource_limits = ResourceLimits.new(self.class.default_resource_limits) end # Parse source code. # Returns self for easy chaining def parse(source, options = {}) - @options = options - @profiling = options[:profile] + @options = options + @profiling = options[:profile] @line_numbers = options[:line_numbers] || @profiling parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options) - @root = Document.parse(tokenize(source), parse_context) - @warnings = parse_context.warnings + @root = Document.parse(tokenize(source), parse_context) + @warnings = parse_context.warnings self end @@ -179,7 +179,7 @@ def render(*args) c when Liquid::Drop - drop = args.shift + drop = args.shift drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits) when Hash Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits) @@ -194,7 +194,7 @@ def render(*args) case args.last when Hash options = args.pop - output = options[:output] if options[:output] + output = options[:output] if options[:output] registers.merge!(options[:registers]) if options[:registers].is_a?(Hash) @@ -253,10 +253,10 @@ def with_profiling(context) def apply_options_to_context(context, options) context.add_filters(options[:filters]) if options[:filters] - context.global_filter = options[:global_filter] if options[:global_filter] + context.global_filter = options[:global_filter] if options[:global_filter] context.exception_renderer = options[:exception_renderer] if options[:exception_renderer] - context.strict_variables = options[:strict_variables] if options[:strict_variables] - context.strict_filters = options[:strict_filters] if options[:strict_filters] + context.strict_variables = options[:strict_variables] if options[:strict_variables] + context.strict_filters = options[:strict_filters] if options[:strict_filters] end end end diff --git a/lib/liquid/tokenizer.rb b/lib/liquid/tokenizer.rb index 93edd1856..5bffb9a87 100644 --- a/lib/liquid/tokenizer.rb +++ b/lib/liquid/tokenizer.rb @@ -5,10 +5,10 @@ class Tokenizer attr_reader :line_number, :for_liquid_tag def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false) - @source = source - @line_number = line_number || (line_numbers ? 1 : nil) + @source = source + @line_number = line_number || (line_numbers ? 1 : nil) @for_liquid_tag = for_liquid_tag - @tokens = tokenize + @tokens = tokenize end def shift diff --git a/lib/liquid/utils.rb b/lib/liquid/utils.rb index 15a513ff7..709fb0026 100644 --- a/lib/liquid/utils.rb +++ b/lib/liquid/utils.rb @@ -12,7 +12,7 @@ def self.slice_collection(collection, from, to) def self.slice_collection_using_each(collection, from, to) segments = [] - index = 0 + index = 0 # Maintains Ruby 1.8.7 String#each behaviour on 1.9 if collection.is_a?(String) diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index 7bcd7246f..2ede9e8cb 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -12,10 +12,10 @@ module Liquid # {{ user | link }} # class Variable - FILTER_MARKUP_REGEX = /#{FILTER_SEPARATOR}\s*(.*)/om - FILTER_PARSER = /(?:\s+|#{QUOTED_FRAGMENT}|#{ARGUMENT_SEPARATOR})+/o - FILTER_ARGS_REGEX = /(?:#{FILTER_ARGUMENT_SEPARATOR}|#{ARGUMENT_SEPARATOR})\s*((?:\w+\s*\:\s*)?#{QUOTED_FRAGMENT})/o - JUST_TAG_ATTRIBUTES = /\A#{TAG_ATTRIBUTES}\z/o + FILTER_MARKUP_REGEX = /#{FILTER_SEPARATOR}\s*(.*)/om + FILTER_PARSER = /(?:\s+|#{QUOTED_FRAGMENT}|#{ARGUMENT_SEPARATOR})+/o + FILTER_ARGS_REGEX = /(?:#{FILTER_ARGUMENT_SEPARATOR}|#{ARGUMENT_SEPARATOR})\s*((?:\w+\s*\:\s*)?#{QUOTED_FRAGMENT})/o + JUST_TAG_ATTRIBUTES = /\A#{TAG_ATTRIBUTES}\z/o MARKUP_WITH_QUOTED_FRAGMENT = /(#{QUOTED_FRAGMENT})(.*)/om attr_accessor :filters, :name, :line_number @@ -25,10 +25,10 @@ class Variable include ParserSwitching def initialize(markup, parse_context) - @markup = markup - @name = nil + @markup = markup + @name = nil @parse_context = parse_context - @line_number = parse_context.line_number + @line_number = parse_context.line_number parse_with_selected_parser(markup) end @@ -45,9 +45,9 @@ def lax_parse(markup) @filters = [] return unless markup =~ MARKUP_WITH_QUOTED_FRAGMENT - name_markup = Regexp.last_match(1) + name_markup = Regexp.last_match(1) filter_markup = Regexp.last_match(2) - @name = Expression.parse(name_markup) + @name = Expression.parse(name_markup) if filter_markup =~ FILTER_MARKUP_REGEX filters = Regexp.last_match(1).scan(FILTER_PARSER) filters.each do |f| @@ -61,7 +61,7 @@ def lax_parse(markup) def strict_parse(markup) @filters = [] - p = Parser.new(markup) + p = Parser.new(markup) @name = Expression.parse(p.expression) while p.consume?(:pipe) @@ -107,17 +107,17 @@ def render_to_output_buffer(context, output) private def parse_filter_expressions(filter_name, unparsed_args) - filter_args = [] + filter_args = [] keyword_args = nil unparsed_args.each do |a| if (matches = a.match(JUST_TAG_ATTRIBUTES)) - keyword_args ||= {} + keyword_args ||= {} keyword_args[matches[1]] = Expression.parse(matches[2]) else filter_args << Expression.parse(a) end end - result = [filter_name, filter_args] + result = [filter_name, filter_args] result << keyword_args if keyword_args result end @@ -141,8 +141,8 @@ def taint_check(context, obj) @markup =~ QUOTED_FRAGMENT name = Regexp.last_match(0) - error = TaintedError.new("variable '#{name}' is tainted and was not escaped") - error.line_number = line_number + error = TaintedError.new("variable '#{name}' is tainted and was not escaped") + error.line_number = line_number error.template_name = context.template_name case Template.taint_mode diff --git a/lib/liquid/variable_lookup.rb b/lib/liquid/variable_lookup.rb index fb2acc679..c96a5233b 100644 --- a/lib/liquid/variable_lookup.rb +++ b/lib/liquid/variable_lookup.rb @@ -3,7 +3,7 @@ module Liquid class VariableLookup SQUARE_BRACKETED = /\A\[(.*)\]\z/m - COMMAND_METHODS = ['size', 'first', 'last'].freeze + COMMAND_METHODS = ['size', 'first', 'last'].freeze attr_reader :name, :lookups @@ -14,13 +14,13 @@ def self.parse(markup) def initialize(markup) lookups = markup.scan(VARIABLE_PARSER) - name = lookups.shift + name = lookups.shift if name =~ SQUARE_BRACKETED name = Expression.parse(Regexp.last_match(1)) end @name = name - @lookups = lookups + @lookups = lookups @command_flags = 0 @lookups.each_index do |i| @@ -34,7 +34,7 @@ def initialize(markup) end def evaluate(context) - name = context.evaluate(@name) + name = context.evaluate(@name) object = context.find_variable(name) @lookups.each_index do |i| @@ -47,7 +47,7 @@ def evaluate(context) (object.respond_to?(:fetch) && key.is_a?(Integer))) # if its a proc we will replace the entry with the proc - res = context.lookup_and_evaluate(object, key) + res = context.lookup_and_evaluate(object, key) object = res.to_liquid # Some special cases. If the part wasn't in square brackets and diff --git a/performance/benchmark.rb b/performance/benchmark.rb index 993cc933e..4d28b9acf 100644 --- a/performance/benchmark.rb +++ b/performance/benchmark.rb @@ -4,10 +4,10 @@ require_relative 'theme_runner' Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first -profiler = ThemeRunner.new +profiler = ThemeRunner.new Benchmark.ips do |x| - x.time = 10 + x.time = 10 x.warmup = 5 puts diff --git a/performance/profile.rb b/performance/profile.rb index de4ee2aac..70740778d 100644 --- a/performance/profile.rb +++ b/performance/profile.rb @@ -4,7 +4,7 @@ require_relative 'theme_runner' Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first -profiler = ThemeRunner.new +profiler = ThemeRunner.new profiler.run [:cpu, :object].each do |profile_type| diff --git a/performance/shopify/comment_form.rb b/performance/shopify/comment_form.rb index cb09d0e7e..0dabc4bde 100644 --- a/performance/shopify/comment_form.rb +++ b/performance/shopify/comment_form.rb @@ -8,7 +8,7 @@ def initialize(tag_name, markup, options) if markup =~ SYNTAX @variable_name = Regexp.last_match(1) - @attributes = {} + @attributes = {} else raise SyntaxError, "Syntax Error in 'comment_form' - Valid syntax: comment_form [article]" end diff --git a/performance/shopify/database.rb b/performance/shopify/database.rb index 35a403807..2db6d300c 100644 --- a/performance/shopify/database.rb +++ b/performance/shopify/database.rb @@ -11,7 +11,7 @@ def self.tables # From vision source db['products'].each do |product| - collections = db['collections'].find_all do |collection| + collections = db['collections'].find_all do |collection| collection['products'].any? { |p| p['id'].to_i == product['id'].to_i } end product['collections'] = collections diff --git a/performance/shopify/paginate.rb b/performance/shopify/paginate.rb index acd7036af..07f3cfced 100644 --- a/performance/shopify/paginate.rb +++ b/performance/shopify/paginate.rb @@ -8,7 +8,7 @@ def initialize(tag_name, markup, options) if markup =~ SYNTAX @collection_name = Regexp.last_match(1) - @page_size = if Regexp.last_match(2) + @page_size = if Regexp.last_match(2) Regexp.last_match(3).to_i else 20 diff --git a/performance/theme_runner.rb b/performance/theme_runner.rb index d8d093661..5ad01c554 100644 --- a/performance/theme_runner.rb +++ b/performance/theme_runner.rb @@ -58,9 +58,9 @@ def run # `render` is called to benchmark just the render portion of liquid def render @compiled_tests.each do |test| - tmpl = test[:tmpl] + tmpl = test[:tmpl] assigns = test[:assigns] - layout = test[:layout] + layout = test[:layout] if layout assigns['content_for_layout'] = tmpl.render!(assigns) @@ -74,7 +74,7 @@ def render private def compile_and_render(template, layout, assigns, page_template, template_file) - compiled_test = compile_test(template, layout, assigns, page_template, template_file) + compiled_test = compile_test(template, layout, assigns, page_template, template_file) assigns['content_for_layout'] = compiled_test[:tmpl].render!(assigns) compiled_test[:layout].render!(assigns) if layout end @@ -88,7 +88,7 @@ def compile_all_tests end def compile_test(template, layout, assigns, page_template, template_file) - tmpl = init_template(page_template, template_file) + tmpl = init_template(page_template, template_file) parsed_template = tmpl.parse(template).dup if layout @@ -113,9 +113,9 @@ def each_test # set up a new Liquid::Template object for use in `compile_and_render` and `compile_test` def init_template(page_template, template_file) - tmpl = Liquid::Template.new - tmpl.assigns['page_title'] = 'Page title' - tmpl.assigns['template'] = page_template + tmpl = Liquid::Template.new + tmpl.assigns['page_title'] = 'Page title' + tmpl.assigns['template'] = page_template tmpl.registers[:file_system] = ThemeRunner::FileSystem.new(File.dirname(template_file)) tmpl end diff --git a/test/integration/assign_test.rb b/test/integration/assign_test.rb index ce86c7a9e..ffcb8a3f0 100644 --- a/test/integration/assign_test.rb +++ b/test/integration/assign_test.rb @@ -10,8 +10,8 @@ def test_assign_with_hyphen_in_variable_name {% assign this-thing = 'Print this-thing' %} {{ this-thing }} END_TEMPLATE - template = Template.parse(template_source) - rendered = template.render! + template = Template.parse(template_source) + rendered = template.render! assert_equal "Print this-thing", rendered.strip end diff --git a/test/integration/capture_test.rb b/test/integration/capture_test.rb index 6743cd838..f28e1b1b3 100644 --- a/test/integration/capture_test.rb +++ b/test/integration/capture_test.rb @@ -14,8 +14,8 @@ def test_capture_with_hyphen_in_variable_name {% capture this-thing %}Print this-thing{% endcapture %} {{ this-thing }} END_TEMPLATE - template = Template.parse(template_source) - rendered = template.render! + template = Template.parse(template_source) + rendered = template.render! assert_equal "Print this-thing", rendered.strip end @@ -30,8 +30,8 @@ def test_capture_to_variable_from_outer_scope_if_existing {% endif %} {{var}} END_TEMPLATE - template = Template.parse(template_source) - rendered = template.render! + template = Template.parse(template_source) + rendered = template.render! assert_equal "test-string", rendered.gsub(/\s/, '') end @@ -45,8 +45,8 @@ def test_assigning_from_capture {% endfor %} {{ first }}-{{ second }} END_TEMPLATE - template = Template.parse(template_source) - rendered = template.render! + template = Template.parse(template_source) + rendered = template.render! assert_equal "3-3", rendered.gsub(/\s/, '') end end # CaptureTest diff --git a/test/integration/drop_test.rb b/test/integration/drop_test.rb index 34702d415..3fe61750d 100644 --- a/test/integration/drop_test.rb +++ b/test/integration/drop_test.rb @@ -125,7 +125,7 @@ def test_rendering_raises_on_tainted_attr def test_rendering_warns_on_tainted_attr with_taint_mode(:warn) do - tpl = Liquid::Template.parse('{{ product.user_input }}') + tpl = Liquid::Template.parse('{{ product.user_input }}') context = Context.new('product' => ProductDrop.new) tpl.render!(context) assert_equal [Liquid::TaintedError], context.warnings.map(&:class) diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index 9f7d92023..7abaec040 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -209,13 +209,13 @@ def test_default_exception_renderer_with_internal_error end def test_setting_default_exception_renderer - old_exception_renderer = Liquid::Template.default_exception_renderer - exceptions = [] + old_exception_renderer = Liquid::Template.default_exception_renderer + exceptions = [] Liquid::Template.default_exception_renderer = ->(e) { exceptions << e '' } - template = Liquid::Template.parse('This is a runtime error: {{ errors.argument_error }}') + template = Liquid::Template.parse('This is a runtime error: {{ errors.argument_error }}') output = template.render('errors' => ErrorDrop.new) @@ -226,9 +226,9 @@ def test_setting_default_exception_renderer end def test_exception_renderer_exposing_non_liquid_error - template = Liquid::Template.parse('This is a runtime error: {{ errors.runtime_error }}', line_numbers: true) + template = Liquid::Template.parse('This is a runtime error: {{ errors.runtime_error }}', line_numbers: true) exceptions = [] - handler = ->(e) { + handler = ->(e) { exceptions << e e.cause } @@ -252,8 +252,8 @@ def test_included_template_name_with_line_numbers begin Liquid::Template.file_system = TestFileSystem.new - template = Liquid::Template.parse("Argument error:\n{% include 'product' %}", line_numbers: true) - page = template.render('errors' => ErrorDrop.new) + template = Liquid::Template.parse("Argument error:\n{% include 'product' %}", line_numbers: true) + page = template.render('errors' => ErrorDrop.new) ensure Liquid::Template.file_system = old_file_system end diff --git a/test/integration/filter_test.rb b/test/integration/filter_test.rb index 976c34bbe..270477e68 100644 --- a/test/integration/filter_test.rb +++ b/test/integration/filter_test.rb @@ -72,10 +72,10 @@ def test_join end def test_sort - @context['value'] = 3 - @context['numbers'] = [2, 1, 4, 3] - @context['words'] = ['expected', 'as', 'alphabetic'] - @context['arrays'] = ['flower', 'are'] + @context['value'] = 3 + @context['numbers'] = [2, 1, 4, 3] + @context['words'] = ['expected', 'as', 'alphabetic'] + @context['arrays'] = ['flower', 'are'] @context['case_sensitive'] = ['sensitive', 'Expected', 'case'] assert_equal '1 2 3 4', Template.parse("{{numbers | sort | join}}").render(@context) @@ -86,8 +86,8 @@ def test_sort end def test_sort_natural - @context['words'] = ['case', 'Assert', 'Insensitive'] - @context['hashes'] = [{ 'a' => 'A' }, { 'a' => 'b' }, { 'a' => 'C' }] + @context['words'] = ['case', 'Assert', 'Insensitive'] + @context['hashes'] = [{ 'a' => 'A' }, { 'a' => 'b' }, { 'a' => 'C' }] @context['objects'] = [TestObject.new('A'), TestObject.new('b'), TestObject.new('C')] # Test strings @@ -101,8 +101,8 @@ def test_sort_natural end def test_compact - @context['words'] = ['a', nil, 'b', nil, 'c'] - @context['hashes'] = [{ 'a' => 'A' }, { 'a' => nil }, { 'a' => 'C' }] + @context['words'] = ['a', nil, 'b', nil, 'c'] + @context['hashes'] = [{ 'a' => 'A' }, { 'a' => nil }, { 'a' => 'C' }] @context['objects'] = [TestObject.new('A'), TestObject.new(nil), TestObject.new('C')] # Test strings @@ -141,9 +141,9 @@ def test_nonexistent_filter_is_ignored def test_filter_with_keyword_arguments @context['surname'] = 'john' - @context['input'] = 'hello %{first_name}, %{last_name}' + @context['input'] = 'hello %{first_name}, %{last_name}' @context.add_filters(SubstituteFilter) - output = Template.parse(%({{ input | substitute: first_name: surname, last_name: 'doe' }})).render(@context) + output = Template.parse(%({{ input | substitute: first_name: surname, last_name: 'doe' }})).render(@context) assert_equal 'hello john, doe', output end diff --git a/test/integration/output_test.rb b/test/integration/output_test.rb index 05f9bb1d6..687cad873 100644 --- a/test/integration/output_test.rb +++ b/test/integration/output_test.rb @@ -61,63 +61,63 @@ def test_variable_traversing end def test_variable_piping - text = %( {{ car.gm | make_funny }} ) + text = %( {{ car.gm | make_funny }} ) expected = %( LOL ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_variable_piping_with_input - text = %( {{ car.gm | cite_funny }} ) + text = %( {{ car.gm | cite_funny }} ) expected = %( LOL: bad ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_variable_piping_with_args - text = %! {{ car.gm | add_smiley : ':-(' }} ! + text = %! {{ car.gm | add_smiley : ':-(' }} ! expected = %| bad :-( | assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_variable_piping_with_no_args - text = %( {{ car.gm | add_smiley }} ) + text = %( {{ car.gm | add_smiley }} ) expected = %| bad :-) | assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_multiple_variable_piping_with_args - text = %! {{ car.gm | add_smiley : ':-(' | add_smiley : ':-('}} ! + text = %! {{ car.gm | add_smiley : ':-(' | add_smiley : ':-('}} ! expected = %| bad :-( :-( | assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_variable_piping_with_multiple_args - text = %( {{ car.gm | add_tag : 'span', 'bar'}} ) + text = %( {{ car.gm | add_tag : 'span', 'bar'}} ) expected = %( bad ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_variable_piping_with_variable_args - text = %( {{ car.gm | add_tag : 'span', car.bmw}} ) + text = %( {{ car.gm | add_tag : 'span', car.bmw}} ) expected = %( bad ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_multiple_pipings - text = %( {{ best_cars | cite_funny | paragraph }} ) + text = %( {{ best_cars | cite_funny | paragraph }} ) expected = %(

LOL: bmw

) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) end def test_link_to - text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} ) + text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} ) expected = %( Typo ) assert_equal expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]) diff --git a/test/integration/parsing_quirks_test.rb b/test/integration/parsing_quirks_test.rb index 58ca3f347..c210b486b 100644 --- a/test/integration/parsing_quirks_test.rb +++ b/test/integration/parsing_quirks_test.rb @@ -72,7 +72,7 @@ def test_no_error_on_lax_empty_filter def test_meaningless_parens_lax with_error_mode(:lax) do assigns = { 'b' => 'bar', 'c' => 'baz' } - markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" + markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false" assert_template_result(' YES ', "{% if #{markup} %} YES {% endif %}", assigns) end end diff --git a/test/integration/security_test.rb b/test/integration/security_test.rb index dec33df36..28e9d3928 100644 --- a/test/integration/security_test.rb +++ b/test/integration/security_test.rb @@ -16,28 +16,28 @@ def setup end def test_no_instance_eval - text = %( {{ '1+1' | instance_eval }} ) + text = %( {{ '1+1' | instance_eval }} ) expected = %( 1+1 ) assert_equal expected, Template.parse(text).render!(@assigns) end def test_no_existing_instance_eval - text = %( {{ '1+1' | __instance_eval__ }} ) + text = %( {{ '1+1' | __instance_eval__ }} ) expected = %( 1+1 ) assert_equal expected, Template.parse(text).render!(@assigns) end def test_no_instance_eval_after_mixing_in_new_filter - text = %( {{ '1+1' | instance_eval }} ) + text = %( {{ '1+1' | instance_eval }} ) expected = %( 1+1 ) assert_equal expected, Template.parse(text).render!(@assigns) end def test_no_instance_eval_later_in_chain - text = %( {{ '1+1' | add_one | instance_eval }} ) + text = %( {{ '1+1' | add_one | instance_eval }} ) expected = %( 1+1 + 1 ) assert_equal expected, Template.parse(text).render!(@assigns, filters: SecurityFilter) @@ -68,13 +68,13 @@ def test_does_not_add_drop_methods_to_symbol_table def test_max_depth_nested_blocks_does_not_raise_exception depth = Liquid::Block::MAX_DEPTH - code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth + code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth assert_equal "rendered", Template.parse(code).render! end def test_more_than_max_depth_nested_blocks_raises_exception depth = Liquid::Block::MAX_DEPTH + 1 - code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth + code = "{% if true %}" * depth + "rendered" + "{% endif %}" * depth assert_raises(Liquid::StackLevelError) do Template.parse(code).render! end diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index 7a4bf835a..bf285399e 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -204,7 +204,7 @@ def test_sort_with_nils end def test_sort_when_property_is_sometimes_missing_puts_nils_last - input = [ + input = [ { "price" => 4, "handle" => "alpha" }, { "handle" => "beta" }, { "price" => 1, "handle" => "gamma" }, @@ -232,7 +232,7 @@ def test_sort_natural_with_nils end def test_sort_natural_when_property_is_sometimes_missing_puts_nils_last - input = [ + input = [ { "price" => "4", "handle" => "alpha" }, { "handle" => "beta" }, { "price" => "1", "handle" => "gamma" }, @@ -250,7 +250,7 @@ def test_sort_natural_when_property_is_sometimes_missing_puts_nils_last end def test_sort_natural_case_check - input = [ + input = [ { "key" => "X" }, { "key" => "Y" }, { "key" => "Z" }, @@ -386,7 +386,7 @@ def test_map_on_hashes def test_legacy_map_on_hashes_with_dynamic_key template = "{% assign key = 'foo' %}{{ thing | map: key | map: 'bar' }}" - hash = { "foo" => { "bar" => 42 } } + hash = { "foo" => { "bar" => 42 } } assert_template_result "42", template, "thing" => hash end @@ -397,8 +397,8 @@ def test_sort_calls_to_liquid end def test_map_over_proc - drop = TestDrop.new - p = proc { drop } + drop = TestDrop.new + p = proc { drop } templ = '{{ procs | map: "test" }}' assert_template_result "testfoo", templ, "procs" => [p] end @@ -768,7 +768,7 @@ def test_where_no_target_value private def with_timezone(tz) - old_tz = ENV['TZ'] + old_tz = ENV['TZ'] ENV['TZ'] = tz yield ensure diff --git a/test/integration/tags/break_tag_test.rb b/test/integration/tags/break_tag_test.rb index a67a8b535..c3a467918 100644 --- a/test/integration/tags/break_tag_test.rb +++ b/test/integration/tags/break_tag_test.rb @@ -8,8 +8,8 @@ class BreakTagTest < Minitest::Test # tests that no weird errors are raised if break is called outside of a # block def test_break_with_no_block - assigns = { 'i' => 1 } - markup = '{% break %}' + assigns = { 'i' => 1 } + markup = '{% break %}' expected = '' assert_template_result(expected, markup, assigns) diff --git a/test/integration/tags/continue_tag_test.rb b/test/integration/tags/continue_tag_test.rb index 0530a718f..00cca17c1 100644 --- a/test/integration/tags/continue_tag_test.rb +++ b/test/integration/tags/continue_tag_test.rb @@ -8,8 +8,8 @@ class ContinueTagTest < Minitest::Test # tests that no weird errors are raised if continue is called outside of a # block def test_continue_with_no_block - assigns = {} - markup = '{% continue %}' + assigns = {} + markup = '{% continue %}' expected = '' assert_template_result(expected, markup, assigns) diff --git a/test/integration/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb index 0377fcf2c..667efac0c 100644 --- a/test/integration/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -106,7 +106,7 @@ def test_limiting end def test_limiting_with_invalid_limit - assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } + assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } template = <<-MKUP {% for i in array limit: true offset: 1 %} {{ i }} @@ -120,7 +120,7 @@ def test_limiting_with_invalid_limit end def test_limiting_with_invalid_offset - assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } + assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } template = <<-MKUP {% for i in array limit: 1 offset: true %} {{ i }} @@ -134,8 +134,8 @@ def test_limiting_with_invalid_offset end def test_dynamic_variable_limiting - assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } - assigns['limit'] = 2 + assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } + assigns['limit'] = 2 assigns['offset'] = 2 assert_template_result('34', '{%for i in array limit: limit offset: offset %}{{ i }}{%endfor%}', assigns) @@ -152,8 +152,8 @@ def test_offset_only end def test_pause_resume - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = <<-MKUP + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = <<-MKUP {%for i in array.items limit: 3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit: 3 %}{{i}}{%endfor%} @@ -171,8 +171,8 @@ def test_pause_resume end def test_pause_resume_limit - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = <<-MKUP + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = <<-MKUP {%for i in array.items limit:3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%} @@ -190,8 +190,8 @@ def test_pause_resume_limit end def test_pause_resume_big_limit - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = <<-MKUP + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = <<-MKUP {%for i in array.items limit:3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%} @@ -209,8 +209,8 @@ def test_pause_resume_big_limit end def test_pause_resume_big_offset - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } - markup = '{%for i in array.items limit:3 %}{{i}}{%endfor%} + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } } + markup = '{%for i in array.items limit:3 %}{{i}}{%endfor%} next {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%} next @@ -226,26 +226,26 @@ def test_pause_resume_big_offset def test_for_with_break assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } } - markup = '{% for i in array.items %}{% break %}{% endfor %}' + markup = '{% for i in array.items %}{% break %}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{{ i }}{% break %}{% endfor %}' + markup = '{% for i in array.items %}{{ i }}{% break %}{% endfor %}' expected = "1" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% break %}{{ i }}{% endfor %}' + markup = '{% for i in array.items %}{% break %}{{ i }}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{{ i }}{% if i > 3 %}{% break %}{% endif %}{% endfor %}' + markup = '{% for i in array.items %}{{ i }}{% if i > 3 %}{% break %}{% endif %}{% endfor %}' expected = "1234" assert_template_result(expected, markup, assigns) # tests to ensure it only breaks out of the local for loop # and not all of them. - assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } - markup = '{% for item in array %}' \ + assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } + markup = '{% for item in array %}' \ '{% for i in item %}' \ '{% if i == 1 %}' \ '{% break %}' \ @@ -257,8 +257,8 @@ def test_for_with_break assert_template_result(expected, markup, assigns) # test break does nothing when unreached - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } - markup = '{% for i in array.items %}{% if i == 9999 %}{% break %}{% endif %}{{ i }}{% endfor %}' + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } + markup = '{% for i in array.items %}{% if i == 9999 %}{% break %}{% endif %}{{ i }}{% endfor %}' expected = '12345' assert_template_result(expected, markup, assigns) end @@ -266,29 +266,29 @@ def test_for_with_break def test_for_with_continue assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } - markup = '{% for i in array.items %}{% continue %}{% endfor %}' + markup = '{% for i in array.items %}{% continue %}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{{ i }}{% continue %}{% endfor %}' + markup = '{% for i in array.items %}{{ i }}{% continue %}{% endfor %}' expected = "12345" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% continue %}{{ i }}{% endfor %}' + markup = '{% for i in array.items %}{% continue %}{{ i }}{% endfor %}' expected = "" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% if i > 3 %}{% continue %}{% endif %}{{ i }}{% endfor %}' + markup = '{% for i in array.items %}{% if i > 3 %}{% continue %}{% endif %}{{ i }}{% endfor %}' expected = "123" assert_template_result(expected, markup, assigns) - markup = '{% for i in array.items %}{% if i == 3 %}{% continue %}{% else %}{{ i }}{% endif %}{% endfor %}' + markup = '{% for i in array.items %}{% if i == 3 %}{% continue %}{% else %}{{ i }}{% endif %}{% endfor %}' expected = "1245" assert_template_result(expected, markup, assigns) # tests to ensure it only continues the local for loop and not all of them. - assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } - markup = '{% for item in array %}' \ + assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] } + markup = '{% for item in array %}' \ '{% for i in item %}' \ '{% if i == 1 %}' \ '{% continue %}' \ @@ -300,8 +300,8 @@ def test_for_with_continue assert_template_result(expected, markup, assigns) # test continue does nothing when unreached - assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } - markup = '{% for i in array.items %}{% if i == 9999 %}{% continue %}{% endif %}{{ i }}{% endfor %}' + assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } } + markup = '{% for i in array.items %}{% if i == 9999 %}{% continue %}{% endif %}{{ i }}{% endfor %}' expected = '12345' assert_template_result(expected, markup, assigns) end @@ -389,8 +389,8 @@ def load_slice(from, to) end def test_iterate_with_each_when_no_limit_applied - loader = LoaderDrop.new([1, 2, 3, 4, 5]) - assigns = { 'items' => loader } + loader = LoaderDrop.new([1, 2, 3, 4, 5]) + assigns = { 'items' => loader } expected = '12345' template = '{% for item in items %}{{item}}{% endfor %}' assert_template_result(expected, template, assigns) @@ -399,8 +399,8 @@ def test_iterate_with_each_when_no_limit_applied end def test_iterate_with_load_slice_when_limit_applied - loader = LoaderDrop.new([1, 2, 3, 4, 5]) - assigns = { 'items' => loader } + loader = LoaderDrop.new([1, 2, 3, 4, 5]) + assigns = { 'items' => loader } expected = '1' template = '{% for item in items limit:1 %}{{item}}{% endfor %}' assert_template_result(expected, template, assigns) @@ -409,8 +409,8 @@ def test_iterate_with_load_slice_when_limit_applied end def test_iterate_with_load_slice_when_limit_and_offset_applied - loader = LoaderDrop.new([1, 2, 3, 4, 5]) - assigns = { 'items' => loader } + loader = LoaderDrop.new([1, 2, 3, 4, 5]) + assigns = { 'items' => loader } expected = '34' template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}' assert_template_result(expected, template, assigns) @@ -419,11 +419,11 @@ def test_iterate_with_load_slice_when_limit_and_offset_applied end def test_iterate_with_load_slice_returns_same_results_as_without - loader = LoaderDrop.new([1, 2, 3, 4, 5]) + loader = LoaderDrop.new([1, 2, 3, 4, 5]) loader_assigns = { 'items' => loader } - array_assigns = { 'items' => [1, 2, 3, 4, 5] } - expected = '34' - template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}' + array_assigns = { 'items' => [1, 2, 3, 4, 5] } + expected = '34' + template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}' assert_template_result(expected, template, loader_assigns) assert_template_result(expected, template, array_assigns) end diff --git a/test/integration/tags/if_else_tag_test.rb b/test/integration/tags/if_else_tag_test.rb index dfbc537d6..d54b2fb8d 100644 --- a/test/integration/tags/if_else_tag_test.rb +++ b/test/integration/tags/if_else_tag_test.rb @@ -45,7 +45,7 @@ def test_if_or_with_operators def test_comparison_of_strings_containing_and_or_or awful_markup = "a == 'and' and b == 'or' and c == 'foo and bar' and d == 'bar or baz' and e == 'foo' and foo and bar" - assigns = { 'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true } + assigns = { 'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true } assert_template_result(' YES ', "{% if #{awful_markup} %} YES {% endif %}", assigns) end @@ -142,7 +142,7 @@ def test_syntax_error_no_expression end def test_if_with_custom_condition - original_op = Condition.operators['contains'] + original_op = Condition.operators['contains'] Condition.operators['contains'] = :[] assert_template_result('yes', %({% if 'bob' contains 'o' %}yes{% endif %})) @@ -152,7 +152,7 @@ def test_if_with_custom_condition end def test_operators_are_ignored_unless_isolated - original_op = Condition.operators['contains'] + original_op = Condition.operators['contains'] Condition.operators['contains'] = :[] assert_template_result('yes', diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index ef9608188..686d482e3 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -51,7 +51,7 @@ class CountingFileSystem attr_reader :count def read_template_file(_template_path) @count ||= 0 - @count += 1 + @count += 1 'from CountingFileSystem' end end @@ -179,7 +179,7 @@ def test_include_tag_within_if_statement end def test_custom_include_tag - original_tag = Liquid::Template.tags['include'] + original_tag = Liquid::Template.tags['include'] Liquid::Template.tags['include'] = CustomInclude begin assert_equal "custom_foo", @@ -190,7 +190,7 @@ def test_custom_include_tag end def test_custom_include_tag_within_if_statement - original_tag = Liquid::Template.tags['include'] + original_tag = Liquid::Template.tags['include'] Liquid::Template.tags['include'] = CustomInclude begin assert_equal "custom_foo_if_true", diff --git a/test/integration/tags/render_tag_test.rb b/test/integration/tags/render_tag_test.rb index 656ec8e55..154783ad3 100644 --- a/test/integration/tags/render_tag_test.rb +++ b/test/integration/tags/render_tag_test.rb @@ -47,7 +47,7 @@ def test_render_sets_the_correct_template_name_for_errors with_taint_mode :error do template = Liquid::Template.parse('{% render "snippet", unsafe: unsafe %}') - context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) + context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) template.render(context) assert_equal [Liquid::TaintedError], template.errors.map(&:class) @@ -60,7 +60,7 @@ def test_render_sets_the_correct_template_name_for_warnings with_taint_mode :warn do template = Liquid::Template.parse('{% render "snippet", unsafe: unsafe %}') - context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) + context = Context.new('unsafe' => (+'unsafe').tap(&:taint)) template.render(context) assert_equal [Liquid::TaintedError], context.warnings.map(&:class) diff --git a/test/integration/tags/standard_tag_test.rb b/test/integration/tags/standard_tag_test.rb index 72b5a3730..7939cd36a 100644 --- a/test/integration/tags/standard_tag_test.rb +++ b/test/integration/tags/standard_tag_test.rb @@ -174,7 +174,7 @@ def test_case_on_length_with_else def test_assign_from_case # Example from the shopify forums - code = "{% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }}" + code = "{% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }}" template = Liquid::Template.parse(code) assert_equal "menswear", template.render!("collection" => { 'handle' => 'menswear-jackets' }) assert_equal "menswear", template.render!("collection" => { 'handle' => 'menswear-t-shirts' }) diff --git a/test/integration/template_test.rb b/test/integration/template_test.rb index 9f21d39d6..48549f55a 100644 --- a/test/integration/template_test.rb +++ b/test/integration/template_test.rb @@ -73,29 +73,29 @@ def test_custom_assigns_squash_instance_assigns end def test_persistent_assigns_squash_instance_assigns - t = Template.new + t = Template.new assert_equal 'from instance assigns', t.parse("{% assign foo = 'from instance assigns' %}{{ foo }}").render! t.assigns['foo'] = 'from persistent assigns' assert_equal 'from persistent assigns', t.parse("{{ foo }}").render! end def test_lambda_is_called_once_from_persistent_assigns_over_multiple_parses_and_renders - t = Template.new + t = Template.new t.assigns['number'] = -> { @global ||= 0 - @global += 1 + @global += 1 } assert_equal '1', t.parse("{{number}}").render! assert_equal '1', t.parse("{{number}}").render! assert_equal '1', t.render! - @global = nil + @global = nil end def test_lambda_is_called_once_from_custom_assigns_over_multiple_parses_and_renders - t = Template.new + t = Template.new assigns = { 'number' => -> { @global ||= 0 - @global += 1 + @global += 1 } } assert_equal '1', t.parse("{{number}}").render!(assigns) assert_equal '1', t.parse("{{number}}").render!(assigns) @@ -104,13 +104,13 @@ def test_lambda_is_called_once_from_custom_assigns_over_multiple_parses_and_rend end def test_resource_limits_works_with_custom_length_method - t = Template.parse("{% assign foo = bar %}") + t = Template.parse("{% assign foo = bar %}") t.resource_limits.render_length_limit = 42 assert_equal "", t.render!("bar" => SomethingWithLength.new) end def test_resource_limits_render_length - t = Template.parse("0123456789") + t = Template.parse("0123456789") t.resource_limits.render_length_limit = 5 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -121,12 +121,12 @@ def test_resource_limits_render_length end def test_resource_limits_render_score - t = Template.parse("{% for a in (1..10) %} {% for a in (1..10) %} foo {% endfor %} {% endfor %}") + t = Template.parse("{% for a in (1..10) %} {% for a in (1..10) %} foo {% endfor %} {% endfor %}") t.resource_limits.render_score_limit = 50 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? - t = Template.parse("{% for a in (1..100) %} foo {% endfor %}") + t = Template.parse("{% for a in (1..100) %} foo {% endfor %}") t.resource_limits.render_score_limit = 50 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -137,7 +137,7 @@ def test_resource_limits_render_score end def test_resource_limits_assign_score - t = Template.parse("{% assign foo = 42 %}{% assign bar = 23 %}") + t = Template.parse("{% assign foo = 42 %}{% assign bar = 23 %}") t.resource_limits.assign_score_limit = 1 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -169,7 +169,7 @@ def test_resource_limits_assign_score_nested end def test_resource_limits_aborts_rendering_after_first_error - t = Template.parse("{% for a in (1..100) %} foo1 {% endfor %} bar {% for a in (1..100) %} foo2 {% endfor %}") + t = Template.parse("{% for a in (1..100) %} foo1 {% endfor %} bar {% for a in (1..100) %} foo2 {% endfor %}") t.resource_limits.render_score_limit = 50 assert_equal "Liquid error: Memory limits exceeded", t.render assert t.resource_limits.reached? @@ -184,19 +184,19 @@ def test_resource_limits_hash_in_template_gets_updated_even_if_no_limits_are_set end def test_render_length_persists_between_blocks - t = Template.parse("{% if true %}aaaa{% endif %}") + t = Template.parse("{% if true %}aaaa{% endif %}") t.resource_limits.render_length_limit = 7 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 8 assert_equal "aaaa", t.render - t = Template.parse("{% if true %}aaaa{% endif %}{% if true %}bbb{% endif %}") + t = Template.parse("{% if true %}aaaa{% endif %}{% if true %}bbb{% endif %}") t.resource_limits.render_length_limit = 13 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 14 assert_equal "aaaabbb", t.render - t = Template.parse("{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}") + t = Template.parse("{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}{% if true %}a{% endif %}{% if true %}b{% endif %}") t.resource_limits.render_length_limit = 5 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 11 @@ -206,7 +206,7 @@ def test_render_length_persists_between_blocks end def test_render_length_uses_number_of_bytes_not_characters - t = Template.parse("{% if true %}すごい{% endif %}") + t = Template.parse("{% if true %}すごい{% endif %}") t.resource_limits.render_length_limit = 10 assert_equal "Liquid error: Memory limits exceeded", t.render t.resource_limits.render_length_limit = 18 @@ -215,7 +215,7 @@ def test_render_length_uses_number_of_bytes_not_characters def test_default_resource_limits_unaffected_by_render_with_context context = Context.new - t = Template.parse("{% for a in (1..100) %} {% assign foo = 1 %} {% endfor %}") + t = Template.parse("{% for a in (1..100) %} {% assign foo = 1 %} {% endfor %}") t.render!(context) assert context.resource_limits.assign_score > 0 assert context.resource_limits.render_score > 0 @@ -223,9 +223,9 @@ def test_default_resource_limits_unaffected_by_render_with_context end def test_can_use_drop_as_context - t = Template.new + t = Template.new t.registers['lulz'] = 'haha' - drop = TemplateContextDrop.new + drop = TemplateContextDrop.new assert_equal 'fizzbuzz', t.parse('{{foo}}').render!(drop) assert_equal 'bar', t.parse('{{bar}}').render!(drop) assert_equal 'haha', t.parse("{{baz}}").render!(drop) @@ -233,7 +233,7 @@ def test_can_use_drop_as_context def test_render_bang_force_rethrow_errors_on_passed_context context = Context.new('drop' => ErroneousDrop.new) - t = Template.new.parse('{{ drop.bad_method }}') + t = Template.new.parse('{{ drop.bad_method }}') e = assert_raises RuntimeError do t.render!(context) @@ -243,7 +243,7 @@ def test_render_bang_force_rethrow_errors_on_passed_context def test_exception_renderer_that_returns_string exception = nil - handler = ->(e) { + handler = ->(e) { exception = e '' } @@ -267,20 +267,20 @@ def test_exception_renderer_that_raises def test_global_filter_option_on_render global_filter_proc = ->(output) { "#{output} filtered" } - rendered_template = Template.parse("{{name}}").render({ "name" => "bob" }, global_filter: global_filter_proc) + rendered_template = Template.parse("{{name}}").render({ "name" => "bob" }, global_filter: global_filter_proc) assert_equal 'bob filtered', rendered_template end def test_global_filter_option_when_native_filters_exist global_filter_proc = ->(output) { "#{output} filtered" } - rendered_template = Template.parse("{{name | upcase}}").render({ "name" => "bob" }, global_filter: global_filter_proc) + rendered_template = Template.parse("{{name | upcase}}").render({ "name" => "bob" }, global_filter: global_filter_proc) assert_equal 'BOB filtered', rendered_template end def test_undefined_variables - t = Template.parse("{{x}} {{y}} {{z.a}} {{z.b}} {{z.c.d}}") + t = Template.parse("{{x}} {{y}} {{z.a}} {{z.b}} {{z.c.d}}") result = t.render({ 'x' => 33, 'z' => { 'a' => 32, 'c' => { 'e' => 31 } } }, strict_variables: true) assert_equal '33 32 ', result @@ -295,8 +295,8 @@ def test_undefined_variables def test_nil_value_does_not_raise Liquid::Template.error_mode = :strict - t = Template.parse("some{{x}}thing") - result = t.render!({ 'x' => nil }, strict_variables: true) + t = Template.parse("some{{x}}thing") + result = t.render!({ 'x' => nil }, strict_variables: true) assert_equal 0, t.errors.count assert_equal 'something', result @@ -311,8 +311,8 @@ def test_undefined_variables_raise end def test_undefined_drop_methods - d = DropWithUndefinedMethod.new - t = Template.new.parse('{{ foo }} {{ woot }}') + d = DropWithUndefinedMethod.new + t = Template.new.parse('{{ foo }} {{ woot }}') result = t.render(d, strict_variables: true) assert_equal 'foo ', result @@ -330,13 +330,13 @@ def test_undefined_drop_methods_raise end def test_undefined_filters - t = Template.parse("{{a}} {{x | upcase | somefilter1 | somefilter2 | somefilter3}}") + t = Template.parse("{{a}} {{x | upcase | somefilter1 | somefilter2 | somefilter3}}") filters = Module.new do def somefilter3(v) "-#{v}-" end end - result = t.render({ 'a' => 123, 'x' => 'foo' }, filters: [filters], strict_filters: true) + result = t.render({ 'a' => 123, 'x' => 'foo' }, filters: [filters], strict_filters: true) assert_equal '123 ', result assert_equal 1, t.errors.count @@ -353,11 +353,11 @@ def test_undefined_filters_raise end def test_using_range_literal_works_as_expected - t = Template.parse("{% assign foo = (x..y) %}{{ foo }}") + t = Template.parse("{% assign foo = (x..y) %}{{ foo }}") result = t.render('x' => 1, 'y' => 5) assert_equal '1..5', result - t = Template.parse("{% assign nums = (x..y) %}{% for num in nums %}{{ num }}{% endfor %}") + t = Template.parse("{% assign nums = (x..y) %}{% for num in nums %}{{ num }}{% endfor %}") result = t.render('x' => 1, 'y' => 5) assert_equal '12345', result end diff --git a/test/integration/trim_mode_test.rb b/test/integration/trim_mode_test.rb index 4c4d4c831..438f86b5d 100644 --- a/test/integration/trim_mode_test.rb +++ b/test/integration/trim_mode_test.rb @@ -7,7 +7,7 @@ class TrimModeTest < Minitest::Test # Make sure the trim isn't applied to standard output def test_standard_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{ 'John' }} @@ -25,7 +25,7 @@ def test_standard_output end def test_variable_output_with_multiple_blank_lines - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

@@ -45,7 +45,7 @@ def test_variable_output_with_multiple_blank_lines end def test_tag_output_with_multiple_blank_lines - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

@@ -69,7 +69,7 @@ def test_tag_output_with_multiple_blank_lines # Make sure the trim isn't applied to standard tags def test_standard_tags whitespace = ' ' - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if true %} @@ -78,7 +78,7 @@ def test_standard_tags

END_TEMPLATE - expected = <<~END_EXPECTED + expected = <<~END_EXPECTED

#{whitespace} @@ -89,7 +89,7 @@ def test_standard_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if false %} @@ -110,64 +110,64 @@ def test_standard_tags # Make sure the trim isn't too agressive def test_no_trim_output - text = '

{{- \'John\' -}}

' + text = '

{{- \'John\' -}}

' expected = '

John

' assert_template_result(expected, text) end # Make sure the trim isn't too agressive def test_no_trim_tags - text = '

{%- if true -%}yes{%- endif -%}

' + text = '

{%- if true -%}yes{%- endif -%}

' expected = '

yes

' assert_template_result(expected, text) - text = '

{%- if false -%}no{%- endif -%}

' + text = '

{%- if false -%}no{%- endif -%}

' expected = '

' assert_template_result(expected, text) end def test_single_line_outer_tag - text = '

{%- if true %} yes {% endif -%}

' + text = '

{%- if true %} yes {% endif -%}

' expected = '

yes

' assert_template_result(expected, text) - text = '

{%- if false %} no {% endif -%}

' + text = '

{%- if false %} no {% endif -%}

' expected = '

' assert_template_result(expected, text) end def test_single_line_inner_tag - text = '

{% if true -%} yes {%- endif %}

' + text = '

{% if true -%} yes {%- endif %}

' expected = '

yes

' assert_template_result(expected, text) - text = '

{% if false -%} no {%- endif %}

' + text = '

{% if false -%} no {%- endif %}

' expected = '

' assert_template_result(expected, text) end def test_single_line_post_tag - text = '

{% if true -%} yes {% endif -%}

' + text = '

{% if true -%} yes {% endif -%}

' expected = '

yes

' assert_template_result(expected, text) - text = '

{% if false -%} no {% endif -%}

' + text = '

{% if false -%} no {% endif -%}

' expected = '

' assert_template_result(expected, text) end def test_single_line_pre_tag - text = '

{%- if true %} yes {%- endif %}

' + text = '

{%- if true %} yes {%- endif %}

' expected = '

yes

' assert_template_result(expected, text) - text = '

{%- if false %} no {%- endif %}

' + text = '

{%- if false %} no {%- endif %}

' expected = '

' assert_template_result(expected, text) end def test_pre_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{- 'John' }} @@ -184,7 +184,7 @@ def test_pre_trim_output end def test_pre_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if true %} @@ -202,7 +202,7 @@ def test_pre_trim_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if false %} @@ -221,7 +221,7 @@ def test_pre_trim_tags end def test_post_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{ 'John' -}} @@ -238,7 +238,7 @@ def test_post_trim_output end def test_post_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if true -%} @@ -256,7 +256,7 @@ def test_post_trim_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if false -%} @@ -275,7 +275,7 @@ def test_post_trim_tags end def test_pre_and_post_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if true %} @@ -293,7 +293,7 @@ def test_pre_and_post_trim_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if false %} @@ -311,7 +311,7 @@ def test_pre_and_post_trim_tags end def test_post_and_pre_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if true -%} @@ -330,7 +330,7 @@ def test_post_and_pre_trim_tags assert_template_result(expected, text) whitespace = ' ' - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{% if false -%} @@ -339,7 +339,7 @@ def test_post_and_pre_trim_tags

END_TEMPLATE - expected = <<~END_EXPECTED + expected = <<~END_EXPECTED

#{whitespace} @@ -350,7 +350,7 @@ def test_post_and_pre_trim_tags end def test_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{- 'John' -}} @@ -366,7 +366,7 @@ def test_trim_output end def test_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if true -%} @@ -382,7 +382,7 @@ def test_trim_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if false -%} @@ -400,7 +400,7 @@ def test_trim_tags end def test_whitespace_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{- 'John' -}}, @@ -417,7 +417,7 @@ def test_whitespace_trim_output end def test_whitespace_trim_tags - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if true -%} @@ -433,7 +433,7 @@ def test_whitespace_trim_tags END_EXPECTED assert_template_result(expected, text) - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if false -%} @@ -451,7 +451,7 @@ def test_whitespace_trim_tags end def test_complex_trim_output - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{{- 'John' -}} @@ -481,7 +481,7 @@ def test_complex_trim_output end def test_complex_trim - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE

{%- if true -%} {%- if true -%} @@ -504,7 +504,7 @@ def test_right_trim_followed_by_tag def test_raw_output whitespace = ' ' - text = <<-END_TEMPLATE + text = <<-END_TEMPLATE
{% raw %} {%- if true -%} @@ -515,7 +515,7 @@ def test_raw_output {% endraw %}
END_TEMPLATE - expected = <<~END_EXPECTED + expected = <<~END_EXPECTED
#{whitespace} {%- if true -%} diff --git a/test/integration/variable_test.rb b/test/integration/variable_test.rb index af8a4cca4..94ed1eca9 100644 --- a/test/integration/variable_test.rb +++ b/test/integration/variable_test.rb @@ -52,13 +52,13 @@ def test_nil_renders_as_empty_string end def test_preset_assigns - template = Template.parse(%({{ test }})) + template = Template.parse(%({{ test }})) template.assigns['test'] = 'worked' assert_equal 'worked', template.render! end def test_reuse_parsed_template - template = Template.parse(%({{ greeting }} {{ name }})) + template = Template.parse(%({{ greeting }} {{ name }})) template.assigns['greeting'] = 'Goodbye' assert_equal 'Hello Tobi', template.render!('greeting' => 'Hello', 'name' => 'Tobi') assert_equal 'Hello ', template.render!('greeting' => 'Hello', 'unknown' => 'Tobi') @@ -68,7 +68,7 @@ def test_reuse_parsed_template end def test_assigns_not_polluted_from_template - template = Template.parse(%({{ test }}{% assign test = 'bar' %}{{ test }})) + template = Template.parse(%({{ test }}{% assign test = 'bar' %}{{ test }})) template.assigns['test'] = 'baz' assert_equal 'bazbar', template.render! assert_equal 'bazbar', template.render! @@ -77,12 +77,12 @@ def test_assigns_not_polluted_from_template end def test_hash_with_default_proc - template = Template.parse(%(Hello {{ test }})) - assigns = Hash.new { |_h, k| raise "Unknown variable '#{k}'" } + template = Template.parse(%(Hello {{ test }})) + assigns = Hash.new { |_h, k| raise "Unknown variable '#{k}'" } assigns['test'] = 'Tobi' assert_equal 'Hello Tobi', template.render!(assigns) assigns.delete('test') - e = assert_raises(RuntimeError) do + e = assert_raises(RuntimeError) do template.render!(assigns) end assert_equal "Unknown variable 'test'", e.message diff --git a/test/test_helper.rb b/test/test_helper.rb index 0f00effb2..9606ef8fb 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,8 +8,8 @@ require 'liquid.rb' require 'liquid/profiler' -mode = :strict -if (env_mode = ENV['LIQUID_PARSER_MODE']) +mode = :strict +if (env_mode = ENV['LIQUID_PARSER_MODE']) puts "-- #{env_mode.upcase} ERROR MODE" mode = env_mode.to_sym end @@ -71,7 +71,7 @@ def with_global_filter(*globals) end def with_taint_mode(mode) - old_mode = Liquid::Template.taint_mode + old_mode = Liquid::Template.taint_mode Liquid::Template.taint_mode = mode yield ensure @@ -79,7 +79,7 @@ def with_taint_mode(mode) end def with_error_mode(mode) - old_mode = Liquid::Template.error_mode + old_mode = Liquid::Template.error_mode Liquid::Template.error_mode = mode yield ensure @@ -128,7 +128,7 @@ class StubFileSystem def initialize(values) @file_read_count = 0 - @values = values + @values = values end def read_template_file(template_path) diff --git a/test/unit/block_unit_test.rb b/test/unit/block_unit_test.rb index 0f79a51f0..fa06a8774 100644 --- a/test/unit/block_unit_test.rb +++ b/test/unit/block_unit_test.rb @@ -63,7 +63,7 @@ def render(*) assert_equal 'hello', template.render - buf = +'' + buf = +'' output = template.render({}, output: buf) assert_equal 'hello', output assert_equal 'hello', buf @@ -81,7 +81,7 @@ def render(*) assert_equal 'foohellobar', template.render - buf = +'' + buf = +'' output = template.render({}, output: buf) assert_equal 'foohellobar', output assert_equal 'foohellobar', buf diff --git a/test/unit/condition_unit_test.rb b/test/unit/condition_unit_test.rb index e79c86351..8d4e02f9d 100644 --- a/test/unit/condition_unit_test.rb +++ b/test/unit/condition_unit_test.rb @@ -75,9 +75,9 @@ def test_hash_compare_backwards_compatibility end def test_contains_works_on_arrays - @context = Liquid::Context.new + @context = Liquid::Context.new @context['array'] = [1, 2, 3, 4, 5] - array_expr = VariableLookup.new("array") + array_expr = VariableLookup.new("array") assert_evaluates_false array_expr, 'contains', 0 assert_evaluates_true array_expr, 'contains', 1 @@ -142,7 +142,7 @@ def test_should_allow_custom_proc_operator end def test_left_or_right_may_contain_operators - @context = Liquid::Context.new + @context = Liquid::Context.new @context['one'] = @context['another'] = "gnomeslab-and-or-liquid" assert_evaluates_true VariableLookup.new("one"), '==', VariableLookup.new("another") diff --git a/test/unit/context_unit_test.rb b/test/unit/context_unit_test.rb index 8b132a1df..3b460d7a3 100644 --- a/test/unit/context_unit_test.rb +++ b/test/unit/context_unit_test.rb @@ -46,7 +46,7 @@ def initialize(category) class CounterDrop < Liquid::Drop def count @count ||= 0 - @count += 1 + @count += 1 end end @@ -55,9 +55,9 @@ def fetch(index) end def [](index) - @counts ||= [] + @counts ||= [] @counts[index] ||= 0 - @counts[index] += 1 + @counts[index] += 1 end def to_liquid @@ -85,7 +85,7 @@ def test_variables @context['date'] = Date.today assert_equal Date.today, @context['date'] - now = Time.now + now = Time.now @context['datetime'] = now assert_equal now, @context['datetime'] @@ -265,7 +265,7 @@ def test_try_first def test_access_hashes_with_hash_notation @context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] } - @context['product'] = { 'variants' => [{ 'title' => 'draft151cm' }, { 'title' => 'element151cm' }] } + @context['product'] = { 'variants' => [{ 'title' => 'draft151cm' }, { 'title' => 'element151cm' }] } assert_equal 5, @context['products["count"]'] assert_equal 'deepsnow', @context['products["tags"][0]'] @@ -285,8 +285,8 @@ def test_access_variable_with_hash_notation end def test_access_hashes_with_hash_access_variables - @context['var'] = 'tags' - @context['nested'] = { 'var' => 'tags' } + @context['var'] = 'tags' + @context['nested'] = { 'var' => 'tags' } @context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] } assert_equal 'deepsnow', @context['products[var].first'] @@ -295,7 +295,7 @@ def test_access_hashes_with_hash_access_variables def test_hash_notation_only_for_hash_access @context['array'] = [1, 2, 3, 4, 5] - @context['hash'] = { 'first' => 'Hello' } + @context['hash'] = { 'first' => 'Hello' } assert_equal 1, @context['array.first'] assert_nil @context['array["first"]'] @@ -407,7 +407,7 @@ def test_array_containing_lambda_as_variable def test_lambda_is_called_once @context['callcount'] = proc { @global ||= 0 - @global += 1 + @global += 1 @global.to_s } @@ -421,7 +421,7 @@ def test_lambda_is_called_once def test_nested_lambda_is_called_once @context['callcount'] = { "lambda" => proc { @global ||= 0 - @global += 1 + @global += 1 @global.to_s } } @@ -435,7 +435,7 @@ def test_nested_lambda_is_called_once def test_lambda_in_array_is_called_once @context['callcount'] = [1, 2, proc { @global ||= 0 - @global += 1 + @global += 1 @global.to_s }, 4, 5] @@ -476,7 +476,7 @@ def test_context_initialization_with_a_proc_in_environment def test_apply_global_filter global_filter_proc = ->(output) { "#{output} filtered" } - context = Context.new + context = Context.new context.global_filter = global_filter_proc assert_equal 'hi filtered', context.apply_global_filter('hi') @@ -498,53 +498,53 @@ def test_apply_global_filter_when_no_global_filter_exist end def test_new_isolated_subcontext_does_not_inherit_variables - super_context = Context.new + super_context = Context.new super_context['my_variable'] = 'some value' - subcontext = super_context.new_isolated_subcontext + subcontext = super_context.new_isolated_subcontext assert_nil subcontext['my_variable'] end def test_new_isolated_subcontext_inherits_static_environment super_context = Context.build(static_environments: { 'my_environment_value' => 'my value' }) - subcontext = super_context.new_isolated_subcontext + subcontext = super_context.new_isolated_subcontext assert_equal 'my value', subcontext['my_environment_value'] end def test_new_isolated_subcontext_inherits_resource_limits resource_limits = ResourceLimits.new({}) - super_context = Context.new({}, {}, {}, false, resource_limits) - subcontext = super_context.new_isolated_subcontext + super_context = Context.new({}, {}, {}, false, resource_limits) + subcontext = super_context.new_isolated_subcontext assert_equal resource_limits, subcontext.resource_limits end def test_new_isolated_subcontext_inherits_exception_renderer - super_context = Context.new + super_context = Context.new super_context.exception_renderer = ->(_e) { 'my exception message' } - subcontext = super_context.new_isolated_subcontext + subcontext = super_context.new_isolated_subcontext assert_equal 'my exception message', subcontext.handle_error(Liquid::Error.new) end def test_new_isolated_subcontext_does_not_inherit_non_static_registers - registers = { + registers = { my_register: :my_value, } - super_context = Context.new({}, {}, StaticRegisters.new(registers)) + super_context = Context.new({}, {}, StaticRegisters.new(registers)) super_context.registers[:my_register] = :my_alt_value - subcontext = super_context.new_isolated_subcontext + subcontext = super_context.new_isolated_subcontext assert_equal :my_value, subcontext.registers[:my_register] end def test_new_isolated_subcontext_inherits_static_registers super_context = Context.build(registers: { my_register: :my_value }) - subcontext = super_context.new_isolated_subcontext + subcontext = super_context.new_isolated_subcontext assert_equal :my_value, subcontext.registers[:my_register] end def test_new_isolated_subcontext_registers_do_not_pollute_context - super_context = Context.build(registers: { my_register: :my_value }) - subcontext = super_context.new_isolated_subcontext + super_context = Context.build(registers: { my_register: :my_value }) + subcontext = super_context.new_isolated_subcontext subcontext.registers[:my_register] = :my_alt_value assert_equal :my_value, super_context.registers[:my_register] end @@ -558,8 +558,8 @@ def my_filter(*) super_context = Context.new super_context.add_filters([my_filter]) - subcontext = super_context.new_isolated_subcontext - template = Template.parse('{{ 123 | my_filter }}') + subcontext = super_context.new_isolated_subcontext + template = Template.parse('{{ 123 | my_filter }}') assert_equal 'my filter result', template.render(subcontext) end diff --git a/test/unit/partial_cache_unit_test.rb b/test/unit/partial_cache_unit_test.rb index 145c27d1f..dd4318530 100644 --- a/test/unit/partial_cache_unit_test.rb +++ b/test/unit/partial_cache_unit_test.rb @@ -21,7 +21,7 @@ def test_uses_the_file_system_register_if_present def test_reads_from_the_file_system_only_once_per_file file_system = StubFileSystem.new('my_partial' => 'some partial body') - context = Liquid::Context.build( + context = Liquid::Context.build( registers: { file_system: file_system } ) @@ -37,16 +37,16 @@ def test_reads_from_the_file_system_only_once_per_file end def test_cache_state_is_stored_per_context - parse_context = Liquid::ParseContext.new + parse_context = Liquid::ParseContext.new shared_file_system = StubFileSystem.new( 'my_partial' => 'my shared value' ) - context_one = Liquid::Context.build( + context_one = Liquid::Context.build( registers: { file_system: shared_file_system, } ) - context_two = Liquid::Context.build( + context_two = Liquid::Context.build( registers: { file_system: shared_file_system, } @@ -71,7 +71,7 @@ def test_cache_state_is_stored_per_context def test_cache_is_not_broken_when_a_different_parse_context_is_used file_system = StubFileSystem.new('my_partial' => 'some partial body') - context = Liquid::Context.build( + context = Liquid::Context.build( registers: { file_system: file_system } ) diff --git a/test/unit/static_registers_unit_test.rb b/test/unit/static_registers_unit_test.rb index 620375bf3..125440f21 100644 --- a/test/unit/static_registers_unit_test.rb +++ b/test/unit/static_registers_unit_test.rb @@ -6,10 +6,10 @@ class StaticRegistersUnitTest < Minitest::Test include Liquid def set - static_register = StaticRegisters.new - static_register[nil] = true - static_register[1] = :one - static_register[:one] = "one" + static_register = StaticRegisters.new + static_register[nil] = true + static_register[1] = :one + static_register[:one] = "one" static_register["two"] = "three" static_register["two"] = 3 static_register[false] = nil @@ -77,10 +77,10 @@ def test_key end def set_with_static - static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) - static_register[nil] = false + static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) + static_register[nil] = false static_register["two"] = 4 - static_register[true] = "foo" + static_register[true] = "foo" assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static) assert_equal({ nil => false, "two" => 4, true => "foo" }, static_register.registers) @@ -154,23 +154,23 @@ def test_static_register_can_be_frozen end def test_new_static_retains_static - static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) - static_register["one"] = 1 - static_register["two"] = 2 + static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) + static_register["one"] = 1 + static_register["two"] = 2 static_register["three"] = 3 new_register = StaticRegisters.new(static_register) assert_equal({}, new_register.registers) - new_register["one"] = 4 - new_register["two"] = 5 + new_register["one"] = 4 + new_register["two"] = 5 new_register["three"] = 6 newest_register = StaticRegisters.new(new_register) assert_equal({}, newest_register.registers) - newest_register["one"] = 7 - newest_register["two"] = 8 + newest_register["one"] = 7 + newest_register["two"] = 8 newest_register["three"] = 9 assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers) @@ -182,23 +182,23 @@ def test_new_static_retains_static end def test_multiple_instances_are_unique - static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) - static_register["one"] = 1 - static_register["two"] = 2 + static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) + static_register["one"] = 1 + static_register["two"] = 2 static_register["three"] = 3 new_register = StaticRegisters.new(foo: :bar) assert_equal({}, new_register.registers) - new_register["one"] = 4 - new_register["two"] = 5 + new_register["one"] = 4 + new_register["two"] = 5 new_register["three"] = 6 newest_register = StaticRegisters.new(bar: :foo) assert_equal({}, newest_register.registers) - newest_register["one"] = 7 - newest_register["two"] = 8 + newest_register["one"] = 7 + newest_register["two"] = 8 newest_register["three"] = 9 assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers) @@ -210,9 +210,9 @@ def test_multiple_instances_are_unique end def test_can_update_static_directly_and_updates_all_instances - static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) - static_register["one"] = 1 - static_register["two"] = 2 + static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil) + static_register["one"] = 1 + static_register["two"] = 2 static_register["three"] = 3 new_register = StaticRegisters.new(static_register) @@ -220,9 +220,9 @@ def test_can_update_static_directly_and_updates_all_instances assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static) - new_register["one"] = 4 - new_register["two"] = 5 - new_register["three"] = 6 + new_register["one"] = 4 + new_register["two"] = 5 + new_register["three"] = 6 new_register.static["four"] = 10 newest_register = StaticRegisters.new(new_register) @@ -230,9 +230,9 @@ def test_can_update_static_directly_and_updates_all_instances assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil, "four" => 10 }, new_register.static) - newest_register["one"] = 7 - newest_register["two"] = 8 - newest_register["three"] = 9 + newest_register["one"] = 7 + newest_register["two"] = 8 + newest_register["three"] = 9 new_register.static["four"] = 5 new_register.static["five"] = 15 diff --git a/test/unit/strainer_unit_test.rb b/test/unit/strainer_unit_test.rb index b2d393aa4..2fb9ad440 100644 --- a/test/unit/strainer_unit_test.rb +++ b/test/unit/strainer_unit_test.rb @@ -72,8 +72,8 @@ def test_strainer_only_allows_methods_defined_in_filters end def test_strainer_uses_a_class_cache_to_avoid_method_cache_invalidation - a = Module.new - b = Module.new + a = Module.new + b = Module.new strainer = Strainer.create(nil, [a, b]) assert_kind_of Strainer, strainer assert_kind_of a, strainer @@ -82,8 +82,8 @@ def test_strainer_uses_a_class_cache_to_avoid_method_cache_invalidation end def test_add_filter_when_wrong_filter_class - c = Context.new - s = c.strainer + c = Context.new + s = c.strainer wrong_filter = ->(v) { v.reverse } assert_raises ArgumentError do @@ -150,7 +150,7 @@ def test_global_filter_clears_cache end def test_add_filter_does_not_include_already_included_module - mod = Module.new do + mod = Module.new do class << self attr_accessor :include_count def included(_mod) diff --git a/test/unit/tag_unit_test.rb b/test/unit/tag_unit_test.rb index c5de4ad45..c9543e921 100644 --- a/test/unit/tag_unit_test.rb +++ b/test/unit/tag_unit_test.rb @@ -33,7 +33,7 @@ def render(*) assert_equal 'hello', template.render - buf = +'' + buf = +'' output = template.render({}, output: buf) assert_equal 'hello', output assert_equal 'hello', buf @@ -51,7 +51,7 @@ def render(*) assert_equal 'foohellobar', template.render - buf = +'' + buf = +'' output = template.render({}, output: buf) assert_equal 'foohellobar', output assert_equal 'foohellobar', buf diff --git a/test/unit/template_unit_test.rb b/test/unit/template_unit_test.rb index deb4f25ab..bc02896d7 100644 --- a/test/unit/template_unit_test.rb +++ b/test/unit/template_unit_test.rb @@ -22,7 +22,7 @@ def test_sets_default_localization_in_context_with_quick_initialization def test_with_cache_classes_tags_returns_the_same_class original_cache_setting = Liquid.cache_classes - Liquid.cache_classes = true + Liquid.cache_classes = true original_klass = Class.new Object.send(:const_set, :CustomTag, original_klass) @@ -42,7 +42,7 @@ def test_with_cache_classes_tags_returns_the_same_class def test_without_cache_classes_tags_reloads_the_class original_cache_setting = Liquid.cache_classes - Liquid.cache_classes = false + Liquid.cache_classes = false original_klass = Class.new Object.send(:const_set, :CustomTag, original_klass) diff --git a/test/unit/tokenizer_unit_test.rb b/test/unit/tokenizer_unit_test.rb index 092c743da..44342d6c1 100644 --- a/test/unit/tokenizer_unit_test.rb +++ b/test/unit/tokenizer_unit_test.rb @@ -34,15 +34,15 @@ def test_calculate_line_numbers_per_token_with_profiling def tokenize(source) tokenizer = Liquid::Tokenizer.new(source) - tokens = [] - while (t = tokenizer.shift) + tokens = [] + while (t = tokenizer.shift) tokens << t end tokens end def tokenize_line_numbers(source) - tokenizer = Liquid::Tokenizer.new(source, true) + tokenizer = Liquid::Tokenizer.new(source, true) line_numbers = [] loop do line_number = tokenizer.line_number From da2fe9cab09ae821d5d1c2897b9f950e075aafd0 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Thu, 19 Sep 2019 22:56:00 +0530 Subject: [PATCH 4/6] Align equals operator in `lib/liquid/legacy.rb` --- lib/liquid/legacy.rb | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/liquid/legacy.rb b/lib/liquid/legacy.rb index 5cd66bc0b..70fb18670 100644 --- a/lib/liquid/legacy.rb +++ b/lib/liquid/legacy.rb @@ -1,32 +1,32 @@ # frozen_string_literal: true module Liquid - FilterSeparator = FILTER_SEPARATOR - ArgumentSeparator = ARGUMENT_SEPARATOR - FilterArgumentSeparator = FILTER_ARGUMENT_SEPARATOR + FilterSeparator = FILTER_SEPARATOR + ArgumentSeparator = ARGUMENT_SEPARATOR + FilterArgumentSeparator = FILTER_ARGUMENT_SEPARATOR VariableAttributeSeparator = VARIABLE_ATTRIBUTE_SEPARATOR - WhitespaceControl = WHITESPACE_CONTROL - TagStart = TAG_START - TagEnd = TAG_END - VariableSignature = VARIABLE_SIGNATURE - VariableSegment = VARIABLE_SEGMENT - VariableStart = VARIABLE_START - VariableEnd = VARIABLE_END - VariableIncompleteEnd = VARIABLE_INCOMPLETE_END - QuotedString = QUOTED_STRING - QuotedFragment = QUOTED_FRAGMENT - TagAttributes = TAG_ATTRIBUTES - AnyStartingTag = ANY_STARTING_TAG - PartialTemplateParser = PARTIAL_TEMPLATE_PARSER - TemplateParser = TEMPLATE_PARSER - VariableParser = VARIABLE_PARSER + WhitespaceControl = WHITESPACE_CONTROL + TagStart = TAG_START + TagEnd = TAG_END + VariableSignature = VARIABLE_SIGNATURE + VariableSegment = VARIABLE_SEGMENT + VariableStart = VARIABLE_START + VariableEnd = VARIABLE_END + VariableIncompleteEnd = VARIABLE_INCOMPLETE_END + QuotedString = QUOTED_STRING + QuotedFragment = QUOTED_FRAGMENT + TagAttributes = TAG_ATTRIBUTES + AnyStartingTag = ANY_STARTING_TAG + PartialTemplateParser = PARTIAL_TEMPLATE_PARSER + TemplateParser = TEMPLATE_PARSER + VariableParser = VARIABLE_PARSER class BlockBody - FullToken = FULL_TOKEN - ContentOfVariable = CONTENT_OF_VARIABLE + FullToken = FULL_TOKEN + ContentOfVariable = CONTENT_OF_VARIABLE WhitespaceOrNothing = WHITESPACE_OR_NOTHING - TAGSTART = TAG_START_STRING - VARSTART = VAR_START_STRING + TAGSTART = TAG_START_STRING + VARSTART = VAR_START_STRING end class Assign < Tag @@ -52,7 +52,7 @@ class For < Block end class If < Block - Syntax = SYNTAX + Syntax = SYNTAX ExpressionsAndOperators = EXPRESSIONS_AND_OPERATORS end @@ -61,7 +61,7 @@ class Include < Tag end class Raw < Block - Syntax = SYNTAX + Syntax = SYNTAX FullTokenPossiblyInvalid = FULL_TOKEN_POSSIBLY_INVALID end @@ -70,10 +70,10 @@ class TableRow < Block end class Variable - FilterMarkupRegex = FILTER_MARKUP_REGEX - FilterParser = FILTER_PARSER - FilterArgsRegex = FILTER_ARGS_REGEX - JustTagAttributes = JUST_TAG_ATTRIBUTES + FilterMarkupRegex = FILTER_MARKUP_REGEX + FilterParser = FILTER_PARSER + FilterArgsRegex = FILTER_ARGS_REGEX + JustTagAttributes = JUST_TAG_ATTRIBUTES MarkupWithQuotedFragment = MARKUP_WITH_QUOTED_FRAGMENT end end From da5688aeb21f19049850e6c869de1be8f7e85c71 Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Fri, 20 Sep 2019 03:57:49 +1000 Subject: [PATCH 5/6] Fix spacing --- lib/liquid.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/liquid.rb b/lib/liquid.rb index 7b4f098e7..ee7a4ef76 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -24,8 +24,8 @@ module Liquid FILTER_SEPARATOR = /\|/ ARGUMENT_SEPARATOR = ',' - FILTER_ARGUMENT_SEPARATOR = ':' - VARIABLE_ATTRIBUTE_SEPARATOR = '.' + FILTER_ARGUMENT_SEPARATOR = ':' + VARIABLE_ATTRIBUTE_SEPARATOR = '.' WHITESPACE_CONTROL = '-' TAG_START = /\{\%/ TAG_END = /\%\}/ @@ -33,12 +33,12 @@ module Liquid VARIABLE_SEGMENT = /[\w\-]/ VARIABLE_START = /\{\{/ VARIABLE_END = /\}\}/ - VARIABLE_INCOMPLETE_END = /\}\}?/ + VARIABLE_INCOMPLETE_END = /\}\}?/ QUOTED_STRING = /"[^"]*"|'[^']*'/ QUOTED_FRAGMENT = /#{QUOTED_STRING}|(?:[^\s,\|'"]|#{QUOTED_STRING})+/o TAG_ATTRIBUTES = /(\w+)\s*\:\s*(#{QUOTED_FRAGMENT})/o - ANY_STARTING_TAG = /#{TAG_START}|#{VARIABLE_START}/o - PARTIAL_TEMPLATE_PARSER = /#{TAG_START}.*?#{TAG_END}|#{VARIABLE_START}.*?#{VARIABLE_INCOMPLETE_END}/om + ANY_STARTING_TAG = /#{TAG_START}|#{VARIABLE_START}/o + PARTIAL_TEMPLATE_PARSER = /#{TAG_START}.*?#{TAG_END}|#{VARIABLE_START}.*?#{VARIABLE_INCOMPLETE_END}/om TEMPLATE_PARSER = /(#{PARTIAL_TEMPLATE_PARSER}|#{ANY_STARTING_TAG})/om VARIABLE_PARSER = /\[[^\]]+\]|#{VARIABLE_SEGMENT}+\??/o From 4ca476f71e334a6187c52b3675b9cdad56a37947 Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Sat, 5 Oct 2019 01:20:25 +1000 Subject: [PATCH 6/6] Resolve missing newline --- lib/liquid.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/liquid.rb b/lib/liquid.rb index 17dcef841..38c0b27ed 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -86,4 +86,4 @@ module Liquid Dir["#{__dir__}/liquid/tags/*.rb"].each { |f| require f } Dir["#{__dir__}/liquid/registers/*.rb"].each { |f| require f } -require 'liquid/legacy' \ No newline at end of file +require 'liquid/legacy'