mirror of
https://github.com/kemko/liquid.git
synced 2026-01-03 00:35:40 +03:00
Compare commits
12 Commits
render-for
...
fix-consta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dfcd9dedc | ||
|
|
e83b1e4159 | ||
|
|
3784020a8d | ||
|
|
4ca476f71e | ||
|
|
12f702c431 | ||
|
|
da5688aeb2 | ||
|
|
9c0bdf80bd | ||
|
|
da2fe9cab0 | ||
|
|
00c8ca559a | ||
|
|
26eb27f79f | ||
|
|
05c0bcf609 | ||
|
|
a4ec6a08cb |
@@ -892,7 +892,7 @@ Lint/FormatParameterMismatch:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Lint/HandleExceptions:
|
Lint/HandleExceptions:
|
||||||
Enabled: true
|
AllowComments: true
|
||||||
|
|
||||||
Lint/ImplicitStringConcatenation:
|
Lint/ImplicitStringConcatenation:
|
||||||
Description: Checks for adjacent string literals on the same line, which could
|
Description: Checks for adjacent string literals on the same line, which could
|
||||||
|
|||||||
@@ -21,25 +21,6 @@ Lint/InheritException:
|
|||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
Max: 294
|
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
|
# Offense count: 5
|
||||||
Style/ClassVars:
|
Style/ClassVars:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|||||||
2
Rakefile
2
Rakefile
@@ -11,7 +11,7 @@ desc('run test suite with default parser')
|
|||||||
Rake::TestTask.new(:base_test) do |t|
|
Rake::TestTask.new(:base_test) do |t|
|
||||||
t.libs << '.' << 'lib' << 'test'
|
t.libs << '.' << 'lib' << 'test'
|
||||||
t.test_files = FileList['test/{integration,unit}/**/*_test.rb']
|
t.test_files = FileList['test/{integration,unit}/**/*_test.rb']
|
||||||
t.verbose = false
|
t.verbose = false
|
||||||
end
|
end
|
||||||
|
|
||||||
desc('run test suite with warn error mode')
|
desc('run test suite with warn error mode')
|
||||||
|
|||||||
@@ -12,16 +12,16 @@ class LiquidServlet < WEBrick::HTTPServlet::AbstractServlet
|
|||||||
private
|
private
|
||||||
|
|
||||||
def handle(_type, req, res)
|
def handle(_type, req, res)
|
||||||
@request = req
|
@request = req
|
||||||
@response = res
|
@response = res
|
||||||
|
|
||||||
@request.path_info =~ /(\w+)\z/
|
@request.path_info =~ /(\w+)\z/
|
||||||
@action = Regexp.last_match(1) || 'index'
|
@action = Regexp.last_match(1) || 'index'
|
||||||
@assigns = send(@action) if respond_to?(@action)
|
@assigns = send(@action) if respond_to?(@action)
|
||||||
|
|
||||||
@response['Content-Type'] = "text/html"
|
@response['Content-Type'] = "text/html"
|
||||||
@response.status = 200
|
@response.status = 200
|
||||||
@response.body = Liquid::Template.parse(read_template).render(@assigns, filters: [ProductsFilter])
|
@response.body = Liquid::Template.parse(read_template).render(@assigns, filters: [ProductsFilter])
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_template(filename = @action)
|
def read_template(filename = @action)
|
||||||
|
|||||||
@@ -22,25 +22,25 @@
|
|||||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
module Liquid
|
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 = /\(?[\w\-\.\[\]]\)?/
|
VARIABLE_SIGNATURE = /\(?[\w\-\.\[\]]\)?/
|
||||||
VariableSegment = /[\w\-]/
|
VARIABLE_SEGMENT = /[\w\-]/
|
||||||
VariableStart = /\{\{/
|
VARIABLE_START = /\{\{/
|
||||||
VariableEnd = /\}\}/
|
VARIABLE_END = /\}\}/
|
||||||
VariableIncompleteEnd = /\}\}?/
|
VARIABLE_INCOMPLETE_END = /\}\}?/
|
||||||
QuotedString = /"[^"]*"|'[^']*'/
|
QUOTED_STRING = /"[^"]*"|'[^']*'/
|
||||||
QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
|
QUOTED_FRAGMENT = /#{QUOTED_STRING}|(?:[^\s,\|'"]|#{QUOTED_STRING})+/o
|
||||||
TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o
|
TAG_ATTRIBUTES = /(\w+)\s*\:\s*(#{QUOTED_FRAGMENT})/o
|
||||||
AnyStartingTag = /#{TagStart}|#{VariableStart}/o
|
ANY_STARTING_TAG = /#{TAG_START}|#{VARIABLE_START}/o
|
||||||
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
|
PARTIAL_TEMPLATE_PARSER = /#{TAG_START}.*?#{TAG_END}|#{VARIABLE_START}.*?#{VARIABLE_INCOMPLETE_END}/om
|
||||||
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
|
TEMPLATE_PARSER = /(#{PARTIAL_TEMPLATE_PARSER}|#{ANY_STARTING_TAG})/om
|
||||||
VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o
|
VARIABLE_PARSER = /\[[^\]]+\]|#{VARIABLE_SEGMENT}+\??/o
|
||||||
|
|
||||||
singleton_class.send(:attr_accessor, :cache_classes)
|
singleton_class.send(:attr_accessor, :cache_classes)
|
||||||
self.cache_classes = true
|
self.cache_classes = true
|
||||||
@@ -85,3 +85,5 @@ require 'liquid/static_registers'
|
|||||||
#
|
#
|
||||||
Dir["#{__dir__}/liquid/tags/*.rb"].each { |f| require f }
|
Dir["#{__dir__}/liquid/tags/*.rb"].each { |f| require f }
|
||||||
Dir["#{__dir__}/liquid/registers/*.rb"].each { |f| require f }
|
Dir["#{__dir__}/liquid/registers/*.rb"].each { |f| require f }
|
||||||
|
|
||||||
|
require 'liquid/legacy'
|
||||||
|
|||||||
@@ -2,18 +2,18 @@
|
|||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
class BlockBody
|
class BlockBody
|
||||||
LiquidTagToken = /\A\s*(\w+)\s*(.*?)\z/o
|
LIQUID_TAG_TOKEN = /\A\s*(\w+)\s*(.*?)\z/o
|
||||||
FullToken = /\A#{TagStart}#{WhitespaceControl}?(\s*)(\w+)(\s*)(.*?)#{WhitespaceControl}?#{TagEnd}\z/om
|
FULL_TOKEN = /\A#{TAG_START}#{WHITESPACE_CONTROL}?(\s*)(\w+)(\s*)(.*?)#{WHITESPACE_CONTROL}?#{TAG_END}\z/om
|
||||||
ContentOfVariable = /\A#{VariableStart}#{WhitespaceControl}?(.*?)#{WhitespaceControl}?#{VariableEnd}\z/om
|
CONTENT_OF_VARIABLE = /\A#{VARIABLE_START}#{WHITESPACE_CONTROL}?(.*?)#{WHITESPACE_CONTROL}?#{VARIABLE_END}\z/om
|
||||||
WhitespaceOrNothing = /\A\s*\z/
|
WHITESPACE_OR_NOTHING = /\A\s*\z/
|
||||||
TAGSTART = "{%"
|
TAG_START_STRING = "{%"
|
||||||
VARSTART = "{{"
|
VAR_START_STRING = "{{"
|
||||||
|
|
||||||
attr_reader :nodelist
|
attr_reader :nodelist
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@nodelist = []
|
@nodelist = []
|
||||||
@blank = true
|
@blank = true
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(tokenizer, parse_context, &block)
|
def parse(tokenizer, parse_context, &block)
|
||||||
@@ -28,14 +28,14 @@ module Liquid
|
|||||||
|
|
||||||
private def parse_for_liquid_tag(tokenizer, parse_context)
|
private def parse_for_liquid_tag(tokenizer, parse_context)
|
||||||
while (token = tokenizer.shift)
|
while (token = tokenizer.shift)
|
||||||
unless token.empty? || token =~ WhitespaceOrNothing
|
unless token.empty? || token =~ WHITESPACE_OR_NOTHING
|
||||||
unless token =~ LiquidTagToken
|
unless token =~ LIQUID_TAG_TOKEN
|
||||||
# line isn't empty but didn't match tag syntax, yield and let the
|
# line isn't empty but didn't match tag syntax, yield and let the
|
||||||
# caller raise a syntax error
|
# caller raise a syntax error
|
||||||
return yield token, token
|
return yield token, token
|
||||||
end
|
end
|
||||||
tag_name = Regexp.last_match(1)
|
tag_name = Regexp.last_match(1)
|
||||||
markup = Regexp.last_match(2)
|
markup = Regexp.last_match(2)
|
||||||
unless (tag = registered_tags[tag_name])
|
unless (tag = registered_tags[tag_name])
|
||||||
# end parsing if we reach an unknown tag and let the caller decide
|
# end parsing if we reach an unknown tag and let the caller decide
|
||||||
# determine how to proceed
|
# determine how to proceed
|
||||||
@@ -55,13 +55,13 @@ module Liquid
|
|||||||
while (token = tokenizer.shift)
|
while (token = tokenizer.shift)
|
||||||
next if token.empty?
|
next if token.empty?
|
||||||
case
|
case
|
||||||
when token.start_with?(TAGSTART)
|
when token.start_with?(TAG_START_STRING)
|
||||||
whitespace_handler(token, parse_context)
|
whitespace_handler(token, parse_context)
|
||||||
unless token =~ FullToken
|
unless token =~ FULL_TOKEN
|
||||||
raise_missing_tag_terminator(token, parse_context)
|
raise_missing_tag_terminator(token, parse_context)
|
||||||
end
|
end
|
||||||
tag_name = Regexp.last_match(2)
|
tag_name = Regexp.last_match(2)
|
||||||
markup = Regexp.last_match(4)
|
markup = Regexp.last_match(4)
|
||||||
|
|
||||||
if parse_context.line_number
|
if parse_context.line_number
|
||||||
# newlines inside the tag should increase the line number,
|
# newlines inside the tag should increase the line number,
|
||||||
@@ -82,7 +82,7 @@ module Liquid
|
|||||||
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
|
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
|
||||||
@blank &&= new_tag.blank?
|
@blank &&= new_tag.blank?
|
||||||
@nodelist << new_tag
|
@nodelist << new_tag
|
||||||
when token.start_with?(VARSTART)
|
when token.start_with?(VAR_START_STRING)
|
||||||
whitespace_handler(token, parse_context)
|
whitespace_handler(token, parse_context)
|
||||||
@nodelist << create_variable(token, parse_context)
|
@nodelist << create_variable(token, parse_context)
|
||||||
@blank = false
|
@blank = false
|
||||||
@@ -92,7 +92,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
parse_context.trim_whitespace = false
|
parse_context.trim_whitespace = false
|
||||||
@nodelist << token
|
@nodelist << token
|
||||||
@blank &&= !!(token =~ WhitespaceOrNothing)
|
@blank &&= !!(token =~ WHITESPACE_OR_NOTHING)
|
||||||
end
|
end
|
||||||
parse_context.line_number = tokenizer.line_number
|
parse_context.line_number = tokenizer.line_number
|
||||||
end
|
end
|
||||||
@@ -101,13 +101,13 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def whitespace_handler(token, parse_context)
|
def whitespace_handler(token, parse_context)
|
||||||
if token[2] == WhitespaceControl
|
if token[2] == WHITESPACE_CONTROL
|
||||||
previous_token = @nodelist.last
|
previous_token = @nodelist.last
|
||||||
if previous_token.is_a?(String)
|
if previous_token.is_a?(String)
|
||||||
previous_token.rstrip!
|
previous_token.rstrip!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
parse_context.trim_whitespace = (token[-3] == WhitespaceControl)
|
parse_context.trim_whitespace = (token[-3] == WHITESPACE_CONTROL)
|
||||||
end
|
end
|
||||||
|
|
||||||
def blank?
|
def blank?
|
||||||
@@ -180,7 +180,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_variable(token, parse_context)
|
def create_variable(token, parse_context)
|
||||||
token.scan(ContentOfVariable) do |content|
|
token.scan(CONTENT_OF_VARIABLE) do |content|
|
||||||
markup = content.first
|
markup = content.first
|
||||||
return Variable.new(markup, parse_context)
|
return Variable.new(markup, parse_context)
|
||||||
end
|
end
|
||||||
@@ -188,11 +188,11 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def raise_missing_tag_terminator(token, parse_context)
|
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
|
end
|
||||||
|
|
||||||
def raise_missing_variable_terminator(token, parse_context)
|
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
|
end
|
||||||
|
|
||||||
def registered_tags
|
def registered_tags
|
||||||
|
|||||||
@@ -35,10 +35,11 @@ module Liquid
|
|||||||
attr_accessor :left, :operator, :right
|
attr_accessor :left, :operator, :right
|
||||||
|
|
||||||
def initialize(left = nil, operator = nil, right = nil)
|
def initialize(left = nil, operator = nil, right = nil)
|
||||||
@left = left
|
@left = left
|
||||||
@operator = operator
|
@operator = operator
|
||||||
@right = right
|
@right = right
|
||||||
@child_relation = nil
|
|
||||||
|
@child_relation = nil
|
||||||
@child_condition = nil
|
@child_condition = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -62,12 +63,12 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def or(condition)
|
def or(condition)
|
||||||
@child_relation = :or
|
@child_relation = :or
|
||||||
@child_condition = condition
|
@child_condition = condition
|
||||||
end
|
end
|
||||||
|
|
||||||
def and(condition)
|
def and(condition)
|
||||||
@child_relation = :and
|
@child_relation = :and
|
||||||
@child_condition = condition
|
@child_condition = condition
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -115,7 +116,7 @@ module Liquid
|
|||||||
# return this as the result.
|
# return this as the result.
|
||||||
return context.evaluate(left) if op.nil?
|
return context.evaluate(left) if op.nil?
|
||||||
|
|
||||||
left = context.evaluate(left)
|
left = context.evaluate(left)
|
||||||
right = context.evaluate(right)
|
right = context.evaluate(right)
|
||||||
|
|
||||||
operation = self.class.operators[op] || raise(Liquid::ArgumentError, "Unknown operator #{op}")
|
operation = self.class.operators[op] || raise(Liquid::ArgumentError, "Unknown operator #{op}")
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ module Liquid
|
|||||||
self.exception_renderer = ->(_e) { raise }
|
self.exception_renderer = ->(_e) { raise }
|
||||||
end
|
end
|
||||||
|
|
||||||
@interrupts = []
|
@interrupts = []
|
||||||
@filters = []
|
@filters = []
|
||||||
@global_filter = nil
|
@global_filter = nil
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/ParameterLists
|
# rubocop:enable Metrics/ParameterLists
|
||||||
@@ -87,7 +87,7 @@ module Liquid
|
|||||||
def handle_error(e, line_number = nil)
|
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.template_name ||= template_name
|
||||||
e.line_number ||= line_number
|
e.line_number ||= line_number
|
||||||
errors.push(e)
|
errors.push(e)
|
||||||
exception_renderer.call(e).to_s
|
exception_renderer.call(e).to_s
|
||||||
end
|
end
|
||||||
@@ -138,11 +138,11 @@ module Liquid
|
|||||||
static_environments: static_environments,
|
static_environments: static_environments,
|
||||||
registers: StaticRegisters.new(registers)
|
registers: StaticRegisters.new(registers)
|
||||||
).tap do |subcontext|
|
).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.exception_renderer = exception_renderer
|
||||||
subcontext.filters = @filters
|
subcontext.filters = @filters
|
||||||
subcontext.strainer = nil
|
subcontext.strainer = nil
|
||||||
subcontext.errors = errors
|
subcontext.errors = errors
|
||||||
subcontext.warnings = warnings
|
subcontext.warnings = warnings
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -188,7 +188,7 @@ module Liquid
|
|||||||
try_variable_find_in_environments(key, raise_on_not_found: raise_on_not_found)
|
try_variable_find_in_environments(key, raise_on_not_found: raise_on_not_found)
|
||||||
end
|
end
|
||||||
|
|
||||||
variable = variable.to_liquid
|
variable = variable.to_liquid
|
||||||
variable.context = self if variable.respond_to?(:context=)
|
variable.context = self if variable.respond_to?(:context=)
|
||||||
|
|
||||||
variable
|
variable
|
||||||
|
|||||||
@@ -40,19 +40,19 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ArgumentError = Class.new(Error)
|
ArgumentError = Class.new(Error)
|
||||||
ContextError = Class.new(Error)
|
ContextError = Class.new(Error)
|
||||||
FileSystemError = Class.new(Error)
|
FileSystemError = Class.new(Error)
|
||||||
StandardError = Class.new(Error)
|
StandardError = Class.new(Error)
|
||||||
SyntaxError = Class.new(Error)
|
SyntaxError = Class.new(Error)
|
||||||
StackLevelError = Class.new(Error)
|
StackLevelError = Class.new(Error)
|
||||||
TaintedError = Class.new(Error)
|
TaintedError = Class.new(Error)
|
||||||
MemoryError = Class.new(Error)
|
MemoryError = Class.new(Error)
|
||||||
ZeroDivisionError = Class.new(Error)
|
ZeroDivisionError = Class.new(Error)
|
||||||
FloatDomainError = Class.new(Error)
|
FloatDomainError = Class.new(Error)
|
||||||
UndefinedVariable = Class.new(Error)
|
UndefinedVariable = Class.new(Error)
|
||||||
UndefinedDropMethod = Class.new(Error)
|
UndefinedDropMethod = Class.new(Error)
|
||||||
UndefinedFilter = Class.new(Error)
|
UndefinedFilter = Class.new(Error)
|
||||||
MethodOverrideError = Class.new(Error)
|
MethodOverrideError = Class.new(Error)
|
||||||
InternalError = Class.new(Error)
|
InternalError = Class.new(Error)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ module Liquid
|
|||||||
attr_accessor :root
|
attr_accessor :root
|
||||||
|
|
||||||
def initialize(root, pattern = "_%s.liquid")
|
def initialize(root, pattern = "_%s.liquid")
|
||||||
@root = root
|
@root = root
|
||||||
@pattern = pattern
|
@pattern = pattern
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class ForloopDrop < Drop
|
class ForloopDrop < Drop
|
||||||
def initialize(name, length, parentloop)
|
def initialize(name, length, parentloop)
|
||||||
@name = name
|
@name = name
|
||||||
@length = length
|
@length = length
|
||||||
@parentloop = parentloop
|
@parentloop = parentloop
|
||||||
@index = 0
|
@index = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :name, :length, :parentloop
|
attr_reader :name, :length, :parentloop
|
||||||
|
|||||||
79
lib/liquid/legacy.rb
Normal file
79
lib/liquid/legacy.rb
Normal file
@@ -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
|
||||||
@@ -15,12 +15,12 @@ module Liquid
|
|||||||
'?' => :question,
|
'?' => :question,
|
||||||
'-' => :dash,
|
'-' => :dash,
|
||||||
}.freeze
|
}.freeze
|
||||||
IDENTIFIER = /[a-zA-Z_][\w-]*\??/
|
IDENTIFIER = /[a-zA-Z_][\w-]*\??/
|
||||||
SINGLE_STRING_LITERAL = /'[^\']*'/
|
SINGLE_STRING_LITERAL = /'[^\']*'/
|
||||||
DOUBLE_STRING_LITERAL = /"[^\"]*"/
|
DOUBLE_STRING_LITERAL = /"[^\"]*"/
|
||||||
NUMBER_LITERAL = /-?\d+(\.\d+)?/
|
NUMBER_LITERAL = /-?\d+(\.\d+)?/
|
||||||
DOTDOT = /\.\./
|
DOTDOT = /\.\./
|
||||||
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/
|
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/
|
||||||
WHITESPACE_OR_NOTHING = /\s*/
|
WHITESPACE_OR_NOTHING = /\s*/
|
||||||
|
|
||||||
def initialize(input)
|
def initialize(input)
|
||||||
@@ -33,7 +33,7 @@ module Liquid
|
|||||||
until @ss.eos?
|
until @ss.eos?
|
||||||
@ss.skip(WHITESPACE_OR_NOTHING)
|
@ss.skip(WHITESPACE_OR_NOTHING)
|
||||||
break if @ss.eos?
|
break if @ss.eos?
|
||||||
tok = if (t = @ss.scan(COMPARISON_OPERATOR))
|
tok = if (t = @ss.scan(COMPARISON_OPERATOR))
|
||||||
[:comparison, t]
|
[:comparison, t]
|
||||||
elsif (t = @ss.scan(SINGLE_STRING_LITERAL))
|
elsif (t = @ss.scan(SINGLE_STRING_LITERAL))
|
||||||
[:string, t]
|
[:string, t]
|
||||||
@@ -46,7 +46,7 @@ module Liquid
|
|||||||
elsif (t = @ss.scan(DOTDOT))
|
elsif (t = @ss.scan(DOTDOT))
|
||||||
[:dotdot, t]
|
[:dotdot, t]
|
||||||
else
|
else
|
||||||
c = @ss.getch
|
c = @ss.getch
|
||||||
if (s = SPECIALS[c])
|
if (s = SPECIALS[c])
|
||||||
[s, c]
|
[s, c]
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ module Liquid
|
|||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@template_options = options ? options.dup : {}
|
@template_options = options ? options.dup : {}
|
||||||
@locale = @template_options[:locale] ||= I18n.new
|
|
||||||
|
@locale = @template_options[:locale] ||= I18n.new
|
||||||
@warnings = []
|
@warnings = []
|
||||||
self.depth = 0
|
|
||||||
|
self.depth = 0
|
||||||
self.partial = false
|
self.partial = false
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -20,6 +22,7 @@ module Liquid
|
|||||||
def partial=(value)
|
def partial=(value)
|
||||||
@partial = value
|
@partial = value
|
||||||
@options = value ? partial_options : @template_options
|
@options = value ? partial_options : @template_options
|
||||||
|
|
||||||
@error_mode = @options[:error_mode] || Template.error_mode
|
@error_mode = @options[:error_mode] || Template.error_mode
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize(node, callbacks)
|
def initialize(node, callbacks)
|
||||||
@node = node
|
@node = node
|
||||||
@callbacks = callbacks
|
@callbacks = callbacks
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class Parser
|
class Parser
|
||||||
def initialize(input)
|
def initialize(input)
|
||||||
l = Lexer.new(input)
|
l = Lexer.new(input)
|
||||||
@tokens = l.tokenize
|
@tokens = l.tokenize
|
||||||
@p = 0 # pointer to current location
|
@p = 0 # pointer to current location
|
||||||
end
|
end
|
||||||
|
|
||||||
def jump(point)
|
def jump(point)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ module Liquid
|
|||||||
def strict_parse_with_error_context(markup)
|
def strict_parse_with_error_context(markup)
|
||||||
strict_parse(markup)
|
strict_parse(markup)
|
||||||
rescue SyntaxError => e
|
rescue SyntaxError => e
|
||||||
e.line_number = line_number
|
e.line_number = line_number
|
||||||
e.markup_context = markup_context(markup)
|
e.markup_context = markup_context(markup)
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ module Liquid
|
|||||||
return cached if cached
|
return cached if cached
|
||||||
|
|
||||||
file_system = (context.registers[:file_system] ||= Liquid::Template.file_system)
|
file_system = (context.registers[:file_system] ||= Liquid::Template.file_system)
|
||||||
source = file_system.read_template_file(template_name)
|
source = file_system.read_template_file(template_name)
|
||||||
|
|
||||||
parse_context.partial = true
|
parse_context.partial = true
|
||||||
|
|
||||||
partial = Liquid::Template.parse(source, parse_context)
|
partial = Liquid::Template.parse(source, parse_context)
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def finish
|
def finish
|
||||||
@end_time = Time.now
|
@end_time = Time.now
|
||||||
@total_time = @end_time - @start_time
|
@total_time = @end_time - @start_time
|
||||||
|
|
||||||
if @children.empty?
|
if @children.empty?
|
||||||
@@ -112,11 +112,11 @@ module Liquid
|
|||||||
def initialize(partial_name = "<root>")
|
def initialize(partial_name = "<root>")
|
||||||
@partial_stack = [partial_name]
|
@partial_stack = [partial_name]
|
||||||
|
|
||||||
@root_timing = Timing.new("", current_partial)
|
@root_timing = Timing.new("", current_partial)
|
||||||
@timing_stack = [@root_timing]
|
@timing_stack = [@root_timing]
|
||||||
|
|
||||||
@render_start_at = Time.now
|
@render_start_at = Time.now
|
||||||
@render_end_at = @render_start_at
|
@render_end_at = @render_start_at
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ module Liquid
|
|||||||
class RangeLookup
|
class RangeLookup
|
||||||
def self.parse(start_markup, end_markup)
|
def self.parse(start_markup, end_markup)
|
||||||
start_obj = Expression.parse(start_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)
|
if start_obj.respond_to?(:evaluate) || end_obj.respond_to?(:evaluate)
|
||||||
new(start_obj, end_obj)
|
new(start_obj, end_obj)
|
||||||
else
|
else
|
||||||
@@ -14,12 +14,12 @@ module Liquid
|
|||||||
|
|
||||||
def initialize(start_obj, end_obj)
|
def initialize(start_obj, end_obj)
|
||||||
@start_obj = start_obj
|
@start_obj = start_obj
|
||||||
@end_obj = end_obj
|
@end_obj = end_obj
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(context)
|
def evaluate(context)
|
||||||
start_int = to_integer(context.evaluate(@start_obj))
|
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
|
start_int..end_int
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ module Liquid
|
|||||||
|
|
||||||
def increment(tag)
|
def increment(tag)
|
||||||
@disabled_tags[tag] ||= 0
|
@disabled_tags[tag] ||= 0
|
||||||
@disabled_tags[tag] += 1
|
@disabled_tags[tag] += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def decrement(tag)
|
def decrement(tag)
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ module Liquid
|
|||||||
|
|
||||||
def initialize(limits)
|
def initialize(limits)
|
||||||
@render_length_limit = limits[:render_length_limit]
|
@render_length_limit = limits[:render_length_limit]
|
||||||
@render_score_limit = limits[:render_score_limit]
|
@render_score_limit = limits[:render_score_limit]
|
||||||
@assign_score_limit = limits[:assign_score_limit]
|
@assign_score_limit = limits[:assign_score_limit]
|
||||||
reset
|
reset
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ module Liquid
|
|||||||
"'" => ''',
|
"'" => ''',
|
||||||
}.freeze
|
}.freeze
|
||||||
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
|
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
|
||||||
STRIP_HTML_BLOCKS = Regexp.union(
|
STRIP_HTML_BLOCKS = Regexp.union(
|
||||||
%r{<script.*?</script>}m,
|
%r{<script.*?</script>}m,
|
||||||
/<!--.*?-->/m,
|
/<!--.*?-->/m,
|
||||||
%r{<style.*?</style>}m
|
%r{<style.*?</style>}m
|
||||||
@@ -77,19 +77,24 @@ module Liquid
|
|||||||
def truncate(input, length = 50, truncate_string = "...")
|
def truncate(input, length = 50, truncate_string = "...")
|
||||||
return if input.nil?
|
return if input.nil?
|
||||||
input_str = input.to_s
|
input_str = input.to_s
|
||||||
length = Utils.to_integer(length)
|
length = Utils.to_integer(length)
|
||||||
|
|
||||||
truncate_string_str = truncate_string.to_s
|
truncate_string_str = truncate_string.to_s
|
||||||
|
|
||||||
l = length - truncate_string_str.length
|
l = length - truncate_string_str.length
|
||||||
l = 0 if l < 0
|
l = 0 if l < 0
|
||||||
|
|
||||||
input_str.length > length ? input_str[0...l].concat(truncate_string_str) : input_str
|
input_str.length > length ? input_str[0...l].concat(truncate_string_str) : input_str
|
||||||
end
|
end
|
||||||
|
|
||||||
def truncatewords(input, words = 15, truncate_string = "...")
|
def truncatewords(input, words = 15, truncate_string = "...")
|
||||||
return if input.nil?
|
return if input.nil?
|
||||||
wordlist = input.to_s.split
|
wordlist = input.to_s.split
|
||||||
words = Utils.to_integer(words)
|
words = Utils.to_integer(words)
|
||||||
|
|
||||||
l = words - 1
|
l = words - 1
|
||||||
l = 0 if l < 0
|
l = 0 if l < 0
|
||||||
|
|
||||||
wordlist.length > l ? wordlist[0..l].join(" ").concat(truncate_string.to_s) : input
|
wordlist.length > l ? wordlist[0..l].join(" ").concat(truncate_string.to_s) : input
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -115,7 +120,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def strip_html(input)
|
def strip_html(input)
|
||||||
empty = ''
|
empty = ''
|
||||||
result = input.to_s.gsub(STRIP_HTML_BLOCKS, empty)
|
result = input.to_s.gsub(STRIP_HTML_BLOCKS, empty)
|
||||||
result.gsub!(STRIP_HTML_TAGS, empty)
|
result.gsub!(STRIP_HTML_TAGS, empty)
|
||||||
result
|
result
|
||||||
@@ -471,7 +476,7 @@ module Liquid
|
|||||||
|
|
||||||
def initialize(input, context)
|
def initialize(input, context)
|
||||||
@context = context
|
@context = context
|
||||||
@input = if input.is_a?(Array)
|
@input = if input.is_a?(Array)
|
||||||
input.flatten
|
input.flatten
|
||||||
elsif input.is_a?(Hash)
|
elsif input.is_a?(Hash)
|
||||||
[input]
|
[input]
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ module Liquid
|
|||||||
attr_reader :static, :registers
|
attr_reader :static, :registers
|
||||||
|
|
||||||
def initialize(registers = {})
|
def initialize(registers = {})
|
||||||
@static = registers.is_a?(StaticRegisters) ? registers.static : registers
|
@static = registers.is_a?(StaticRegisters) ? registers.static : registers
|
||||||
@registers = {}
|
@registers = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ module Liquid
|
|||||||
class TablerowloopDrop < Drop
|
class TablerowloopDrop < Drop
|
||||||
def initialize(length, cols)
|
def initialize(length, cols)
|
||||||
@length = length
|
@length = length
|
||||||
@row = 1
|
@row = 1
|
||||||
@col = 1
|
@col = 1
|
||||||
@cols = cols
|
@cols = cols
|
||||||
@index = 0
|
@index = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :length, :col, :row
|
attr_reader :length, :col, :row
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize(tag_name, markup, parse_context)
|
def initialize(tag_name, markup, parse_context)
|
||||||
@tag_name = tag_name
|
@tag_name = tag_name
|
||||||
@markup = markup
|
@markup = markup
|
||||||
@parse_context = parse_context
|
@parse_context = parse_context
|
||||||
@line_number = parse_context.line_number
|
@line_number = parse_context.line_number
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(_tokens)
|
def parse(_tokens)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ module Liquid
|
|||||||
# {{ foo }}
|
# {{ foo }}
|
||||||
#
|
#
|
||||||
class Assign < Tag
|
class Assign < Tag
|
||||||
Syntax = /(#{VariableSignature}+)\s*=\s*(.*)\s*/om
|
SYNTAX = /(#{VARIABLE_SIGNATURE}+)\s*=\s*(.*)\s*/om
|
||||||
|
|
||||||
def self.syntax_error_translation_key
|
def self.syntax_error_translation_key
|
||||||
"errors.syntax.assign"
|
"errors.syntax.assign"
|
||||||
@@ -20,7 +20,7 @@ module Liquid
|
|||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def initialize(tag_name, markup, options)
|
||||||
super
|
super
|
||||||
if markup =~ Syntax
|
if markup =~ SYNTAX
|
||||||
@to = Regexp.last_match(1)
|
@to = Regexp.last_match(1)
|
||||||
@from = Variable.new(Regexp.last_match(2), options)
|
@from = Variable.new(Regexp.last_match(2), options)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ module Liquid
|
|||||||
# in a sidebar or footer.
|
# in a sidebar or footer.
|
||||||
#
|
#
|
||||||
class Capture < Block
|
class Capture < Block
|
||||||
Syntax = /(#{VariableSignature}+)/o
|
SYNTAX = /(#{VARIABLE_SIGNATURE}+)/o
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def initialize(tag_name, markup, options)
|
||||||
super
|
super
|
||||||
if markup =~ Syntax
|
if markup =~ SYNTAX
|
||||||
@to = Regexp.last_match(1)
|
@to = Regexp.last_match(1)
|
||||||
else
|
else
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.capture")
|
raise SyntaxError, options[:locale].t("errors.syntax.capture")
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
class Case < Block
|
class Case < Block
|
||||||
Syntax = /(#{QuotedFragment})/o
|
SYNTAX = /(#{QUOTED_FRAGMENT})/o
|
||||||
WhenSyntax = /(#{QuotedFragment})(?:(?:\s+or\s+|\s*\,\s*)(#{QuotedFragment}.*))?/om
|
WHEN_SYNTAX = /(#{QUOTED_FRAGMENT})(?:(?:\s+or\s+|\s*\,\s*)(#{QUOTED_FRAGMENT}.*))?/om
|
||||||
|
|
||||||
attr_reader :blocks, :left
|
attr_reader :blocks, :left
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ module Liquid
|
|||||||
super
|
super
|
||||||
@blocks = []
|
@blocks = []
|
||||||
|
|
||||||
if markup =~ Syntax
|
if markup =~ SYNTAX
|
||||||
@left = Expression.parse(Regexp.last_match(1))
|
@left = Expression.parse(Regexp.last_match(1))
|
||||||
else
|
else
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.case")
|
raise SyntaxError, options[:locale].t("errors.syntax.case")
|
||||||
@@ -59,7 +59,7 @@ module Liquid
|
|||||||
body = BlockBody.new
|
body = BlockBody.new
|
||||||
|
|
||||||
while markup
|
while markup
|
||||||
unless markup =~ WhenSyntax
|
unless markup =~ WHEN_SYNTAX
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.case_invalid_when")
|
raise SyntaxError, options[:locale].t("errors.syntax.case_invalid_when")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -14,20 +14,20 @@ module Liquid
|
|||||||
# <div class="green"> Item five</div>
|
# <div class="green"> Item five</div>
|
||||||
#
|
#
|
||||||
class Cycle < Tag
|
class Cycle < Tag
|
||||||
SimpleSyntax = /\A#{QuotedFragment}+/o
|
SIMPLE_SYNTAX = /\A#{QUOTED_FRAGMENT}+/o
|
||||||
NamedSyntax = /\A(#{QuotedFragment})\s*\:\s*(.*)/om
|
NAMED_SYNTAX = /\A(#{QUOTED_FRAGMENT})\s*\:\s*(.*)/om
|
||||||
|
|
||||||
attr_reader :variables
|
attr_reader :variables
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def initialize(tag_name, markup, options)
|
||||||
super
|
super
|
||||||
case markup
|
case markup
|
||||||
when NamedSyntax
|
when NAMED_SYNTAX
|
||||||
@variables = variables_from_string(Regexp.last_match(2))
|
@variables = variables_from_string(Regexp.last_match(2))
|
||||||
@name = Expression.parse(Regexp.last_match(1))
|
@name = Expression.parse(Regexp.last_match(1))
|
||||||
when SimpleSyntax
|
when SIMPLE_SYNTAX
|
||||||
@variables = variables_from_string(markup)
|
@variables = variables_from_string(markup)
|
||||||
@name = @variables.to_s
|
@name = @variables.to_s
|
||||||
else
|
else
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.cycle")
|
raise SyntaxError, options[:locale].t("errors.syntax.cycle")
|
||||||
end
|
end
|
||||||
@@ -36,7 +36,7 @@ module Liquid
|
|||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
context.registers[:cycle] ||= {}
|
context.registers[:cycle] ||= {}
|
||||||
|
|
||||||
key = context.evaluate(@name)
|
key = context.evaluate(@name)
|
||||||
iteration = context.registers[:cycle][key].to_i
|
iteration = context.registers[:cycle][key].to_i
|
||||||
|
|
||||||
val = context.evaluate(@variables[iteration])
|
val = context.evaluate(@variables[iteration])
|
||||||
@@ -50,9 +50,9 @@ module Liquid
|
|||||||
output << val
|
output << val
|
||||||
|
|
||||||
iteration += 1
|
iteration += 1
|
||||||
iteration = 0 if iteration >= @variables.size
|
iteration = 0 if iteration >= @variables.size
|
||||||
context.registers[:cycle][key] = iteration
|
|
||||||
|
|
||||||
|
context.registers[:cycle][key] = iteration
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ module Liquid
|
|||||||
|
|
||||||
def variables_from_string(markup)
|
def variables_from_string(markup)
|
||||||
markup.split(',').collect do |var|
|
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
|
Regexp.last_match(1) ? Expression.parse(Regexp.last_match(1)) : nil
|
||||||
end.compact
|
end.compact
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ module Liquid
|
|||||||
# forloop.parentloop:: Provides access to the parent loop, if present.
|
# forloop.parentloop:: Provides access to the parent loop, if present.
|
||||||
#
|
#
|
||||||
class For < Block
|
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
|
attr_reader :collection_name, :variable_name, :limit, :from
|
||||||
|
|
||||||
@@ -87,13 +87,13 @@ module Liquid
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def lax_parse(markup)
|
def lax_parse(markup)
|
||||||
if markup =~ Syntax
|
if markup =~ SYNTAX
|
||||||
@variable_name = Regexp.last_match(1)
|
@variable_name = Regexp.last_match(1)
|
||||||
collection_name = Regexp.last_match(2)
|
collection_name = Regexp.last_match(2)
|
||||||
@reversed = !!Regexp.last_match(3)
|
@reversed = !!Regexp.last_match(3)
|
||||||
@name = "#{@variable_name}-#{collection_name}"
|
@name = "#{@variable_name}-#{collection_name}"
|
||||||
@collection_name = Expression.parse(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)
|
set_attribute(key, value)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -105,9 +105,11 @@ module Liquid
|
|||||||
p = Parser.new(markup)
|
p = Parser.new(markup)
|
||||||
@variable_name = p.consume(:id)
|
@variable_name = p.consume(:id)
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.for_invalid_in") unless p.id?('in')
|
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
|
||||||
@collection_name = Expression.parse(collection_name)
|
@collection_name = Expression.parse(collection_name)
|
||||||
|
|
||||||
|
@name = "#{@variable_name}-#{collection_name}"
|
||||||
@reversed = p.id?('reversed')
|
@reversed = p.id?('reversed')
|
||||||
|
|
||||||
while p.look(:id) && p.look(:colon, 1)
|
while p.look(:id) && p.look(:colon, 1)
|
||||||
@@ -156,7 +158,7 @@ module Liquid
|
|||||||
|
|
||||||
def render_segment(context, output, segment)
|
def render_segment(context, output, segment)
|
||||||
for_stack = context.registers[:for_stack] ||= []
|
for_stack = context.registers[:for_stack] ||= []
|
||||||
length = segment.length
|
length = segment.length
|
||||||
|
|
||||||
context.stack do
|
context.stack do
|
||||||
loop_vars = Liquid::ForloopDrop.new(@name, length, for_stack[-1])
|
loop_vars = Liquid::ForloopDrop.new(@name, length, for_stack[-1])
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ module Liquid
|
|||||||
# There are {% if count < 5 %} less {% else %} more {% endif %} items than you need.
|
# There are {% if count < 5 %} less {% else %} more {% endif %} items than you need.
|
||||||
#
|
#
|
||||||
class If < Block
|
class If < Block
|
||||||
Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/o
|
SYNTAX = /(#{QUOTED_FRAGMENT})\s*([=!<>a-z_]+)?\s*(#{QUOTED_FRAGMENT})?/o
|
||||||
ExpressionsAndOperators = /(?:\b(?:\s?and\s?|\s?or\s?)\b|(?:\s*(?!\b(?:\s?and\s?|\s?or\s?)\b)(?:#{QuotedFragment}|\S+)\s*)+)/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
|
attr_reader :blocks
|
||||||
|
|
||||||
@@ -65,15 +65,15 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def lax_parse(markup)
|
def lax_parse(markup)
|
||||||
expressions = markup.scan(ExpressionsAndOperators)
|
expressions = markup.scan(EXPRESSIONS_AND_OPERATORS)
|
||||||
raise SyntaxError, options[:locale].t("errors.syntax.if") unless expressions.pop =~ Syntax
|
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)))
|
condition = Condition.new(Expression.parse(Regexp.last_match(1)), Regexp.last_match(2), Expression.parse(Regexp.last_match(3)))
|
||||||
|
|
||||||
until expressions.empty?
|
until expressions.empty?
|
||||||
operator = expressions.pop.to_s.strip
|
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)))
|
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)
|
raise SyntaxError, options[:locale].t("errors.syntax.if") unless BOOLEAN_OPERATORS.include?(operator)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ module Liquid
|
|||||||
#
|
#
|
||||||
class Include < Tag
|
class Include < Tag
|
||||||
SYNTAX = /(#{QuotedFragment}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
|
SYNTAX = /(#{QuotedFragment}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
|
||||||
Syntax = SYNTAX
|
|
||||||
|
|
||||||
attr_reader :template_name_expr, :variable_name_expr, :attributes
|
attr_reader :template_name_expr, :variable_name_expr, :attributes
|
||||||
|
|
||||||
@@ -29,12 +28,12 @@ module Liquid
|
|||||||
template_name = Regexp.last_match(1)
|
template_name = Regexp.last_match(1)
|
||||||
variable_name = Regexp.last_match(3)
|
variable_name = Regexp.last_match(3)
|
||||||
|
|
||||||
@alias_name = Regexp.last_match(5)
|
@alias_name = Regexp.last_match(5)
|
||||||
@variable_name_expr = variable_name ? Expression.parse(variable_name) : nil
|
@variable_name_expr = variable_name ? Expression.parse(variable_name) : nil
|
||||||
@template_name_expr = Expression.parse(template_name)
|
@template_name_expr = Expression.parse(template_name)
|
||||||
@attributes = {}
|
@attributes = {}
|
||||||
|
|
||||||
markup.scan(TagAttributes) do |key, value|
|
markup.scan(TAG_ATTRIBUTES) do |key, value|
|
||||||
@attributes[key] = Expression.parse(value)
|
@attributes[key] = Expression.parse(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,10 +64,10 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
old_template_name = context.template_name
|
old_template_name = context.template_name
|
||||||
old_partial = context.partial
|
old_partial = context.partial
|
||||||
begin
|
begin
|
||||||
context.template_name = template_name
|
context.template_name = template_name
|
||||||
context.partial = true
|
context.partial = true
|
||||||
context.stack do
|
context.stack do
|
||||||
@attributes.each do |key, value|
|
@attributes.each do |key, value|
|
||||||
context[key] = context.evaluate(value)
|
context[key] = context.evaluate(value)
|
||||||
@@ -86,7 +85,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
context.template_name = old_template_name
|
context.template_name = old_template_name
|
||||||
context.partial = old_partial
|
context.partial = old_partial
|
||||||
end
|
end
|
||||||
|
|
||||||
output
|
output
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
class Raw < Block
|
class Raw < Block
|
||||||
Syntax = /\A\s*\z/
|
SYNTAX = /\A\s*\z/
|
||||||
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
|
FULL_TOKEN_POSSIBLY_INVALID = /\A(.*)#{TAG_START}\s*(\w+)\s*(.*)?#{TAG_END}\z/om
|
||||||
|
|
||||||
def initialize(tag_name, markup, parse_context)
|
def initialize(tag_name, markup, parse_context)
|
||||||
super
|
super
|
||||||
@@ -14,7 +14,7 @@ module Liquid
|
|||||||
def parse(tokens)
|
def parse(tokens)
|
||||||
@body = +''
|
@body = +''
|
||||||
while (token = tokens.shift)
|
while (token = tokens.shift)
|
||||||
if token =~ FullTokenPossiblyInvalid
|
if token =~ FULL_TOKEN_POSSIBLY_INVALID
|
||||||
@body << Regexp.last_match(1) if Regexp.last_match(1) != ""
|
@body << Regexp.last_match(1) if Regexp.last_match(1) != ""
|
||||||
return if block_delimiter == Regexp.last_match(2)
|
return if block_delimiter == Regexp.last_match(2)
|
||||||
end
|
end
|
||||||
@@ -40,7 +40,7 @@ module Liquid
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def ensure_valid_markup(tag_name, markup, parse_context)
|
def ensure_valid_markup(tag_name, markup, parse_context)
|
||||||
unless Syntax.match?(markup)
|
unless SYNTAX.match?(markup)
|
||||||
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_unexpected_args", tag: tag_name)
|
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_unexpected_args", tag: tag_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ module Liquid
|
|||||||
@template_name_expr = Expression.parse(template_name)
|
@template_name_expr = Expression.parse(template_name)
|
||||||
|
|
||||||
@attributes = {}
|
@attributes = {}
|
||||||
markup.scan(TagAttributes) do |key, value|
|
markup.scan(TAG_ATTRIBUTES) do |key, value|
|
||||||
@attributes[key] = Expression.parse(value)
|
@attributes[key] = Expression.parse(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -43,19 +43,27 @@ module Liquid
|
|||||||
|
|
||||||
context_variable_name = @alias_name || template_name.split('/').last
|
context_variable_name = @alias_name || template_name.split('/').last
|
||||||
|
|
||||||
render_partial_func = ->(var) {
|
render_partial_func = ->(var, forloop) {
|
||||||
inner_context = context.new_isolated_subcontext
|
inner_context = context.new_isolated_subcontext
|
||||||
inner_context.template_name = template_name
|
inner_context.template_name = template_name
|
||||||
inner_context.partial = true
|
inner_context.partial = true
|
||||||
|
inner_context['forloop'] = forloop if forloop
|
||||||
|
|
||||||
@attributes.each do |key, value|
|
@attributes.each do |key, value|
|
||||||
inner_context[key] = context.evaluate(value)
|
inner_context[key] = context.evaluate(value)
|
||||||
end
|
end
|
||||||
inner_context[context_variable_name] = var unless var.nil?
|
inner_context[context_variable_name] = var unless var.nil?
|
||||||
partial.render_to_output_buffer(inner_context, output)
|
partial.render_to_output_buffer(inner_context, output)
|
||||||
|
forloop&.send(:increment!)
|
||||||
}
|
}
|
||||||
|
|
||||||
variable = @variable_name_expr ? context.evaluate(@variable_name_expr) : nil
|
variable = @variable_name_expr ? context.evaluate(@variable_name_expr) : nil
|
||||||
variable.is_a?(Array) ? variable.each(&render_partial_func) : render_partial_func.call(variable)
|
if variable.is_a?(Array)
|
||||||
|
forloop = Liquid::ForloopDrop.new(template_name, variable.count, nil)
|
||||||
|
variable.each { |var| render_partial_func.call(var, forloop) }
|
||||||
|
else
|
||||||
|
render_partial_func.call(variable, nil)
|
||||||
|
end
|
||||||
|
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
class TableRow < Block
|
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
|
attr_reader :variable_name, :collection_name, :attributes
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def initialize(tag_name, markup, options)
|
||||||
super
|
super
|
||||||
if markup =~ Syntax
|
if markup =~ SYNTAX
|
||||||
@variable_name = Regexp.last_match(1)
|
@variable_name = Regexp.last_match(1)
|
||||||
@collection_name = Expression.parse(Regexp.last_match(2))
|
@collection_name = Expression.parse(Regexp.last_match(2))
|
||||||
@attributes = {}
|
@attributes = {}
|
||||||
markup.scan(TagAttributes) do |key, value|
|
markup.scan(TAG_ATTRIBUTES) do |key, value|
|
||||||
@attributes[key] = Expression.parse(value)
|
@attributes[key] = Expression.parse(value)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -24,11 +24,10 @@ module Liquid
|
|||||||
(collection = context.evaluate(@collection_name)) || (return '')
|
(collection = context.evaluate(@collection_name)) || (return '')
|
||||||
|
|
||||||
from = @attributes.key?('offset') ? context.evaluate(@attributes['offset']).to_i : 0
|
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)
|
collection = Utils.slice_collection(collection, from, to)
|
||||||
|
length = collection.length
|
||||||
length = collection.length
|
|
||||||
|
|
||||||
cols = context.evaluate(@attributes['cols']).to_i
|
cols = context.evaluate(@attributes['cols']).to_i
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ module Liquid
|
|||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@tags = {}
|
@tags = {}
|
||||||
@cache = {}
|
@cache = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -128,19 +128,19 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@rethrow_errors = false
|
@rethrow_errors = false
|
||||||
@resource_limits = ResourceLimits.new(self.class.default_resource_limits)
|
@resource_limits = ResourceLimits.new(self.class.default_resource_limits)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse source code.
|
# Parse source code.
|
||||||
# Returns self for easy chaining
|
# Returns self for easy chaining
|
||||||
def parse(source, options = {})
|
def parse(source, options = {})
|
||||||
@options = options
|
@options = options
|
||||||
@profiling = options[:profile]
|
@profiling = options[:profile]
|
||||||
@line_numbers = options[:line_numbers] || @profiling
|
@line_numbers = options[:line_numbers] || @profiling
|
||||||
parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options)
|
parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options)
|
||||||
@root = Document.parse(tokenize(source), parse_context)
|
@root = Document.parse(tokenize(source), parse_context)
|
||||||
@warnings = parse_context.warnings
|
@warnings = parse_context.warnings
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ module Liquid
|
|||||||
|
|
||||||
c
|
c
|
||||||
when Liquid::Drop
|
when Liquid::Drop
|
||||||
drop = args.shift
|
drop = args.shift
|
||||||
drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits)
|
drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits)
|
||||||
when Hash
|
when Hash
|
||||||
Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits)
|
Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits)
|
||||||
@@ -204,7 +204,7 @@ module Liquid
|
|||||||
case args.last
|
case args.last
|
||||||
when Hash
|
when Hash
|
||||||
options = args.pop
|
options = args.pop
|
||||||
output = options[:output] if options[:output]
|
output = options[:output] if options[:output]
|
||||||
|
|
||||||
options[:registers]&.each do |key, register|
|
options[:registers]&.each do |key, register|
|
||||||
context_register[key] = register
|
context_register[key] = register
|
||||||
@@ -269,10 +269,10 @@ module Liquid
|
|||||||
|
|
||||||
def apply_options_to_context(context, options)
|
def apply_options_to_context(context, options)
|
||||||
context.add_filters(options[:filters]) if options[:filters]
|
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.exception_renderer = options[:exception_renderer] if options[:exception_renderer]
|
||||||
context.strict_variables = options[:strict_variables] if options[:strict_variables]
|
context.strict_variables = options[:strict_variables] if options[:strict_variables]
|
||||||
context.strict_filters = options[:strict_filters] if options[:strict_filters]
|
context.strict_filters = options[:strict_filters] if options[:strict_filters]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ module Liquid
|
|||||||
attr_reader :line_number, :for_liquid_tag
|
attr_reader :line_number, :for_liquid_tag
|
||||||
|
|
||||||
def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false)
|
def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false)
|
||||||
@source = source
|
@source = source
|
||||||
@line_number = line_number || (line_numbers ? 1 : nil)
|
@line_number = line_number || (line_numbers ? 1 : nil)
|
||||||
@for_liquid_tag = for_liquid_tag
|
@for_liquid_tag = for_liquid_tag
|
||||||
@tokens = tokenize
|
@tokens = tokenize
|
||||||
end
|
end
|
||||||
|
|
||||||
def shift
|
def shift
|
||||||
@@ -28,7 +28,7 @@ module Liquid
|
|||||||
|
|
||||||
return @source.split("\n") if @for_liquid_tag
|
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
|
# removes the rogue empty element at the beginning of the array
|
||||||
tokens.shift if tokens[0]&.empty?
|
tokens.shift if tokens[0]&.empty?
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ module Liquid
|
|||||||
|
|
||||||
def self.slice_collection_using_each(collection, from, to)
|
def self.slice_collection_using_each(collection, from, to)
|
||||||
segments = []
|
segments = []
|
||||||
index = 0
|
index = 0
|
||||||
|
|
||||||
# Maintains Ruby 1.8.7 String#each behaviour on 1.9
|
# Maintains Ruby 1.8.7 String#each behaviour on 1.9
|
||||||
if collection.is_a?(String)
|
if collection.is_a?(String)
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ module Liquid
|
|||||||
# {{ user | link }}
|
# {{ user | link }}
|
||||||
#
|
#
|
||||||
class Variable
|
class Variable
|
||||||
FilterMarkupRegex = /#{FilterSeparator}\s*(.*)/om
|
FILTER_MARKUP_REGEX = /#{FILTER_SEPARATOR}\s*(.*)/om
|
||||||
FilterParser = /(?:\s+|#{QuotedFragment}|#{ArgumentSeparator})+/o
|
FILTER_PARSER = /(?:\s+|#{QUOTED_FRAGMENT}|#{ARGUMENT_SEPARATOR})+/o
|
||||||
FilterArgsRegex = /(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{QuotedFragment})/o
|
FILTER_ARGS_REGEX . = /(?:#{FILTER_ARGUMENT_SEPARATOR}|#{ARGUMENT_SEPARATOR})\s*((?:\w+\s*\:\s*)?#{QUOTED_FRAGMENT})/o
|
||||||
JustTagAttributes = /\A#{TagAttributes}\z/o
|
JUST_TAG_ATTRIBUTES = /\A#{TAG_ATTRIBUTES}\z/o
|
||||||
MarkupWithQuotedFragment = /(#{QuotedFragment})(.*)/om
|
MARKUP_WITH_QUOTED_FRAGMENT = /(#{QUOTED_FRAGMENT})(.*)/om
|
||||||
|
|
||||||
attr_accessor :filters, :name, :line_number
|
attr_accessor :filters, :name, :line_number
|
||||||
attr_reader :parse_context
|
attr_reader :parse_context
|
||||||
@@ -25,10 +25,10 @@ module Liquid
|
|||||||
include ParserSwitching
|
include ParserSwitching
|
||||||
|
|
||||||
def initialize(markup, parse_context)
|
def initialize(markup, parse_context)
|
||||||
@markup = markup
|
@markup = markup
|
||||||
@name = nil
|
@name = nil
|
||||||
@parse_context = parse_context
|
@parse_context = parse_context
|
||||||
@line_number = parse_context.line_number
|
@line_number = parse_context.line_number
|
||||||
|
|
||||||
parse_with_selected_parser(markup)
|
parse_with_selected_parser(markup)
|
||||||
end
|
end
|
||||||
@@ -43,17 +43,17 @@ module Liquid
|
|||||||
|
|
||||||
def lax_parse(markup)
|
def lax_parse(markup)
|
||||||
@filters = []
|
@filters = []
|
||||||
return unless markup =~ MarkupWithQuotedFragment
|
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)
|
filter_markup = Regexp.last_match(2)
|
||||||
@name = Expression.parse(name_markup)
|
@name = Expression.parse(name_markup)
|
||||||
if filter_markup =~ FilterMarkupRegex
|
if filter_markup =~ FILTER_MARKUP_REGEX
|
||||||
filters = Regexp.last_match(1).scan(FilterParser)
|
filters = Regexp.last_match(1).scan(FILTER_PARSER)
|
||||||
filters.each do |f|
|
filters.each do |f|
|
||||||
next unless f =~ /\w+/
|
next unless f =~ /\w+/
|
||||||
filtername = Regexp.last_match(0)
|
filtername = Regexp.last_match(0)
|
||||||
filterargs = f.scan(FilterArgsRegex).flatten
|
filterargs = f.scan(FILTER_ARGS_REGEX).flatten
|
||||||
@filters << parse_filter_expressions(filtername, filterargs)
|
@filters << parse_filter_expressions(filtername, filterargs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -115,11 +115,11 @@ module Liquid
|
|||||||
private
|
private
|
||||||
|
|
||||||
def parse_filter_expressions(filter_name, unparsed_args)
|
def parse_filter_expressions(filter_name, unparsed_args)
|
||||||
filter_args = []
|
filter_args = []
|
||||||
keyword_args = nil
|
keyword_args = nil
|
||||||
unparsed_args.each do |a|
|
unparsed_args.each do |a|
|
||||||
if (matches = a.match(JustTagAttributes))
|
if (matches = a.match(JUST_TAG_ATTRIBUTES))
|
||||||
keyword_args ||= {}
|
keyword_args ||= {}
|
||||||
keyword_args[matches[1]] = Expression.parse(matches[2])
|
keyword_args[matches[1]] = Expression.parse(matches[2])
|
||||||
else
|
else
|
||||||
filter_args << Expression.parse(a)
|
filter_args << Expression.parse(a)
|
||||||
@@ -146,11 +146,11 @@ module Liquid
|
|||||||
return unless obj.tainted?
|
return unless obj.tainted?
|
||||||
return if Template.taint_mode == :lax
|
return if Template.taint_mode == :lax
|
||||||
|
|
||||||
@markup =~ QuotedFragment
|
@markup =~ QUOTED_FRAGMENT
|
||||||
name = Regexp.last_match(0)
|
name = Regexp.last_match(0)
|
||||||
|
|
||||||
error = TaintedError.new("variable '#{name}' is tainted and was not escaped")
|
error = TaintedError.new("variable '#{name}' is tainted and was not escaped")
|
||||||
error.line_number = line_number
|
error.line_number = line_number
|
||||||
error.template_name = context.template_name
|
error.template_name = context.template_name
|
||||||
|
|
||||||
case Template.taint_mode
|
case Template.taint_mode
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class VariableLookup
|
class VariableLookup
|
||||||
SQUARE_BRACKETED = /\A\[(.*)\]\z/m
|
SQUARE_BRACKETED = /\A\[(.*)\]\z/m
|
||||||
COMMAND_METHODS = ['size', 'first', 'last'].freeze
|
COMMAND_METHODS = ['size', 'first', 'last'].freeze
|
||||||
|
|
||||||
attr_reader :name, :lookups
|
attr_reader :name, :lookups
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize(markup)
|
def initialize(markup)
|
||||||
lookups = markup.scan(VariableParser)
|
lookups = markup.scan(VARIABLE_PARSER)
|
||||||
|
|
||||||
name = lookups.shift
|
name = lookups.shift
|
||||||
if name =~ SQUARE_BRACKETED
|
if name =~ SQUARE_BRACKETED
|
||||||
@@ -20,7 +20,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
@name = name
|
@name = name
|
||||||
|
|
||||||
@lookups = lookups
|
@lookups = lookups
|
||||||
@command_flags = 0
|
@command_flags = 0
|
||||||
|
|
||||||
@lookups.each_index do |i|
|
@lookups.each_index do |i|
|
||||||
@@ -34,7 +34,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(context)
|
def evaluate(context)
|
||||||
name = context.evaluate(@name)
|
name = context.evaluate(@name)
|
||||||
object = context.find_variable(name)
|
object = context.find_variable(name)
|
||||||
|
|
||||||
@lookups.each_index do |i|
|
@lookups.each_index do |i|
|
||||||
@@ -47,7 +47,7 @@ module Liquid
|
|||||||
(object.respond_to?(:fetch) && key.is_a?(Integer)))
|
(object.respond_to?(:fetch) && key.is_a?(Integer)))
|
||||||
|
|
||||||
# if its a proc we will replace the entry with the proc
|
# 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
|
object = res.to_liquid
|
||||||
|
|
||||||
# Some special cases. If the part wasn't in square brackets and
|
# Some special cases. If the part wasn't in square brackets and
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first
|
|||||||
profiler = ThemeRunner.new
|
profiler = ThemeRunner.new
|
||||||
|
|
||||||
Benchmark.ips do |x|
|
Benchmark.ips do |x|
|
||||||
x.time = 10
|
x.time = 10
|
||||||
x.warmup = 5
|
x.warmup = 5
|
||||||
|
|
||||||
puts
|
puts
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class CommentForm < Liquid::Block
|
class CommentForm < Liquid::Block
|
||||||
Syntax = /(#{Liquid::VariableSignature}+)/
|
SYNTAX = /(#{Liquid::VariableSignature}+)/
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
def initialize(tag_name, markup, options)
|
||||||
super
|
super
|
||||||
|
|
||||||
if markup =~ Syntax
|
if markup =~ SYNTAX
|
||||||
@variable_name = Regexp.last_match(1)
|
@variable_name = Regexp.last_match(1)
|
||||||
@attributes = {}
|
@attributes = {}
|
||||||
else
|
else
|
||||||
raise SyntaxError, "Syntax Error in 'comment_form' - Valid syntax: comment_form [article]"
|
raise SyntaxError, "Syntax Error in 'comment_form' - Valid syntax: comment_form [article]"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Paginate < Liquid::Block
|
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)
|
def initialize(tag_name, markup, options)
|
||||||
super
|
super
|
||||||
|
|
||||||
if markup =~ Syntax
|
if markup =~ SYNTAX
|
||||||
@collection_name = Regexp.last_match(1)
|
@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
|
Regexp.last_match(3).to_i
|
||||||
else
|
else
|
||||||
20
|
20
|
||||||
end
|
end
|
||||||
|
|
||||||
@attributes = { 'window_size' => 3 }
|
@attributes = { 'window_size' => 3 }
|
||||||
markup.scan(Liquid::TagAttributes) do |key, value|
|
markup.scan(Liquid::TAG_ATTRIBUTES) do |key, value|
|
||||||
@attributes[key] = value
|
@attributes[key] = value
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ class ThemeRunner
|
|||||||
# `render` is called to benchmark just the render portion of liquid
|
# `render` is called to benchmark just the render portion of liquid
|
||||||
def render
|
def render
|
||||||
@compiled_tests.each do |test|
|
@compiled_tests.each do |test|
|
||||||
tmpl = test[:tmpl]
|
tmpl = test[:tmpl]
|
||||||
assigns = test[:assigns]
|
assigns = test[:assigns]
|
||||||
layout = test[:layout]
|
layout = test[:layout]
|
||||||
|
|
||||||
if layout
|
if layout
|
||||||
assigns['content_for_layout'] = tmpl.render!(assigns)
|
assigns['content_for_layout'] = tmpl.render!(assigns)
|
||||||
@@ -74,7 +74,7 @@ class ThemeRunner
|
|||||||
private
|
private
|
||||||
|
|
||||||
def compile_and_render(template, layout, assigns, page_template, template_file)
|
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)
|
assigns['content_for_layout'] = compiled_test[:tmpl].render!(assigns)
|
||||||
compiled_test[:layout].render!(assigns) if layout
|
compiled_test[:layout].render!(assigns) if layout
|
||||||
end
|
end
|
||||||
@@ -88,7 +88,7 @@ class ThemeRunner
|
|||||||
end
|
end
|
||||||
|
|
||||||
def compile_test(template, layout, assigns, page_template, template_file)
|
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
|
parsed_template = tmpl.parse(template).dup
|
||||||
|
|
||||||
if layout
|
if layout
|
||||||
@@ -113,9 +113,9 @@ class ThemeRunner
|
|||||||
|
|
||||||
# set up a new Liquid::Template object for use in `compile_and_render` and `compile_test`
|
# set up a new Liquid::Template object for use in `compile_and_render` and `compile_test`
|
||||||
def init_template(page_template, template_file)
|
def init_template(page_template, template_file)
|
||||||
tmpl = Liquid::Template.new
|
tmpl = Liquid::Template.new
|
||||||
tmpl.assigns['page_title'] = 'Page title'
|
tmpl.assigns['page_title'] = 'Page title'
|
||||||
tmpl.assigns['template'] = page_template
|
tmpl.assigns['template'] = page_template
|
||||||
tmpl.registers[:file_system] = ThemeRunner::FileSystem.new(File.dirname(template_file))
|
tmpl.registers[:file_system] = ThemeRunner::FileSystem.new(File.dirname(template_file))
|
||||||
tmpl
|
tmpl
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ class AssignTest < Minitest::Test
|
|||||||
{% assign this-thing = 'Print this-thing' %}
|
{% assign this-thing = 'Print this-thing' %}
|
||||||
{{ this-thing }}
|
{{ this-thing }}
|
||||||
END_TEMPLATE
|
END_TEMPLATE
|
||||||
template = Template.parse(template_source)
|
template = Template.parse(template_source)
|
||||||
rendered = template.render!
|
rendered = template.render!
|
||||||
assert_equal("Print this-thing", rendered.strip)
|
assert_equal("Print this-thing", rendered.strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ class CaptureTest < Minitest::Test
|
|||||||
{% capture this-thing %}Print this-thing{% endcapture %}
|
{% capture this-thing %}Print this-thing{% endcapture %}
|
||||||
{{ this-thing }}
|
{{ this-thing }}
|
||||||
END_TEMPLATE
|
END_TEMPLATE
|
||||||
template = Template.parse(template_source)
|
template = Template.parse(template_source)
|
||||||
rendered = template.render!
|
rendered = template.render!
|
||||||
assert_equal("Print this-thing", rendered.strip)
|
assert_equal("Print this-thing", rendered.strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,8 +30,8 @@ class CaptureTest < Minitest::Test
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{{var}}
|
{{var}}
|
||||||
END_TEMPLATE
|
END_TEMPLATE
|
||||||
template = Template.parse(template_source)
|
template = Template.parse(template_source)
|
||||||
rendered = template.render!
|
rendered = template.render!
|
||||||
assert_equal("test-string", rendered.gsub(/\s/, ''))
|
assert_equal("test-string", rendered.gsub(/\s/, ''))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -45,8 +45,8 @@ class CaptureTest < Minitest::Test
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{{ first }}-{{ second }}
|
{{ first }}-{{ second }}
|
||||||
END_TEMPLATE
|
END_TEMPLATE
|
||||||
template = Template.parse(template_source)
|
template = Template.parse(template_source)
|
||||||
rendered = template.render!
|
rendered = template.render!
|
||||||
assert_equal("3-3", rendered.gsub(/\s/, ''))
|
assert_equal("3-3", rendered.gsub(/\s/, ''))
|
||||||
end
|
end
|
||||||
end # CaptureTest
|
end # CaptureTest
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ class DropsTest < Minitest::Test
|
|||||||
|
|
||||||
def test_rendering_warns_on_tainted_attr
|
def test_rendering_warns_on_tainted_attr
|
||||||
with_taint_mode(:warn) do
|
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)
|
context = Context.new('product' => ProductDrop.new)
|
||||||
tpl.render!(context)
|
tpl.render!(context)
|
||||||
assert_equal [Liquid::TaintedError], context.warnings.map(&:class)
|
assert_equal [Liquid::TaintedError], context.warnings.map(&:class)
|
||||||
|
|||||||
@@ -226,9 +226,9 @@ class ErrorHandlingTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_exception_renderer_exposing_non_liquid_error
|
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 = []
|
exceptions = []
|
||||||
handler = ->(e) {
|
handler = ->(e) {
|
||||||
exceptions << e
|
exceptions << e
|
||||||
e.cause
|
e.cause
|
||||||
}
|
}
|
||||||
@@ -252,8 +252,9 @@ class ErrorHandlingTest < Minitest::Test
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Liquid::Template.file_system = TestFileSystem.new
|
Liquid::Template.file_system = TestFileSystem.new
|
||||||
|
|
||||||
template = Liquid::Template.parse("Argument error:\n{% include 'product' %}", line_numbers: true)
|
template = Liquid::Template.parse("Argument error:\n{% include 'product' %}", line_numbers: true)
|
||||||
page = template.render('errors' => ErrorDrop.new)
|
page = template.render('errors' => ErrorDrop.new)
|
||||||
ensure
|
ensure
|
||||||
Liquid::Template.file_system = old_file_system
|
Liquid::Template.file_system = old_file_system
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -72,10 +72,10 @@ class FiltersTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_sort
|
def test_sort
|
||||||
@context['value'] = 3
|
@context['value'] = 3
|
||||||
@context['numbers'] = [2, 1, 4, 3]
|
@context['numbers'] = [2, 1, 4, 3]
|
||||||
@context['words'] = ['expected', 'as', 'alphabetic']
|
@context['words'] = ['expected', 'as', 'alphabetic']
|
||||||
@context['arrays'] = ['flower', 'are']
|
@context['arrays'] = ['flower', 'are']
|
||||||
@context['case_sensitive'] = ['sensitive', 'Expected', 'case']
|
@context['case_sensitive'] = ['sensitive', 'Expected', 'case']
|
||||||
|
|
||||||
assert_equal('1 2 3 4', Template.parse("{{numbers | sort | join}}").render(@context))
|
assert_equal('1 2 3 4', Template.parse("{{numbers | sort | join}}").render(@context))
|
||||||
@@ -86,8 +86,8 @@ class FiltersTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_natural
|
def test_sort_natural
|
||||||
@context['words'] = ['case', 'Assert', 'Insensitive']
|
@context['words'] = ['case', 'Assert', 'Insensitive']
|
||||||
@context['hashes'] = [{ 'a' => 'A' }, { 'a' => 'b' }, { 'a' => 'C' }]
|
@context['hashes'] = [{ 'a' => 'A' }, { 'a' => 'b' }, { 'a' => 'C' }]
|
||||||
@context['objects'] = [TestObject.new('A'), TestObject.new('b'), TestObject.new('C')]
|
@context['objects'] = [TestObject.new('A'), TestObject.new('b'), TestObject.new('C')]
|
||||||
|
|
||||||
# Test strings
|
# Test strings
|
||||||
@@ -101,8 +101,8 @@ class FiltersTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_compact
|
def test_compact
|
||||||
@context['words'] = ['a', nil, 'b', nil, 'c']
|
@context['words'] = ['a', nil, 'b', nil, 'c']
|
||||||
@context['hashes'] = [{ 'a' => 'A' }, { 'a' => nil }, { 'a' => 'C' }]
|
@context['hashes'] = [{ 'a' => 'A' }, { 'a' => nil }, { 'a' => 'C' }]
|
||||||
@context['objects'] = [TestObject.new('A'), TestObject.new(nil), TestObject.new('C')]
|
@context['objects'] = [TestObject.new('A'), TestObject.new(nil), TestObject.new('C')]
|
||||||
|
|
||||||
# Test strings
|
# Test strings
|
||||||
@@ -141,9 +141,9 @@ class FiltersTest < Minitest::Test
|
|||||||
|
|
||||||
def test_filter_with_keyword_arguments
|
def test_filter_with_keyword_arguments
|
||||||
@context['surname'] = 'john'
|
@context['surname'] = 'john'
|
||||||
@context['input'] = 'hello %{first_name}, %{last_name}'
|
@context['input'] = 'hello %{first_name}, %{last_name}'
|
||||||
@context.add_filters(SubstituteFilter)
|
@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)
|
assert_equal('hello john, doe', output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -61,63 +61,63 @@ class OutputTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_variable_piping
|
def test_variable_piping
|
||||||
text = %( {{ car.gm | make_funny }} )
|
text = %( {{ car.gm | make_funny }} )
|
||||||
expected = %( LOL )
|
expected = %( LOL )
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_variable_piping_with_input
|
def test_variable_piping_with_input
|
||||||
text = %( {{ car.gm | cite_funny }} )
|
text = %( {{ car.gm | cite_funny }} )
|
||||||
expected = %( LOL: bad )
|
expected = %( LOL: bad )
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_variable_piping_with_args
|
def test_variable_piping_with_args
|
||||||
text = %! {{ car.gm | add_smiley : ':-(' }} !
|
text = %! {{ car.gm | add_smiley : ':-(' }} !
|
||||||
expected = %| bad :-( |
|
expected = %| bad :-( |
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_variable_piping_with_no_args
|
def test_variable_piping_with_no_args
|
||||||
text = %( {{ car.gm | add_smiley }} )
|
text = %( {{ car.gm | add_smiley }} )
|
||||||
expected = %| bad :-) |
|
expected = %| bad :-) |
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multiple_variable_piping_with_args
|
def test_multiple_variable_piping_with_args
|
||||||
text = %! {{ car.gm | add_smiley : ':-(' | add_smiley : ':-('}} !
|
text = %! {{ car.gm | add_smiley : ':-(' | add_smiley : ':-('}} !
|
||||||
expected = %| bad :-( :-( |
|
expected = %| bad :-( :-( |
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_variable_piping_with_multiple_args
|
def test_variable_piping_with_multiple_args
|
||||||
text = %( {{ car.gm | add_tag : 'span', 'bar'}} )
|
text = %( {{ car.gm | add_tag : 'span', 'bar'}} )
|
||||||
expected = %( <span id="bar">bad</span> )
|
expected = %( <span id="bar">bad</span> )
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_variable_piping_with_variable_args
|
def test_variable_piping_with_variable_args
|
||||||
text = %( {{ car.gm | add_tag : 'span', car.bmw}} )
|
text = %( {{ car.gm | add_tag : 'span', car.bmw}} )
|
||||||
expected = %( <span id="good">bad</span> )
|
expected = %( <span id="good">bad</span> )
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multiple_pipings
|
def test_multiple_pipings
|
||||||
text = %( {{ best_cars | cite_funny | paragraph }} )
|
text = %( {{ best_cars | cite_funny | paragraph }} )
|
||||||
expected = %( <p>LOL: bmw</p> )
|
expected = %( <p>LOL: bmw</p> )
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_link_to
|
def test_link_to
|
||||||
text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} )
|
text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} )
|
||||||
expected = %( <a href="http://typo.leetsoft.com">Typo</a> )
|
expected = %( <a href="http://typo.leetsoft.com">Typo</a> )
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
assert_equal(expected, Template.parse(text).render!(@assigns, filters: [FunnyFilter]))
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class ParsingQuirksTest < Minitest::Test
|
|||||||
def test_meaningless_parens_lax
|
def test_meaningless_parens_lax
|
||||||
with_error_mode(:lax) do
|
with_error_mode(:lax) do
|
||||||
assigns = { 'b' => 'bar', 'c' => 'baz' }
|
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)
|
assert_template_result(' YES ', "{% if #{markup} %} YES {% endif %}", assigns)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,28 +16,28 @@ class SecurityTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_no_instance_eval
|
def test_no_instance_eval
|
||||||
text = %( {{ '1+1' | instance_eval }} )
|
text = %( {{ '1+1' | instance_eval }} )
|
||||||
expected = %( 1+1 )
|
expected = %( 1+1 )
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns))
|
assert_equal(expected, Template.parse(text).render!(@assigns))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_no_existing_instance_eval
|
def test_no_existing_instance_eval
|
||||||
text = %( {{ '1+1' | __instance_eval__ }} )
|
text = %( {{ '1+1' | __instance_eval__ }} )
|
||||||
expected = %( 1+1 )
|
expected = %( 1+1 )
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns))
|
assert_equal(expected, Template.parse(text).render!(@assigns))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_no_instance_eval_after_mixing_in_new_filter
|
def test_no_instance_eval_after_mixing_in_new_filter
|
||||||
text = %( {{ '1+1' | instance_eval }} )
|
text = %( {{ '1+1' | instance_eval }} )
|
||||||
expected = %( 1+1 )
|
expected = %( 1+1 )
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns))
|
assert_equal(expected, Template.parse(text).render!(@assigns))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_no_instance_eval_later_in_chain
|
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 )
|
expected = %( 1+1 + 1 )
|
||||||
|
|
||||||
assert_equal(expected, Template.parse(text).render!(@assigns, filters: SecurityFilter))
|
assert_equal(expected, Template.parse(text).render!(@assigns, filters: SecurityFilter))
|
||||||
@@ -68,13 +68,13 @@ class SecurityTest < Minitest::Test
|
|||||||
|
|
||||||
def test_max_depth_nested_blocks_does_not_raise_exception
|
def test_max_depth_nested_blocks_does_not_raise_exception
|
||||||
depth = Liquid::Block::MAX_DEPTH
|
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!)
|
assert_equal("rendered", Template.parse(code).render!)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_more_than_max_depth_nested_blocks_raises_exception
|
def test_more_than_max_depth_nested_blocks_raises_exception
|
||||||
depth = Liquid::Block::MAX_DEPTH + 1
|
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
|
assert_raises(Liquid::StackLevelError) do
|
||||||
Template.parse(code).render!
|
Template.parse(code).render!
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_when_property_is_sometimes_missing_puts_nils_last
|
def test_sort_when_property_is_sometimes_missing_puts_nils_last
|
||||||
input = [
|
input = [
|
||||||
{ "price" => 4, "handle" => "alpha" },
|
{ "price" => 4, "handle" => "alpha" },
|
||||||
{ "handle" => "beta" },
|
{ "handle" => "beta" },
|
||||||
{ "price" => 1, "handle" => "gamma" },
|
{ "price" => 1, "handle" => "gamma" },
|
||||||
@@ -235,7 +235,7 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_natural_when_property_is_sometimes_missing_puts_nils_last
|
def test_sort_natural_when_property_is_sometimes_missing_puts_nils_last
|
||||||
input = [
|
input = [
|
||||||
{ "price" => "4", "handle" => "alpha" },
|
{ "price" => "4", "handle" => "alpha" },
|
||||||
{ "handle" => "beta" },
|
{ "handle" => "beta" },
|
||||||
{ "price" => "1", "handle" => "gamma" },
|
{ "price" => "1", "handle" => "gamma" },
|
||||||
@@ -389,7 +389,7 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
|
|
||||||
def test_legacy_map_on_hashes_with_dynamic_key
|
def test_legacy_map_on_hashes_with_dynamic_key
|
||||||
template = "{% assign key = 'foo' %}{{ thing | map: key | map: 'bar' }}"
|
template = "{% assign key = 'foo' %}{{ thing | map: key | map: 'bar' }}"
|
||||||
hash = { "foo" => { "bar" => 42 } }
|
hash = { "foo" => { "bar" => 42 } }
|
||||||
assert_template_result("42", template, "thing" => hash)
|
assert_template_result("42", template, "thing" => hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -400,8 +400,8 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_map_over_proc
|
def test_map_over_proc
|
||||||
drop = TestDrop.new
|
drop = TestDrop.new
|
||||||
p = proc { drop }
|
p = proc { drop }
|
||||||
templ = '{{ procs | map: "test" }}'
|
templ = '{{ procs | map: "test" }}'
|
||||||
assert_template_result("testfoo", templ, "procs" => [p])
|
assert_template_result("testfoo", templ, "procs" => [p])
|
||||||
end
|
end
|
||||||
@@ -782,7 +782,7 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
private
|
private
|
||||||
|
|
||||||
def with_timezone(tz)
|
def with_timezone(tz)
|
||||||
old_tz = ENV['TZ']
|
old_tz = ENV['TZ']
|
||||||
ENV['TZ'] = tz
|
ENV['TZ'] = tz
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class BreakTagTest < Minitest::Test
|
|||||||
# tests that no weird errors are raised if break is called outside of a
|
# tests that no weird errors are raised if break is called outside of a
|
||||||
# block
|
# block
|
||||||
def test_break_with_no_block
|
def test_break_with_no_block
|
||||||
assigns = { 'i' => 1 }
|
assigns = { 'i' => 1 }
|
||||||
markup = '{% break %}'
|
markup = '{% break %}'
|
||||||
expected = ''
|
expected = ''
|
||||||
|
|
||||||
assert_template_result(expected, markup, assigns)
|
assert_template_result(expected, markup, assigns)
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class ContinueTagTest < Minitest::Test
|
|||||||
# tests that no weird errors are raised if continue is called outside of a
|
# tests that no weird errors are raised if continue is called outside of a
|
||||||
# block
|
# block
|
||||||
def test_continue_with_no_block
|
def test_continue_with_no_block
|
||||||
assigns = {}
|
assigns = {}
|
||||||
markup = '{% continue %}'
|
markup = '{% continue %}'
|
||||||
expected = ''
|
expected = ''
|
||||||
|
|
||||||
assert_template_result(expected, markup, assigns)
|
assert_template_result(expected, markup, assigns)
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_limiting_with_invalid_limit
|
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
|
template = <<-MKUP
|
||||||
{% for i in array limit: true offset: 1 %}
|
{% for i in array limit: true offset: 1 %}
|
||||||
{{ i }}
|
{{ i }}
|
||||||
@@ -120,7 +120,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_limiting_with_invalid_offset
|
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
|
template = <<-MKUP
|
||||||
{% for i in array limit: 1 offset: true %}
|
{% for i in array limit: 1 offset: true %}
|
||||||
{{ i }}
|
{{ i }}
|
||||||
@@ -134,8 +134,8 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_dynamic_variable_limiting
|
def test_dynamic_variable_limiting
|
||||||
assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] }
|
assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] }
|
||||||
assigns['limit'] = 2
|
assigns['limit'] = 2
|
||||||
assigns['offset'] = 2
|
assigns['offset'] = 2
|
||||||
|
|
||||||
assert_template_result('34', '{%for i in array limit: limit offset: offset %}{{ i }}{%endfor%}', assigns)
|
assert_template_result('34', '{%for i in array limit: limit offset: offset %}{{ i }}{%endfor%}', assigns)
|
||||||
@@ -152,8 +152,8 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_pause_resume
|
def test_pause_resume
|
||||||
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
|
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
|
||||||
markup = <<-MKUP
|
markup = <<-MKUP
|
||||||
{%for i in array.items limit: 3 %}{{i}}{%endfor%}
|
{%for i in array.items limit: 3 %}{{i}}{%endfor%}
|
||||||
next
|
next
|
||||||
{%for i in array.items offset:continue limit: 3 %}{{i}}{%endfor%}
|
{%for i in array.items offset:continue limit: 3 %}{{i}}{%endfor%}
|
||||||
@@ -171,8 +171,8 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_pause_resume_limit
|
def test_pause_resume_limit
|
||||||
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
|
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
|
||||||
markup = <<-MKUP
|
markup = <<-MKUP
|
||||||
{%for i in array.items limit:3 %}{{i}}{%endfor%}
|
{%for i in array.items limit:3 %}{{i}}{%endfor%}
|
||||||
next
|
next
|
||||||
{%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
|
{%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
|
||||||
@@ -190,8 +190,8 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_pause_resume_big_limit
|
def test_pause_resume_big_limit
|
||||||
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
|
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
|
||||||
markup = <<-MKUP
|
markup = <<-MKUP
|
||||||
{%for i in array.items limit:3 %}{{i}}{%endfor%}
|
{%for i in array.items limit:3 %}{{i}}{%endfor%}
|
||||||
next
|
next
|
||||||
{%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
|
{%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
|
||||||
@@ -209,8 +209,8 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_pause_resume_big_offset
|
def test_pause_resume_big_offset
|
||||||
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
|
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
|
||||||
markup = '{%for i in array.items limit:3 %}{{i}}{%endfor%}
|
markup = '{%for i in array.items limit:3 %}{{i}}{%endfor%}
|
||||||
next
|
next
|
||||||
{%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
|
{%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
|
||||||
next
|
next
|
||||||
@@ -226,26 +226,26 @@ HERE
|
|||||||
def test_for_with_break
|
def test_for_with_break
|
||||||
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } }
|
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 = ""
|
expected = ""
|
||||||
assert_template_result(expected, markup, assigns)
|
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"
|
expected = "1"
|
||||||
assert_template_result(expected, markup, assigns)
|
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 = ""
|
expected = ""
|
||||||
assert_template_result(expected, markup, assigns)
|
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"
|
expected = "1234"
|
||||||
assert_template_result(expected, markup, assigns)
|
assert_template_result(expected, markup, assigns)
|
||||||
|
|
||||||
# tests to ensure it only breaks out of the local for loop
|
# tests to ensure it only breaks out of the local for loop
|
||||||
# and not all of them.
|
# and not all of them.
|
||||||
assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] }
|
assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] }
|
||||||
markup = '{% for item in array %}' \
|
markup = '{% for item in array %}' \
|
||||||
'{% for i in item %}' \
|
'{% for i in item %}' \
|
||||||
'{% if i == 1 %}' \
|
'{% if i == 1 %}' \
|
||||||
'{% break %}' \
|
'{% break %}' \
|
||||||
@@ -257,8 +257,8 @@ HERE
|
|||||||
assert_template_result(expected, markup, assigns)
|
assert_template_result(expected, markup, assigns)
|
||||||
|
|
||||||
# test break does nothing when unreached
|
# test break does nothing when unreached
|
||||||
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } }
|
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } }
|
||||||
markup = '{% for i in array.items %}{% if i == 9999 %}{% break %}{% endif %}{{ i }}{% endfor %}'
|
markup = '{% for i in array.items %}{% if i == 9999 %}{% break %}{% endif %}{{ i }}{% endfor %}'
|
||||||
expected = '12345'
|
expected = '12345'
|
||||||
assert_template_result(expected, markup, assigns)
|
assert_template_result(expected, markup, assigns)
|
||||||
end
|
end
|
||||||
@@ -266,29 +266,29 @@ HERE
|
|||||||
def test_for_with_continue
|
def test_for_with_continue
|
||||||
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } }
|
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 = ""
|
expected = ""
|
||||||
assert_template_result(expected, markup, assigns)
|
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"
|
expected = "12345"
|
||||||
assert_template_result(expected, markup, assigns)
|
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 = ""
|
expected = ""
|
||||||
assert_template_result(expected, markup, assigns)
|
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"
|
expected = "123"
|
||||||
assert_template_result(expected, markup, assigns)
|
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"
|
expected = "1245"
|
||||||
assert_template_result(expected, markup, assigns)
|
assert_template_result(expected, markup, assigns)
|
||||||
|
|
||||||
# tests to ensure it only continues the local for loop and not all of them.
|
# tests to ensure it only continues the local for loop and not all of them.
|
||||||
assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] }
|
assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] }
|
||||||
markup = '{% for item in array %}' \
|
markup = '{% for item in array %}' \
|
||||||
'{% for i in item %}' \
|
'{% for i in item %}' \
|
||||||
'{% if i == 1 %}' \
|
'{% if i == 1 %}' \
|
||||||
'{% continue %}' \
|
'{% continue %}' \
|
||||||
@@ -300,8 +300,8 @@ HERE
|
|||||||
assert_template_result(expected, markup, assigns)
|
assert_template_result(expected, markup, assigns)
|
||||||
|
|
||||||
# test continue does nothing when unreached
|
# test continue does nothing when unreached
|
||||||
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } }
|
assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } }
|
||||||
markup = '{% for i in array.items %}{% if i == 9999 %}{% continue %}{% endif %}{{ i }}{% endfor %}'
|
markup = '{% for i in array.items %}{% if i == 9999 %}{% continue %}{% endif %}{{ i }}{% endfor %}'
|
||||||
expected = '12345'
|
expected = '12345'
|
||||||
assert_template_result(expected, markup, assigns)
|
assert_template_result(expected, markup, assigns)
|
||||||
end
|
end
|
||||||
@@ -389,8 +389,8 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_iterate_with_each_when_no_limit_applied
|
def test_iterate_with_each_when_no_limit_applied
|
||||||
loader = LoaderDrop.new([1, 2, 3, 4, 5])
|
loader = LoaderDrop.new([1, 2, 3, 4, 5])
|
||||||
assigns = { 'items' => loader }
|
assigns = { 'items' => loader }
|
||||||
expected = '12345'
|
expected = '12345'
|
||||||
template = '{% for item in items %}{{item}}{% endfor %}'
|
template = '{% for item in items %}{{item}}{% endfor %}'
|
||||||
assert_template_result(expected, template, assigns)
|
assert_template_result(expected, template, assigns)
|
||||||
@@ -399,8 +399,8 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_iterate_with_load_slice_when_limit_applied
|
def test_iterate_with_load_slice_when_limit_applied
|
||||||
loader = LoaderDrop.new([1, 2, 3, 4, 5])
|
loader = LoaderDrop.new([1, 2, 3, 4, 5])
|
||||||
assigns = { 'items' => loader }
|
assigns = { 'items' => loader }
|
||||||
expected = '1'
|
expected = '1'
|
||||||
template = '{% for item in items limit:1 %}{{item}}{% endfor %}'
|
template = '{% for item in items limit:1 %}{{item}}{% endfor %}'
|
||||||
assert_template_result(expected, template, assigns)
|
assert_template_result(expected, template, assigns)
|
||||||
@@ -409,8 +409,8 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_iterate_with_load_slice_when_limit_and_offset_applied
|
def test_iterate_with_load_slice_when_limit_and_offset_applied
|
||||||
loader = LoaderDrop.new([1, 2, 3, 4, 5])
|
loader = LoaderDrop.new([1, 2, 3, 4, 5])
|
||||||
assigns = { 'items' => loader }
|
assigns = { 'items' => loader }
|
||||||
expected = '34'
|
expected = '34'
|
||||||
template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}'
|
template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}'
|
||||||
assert_template_result(expected, template, assigns)
|
assert_template_result(expected, template, assigns)
|
||||||
@@ -419,11 +419,11 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_iterate_with_load_slice_returns_same_results_as_without
|
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 }
|
loader_assigns = { 'items' => loader }
|
||||||
array_assigns = { 'items' => [1, 2, 3, 4, 5] }
|
array_assigns = { 'items' => [1, 2, 3, 4, 5] }
|
||||||
expected = '34'
|
expected = '34'
|
||||||
template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}'
|
template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}'
|
||||||
assert_template_result(expected, template, loader_assigns)
|
assert_template_result(expected, template, loader_assigns)
|
||||||
assert_template_result(expected, template, array_assigns)
|
assert_template_result(expected, template, array_assigns)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class IfElseTagTest < Minitest::Test
|
|||||||
|
|
||||||
def test_comparison_of_strings_containing_and_or_or
|
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"
|
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)
|
assert_template_result(' YES ', "{% if #{awful_markup} %} YES {% endif %}", assigns)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -54,16 +54,16 @@ class CountingFileSystem
|
|||||||
attr_reader :count
|
attr_reader :count
|
||||||
def read_template_file(_template_path)
|
def read_template_file(_template_path)
|
||||||
@count ||= 0
|
@count ||= 0
|
||||||
@count += 1
|
@count += 1
|
||||||
'from CountingFileSystem'
|
'from CountingFileSystem'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class CustomInclude < Liquid::Tag
|
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)
|
def initialize(tag_name, markup, tokens)
|
||||||
markup =~ Syntax
|
markup =~ SYNTAX
|
||||||
@template_name = Regexp.last_match(1)
|
@template_name = Regexp.last_match(1)
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
|
|
||||||
with_taint_mode :error do
|
with_taint_mode :error do
|
||||||
template = Liquid::Template.parse('{% render "snippet", unsafe: unsafe %}')
|
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)
|
template.render(context)
|
||||||
|
|
||||||
assert_equal [Liquid::TaintedError], template.errors.map(&:class)
|
assert_equal [Liquid::TaintedError], template.errors.map(&:class)
|
||||||
@@ -60,7 +60,7 @@ class RenderTagTest < Minitest::Test
|
|||||||
|
|
||||||
with_taint_mode :warn do
|
with_taint_mode :warn do
|
||||||
template = Liquid::Template.parse('{% render "snippet", unsafe: unsafe %}')
|
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)
|
template.render(context)
|
||||||
|
|
||||||
assert_equal [Liquid::TaintedError], context.warnings.map(&:class)
|
assert_equal [Liquid::TaintedError], context.warnings.map(&:class)
|
||||||
@@ -205,4 +205,13 @@ class RenderTagTest < Minitest::Test
|
|||||||
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
||||||
"{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
"{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_render_tag_forloop
|
||||||
|
Liquid::Template.file_system = StubFileSystem.new(
|
||||||
|
'product' => "Product: {{ product.title }} {% if forloop.first %}first{% endif %} {% if forloop.last %}last{% endif %} index:{{ forloop.index }} ",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_template_result("Product: Draft 151cm first index:1 Product: Element 155cm last index:2 ",
|
||||||
|
"{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ class StandardTagTest < Minitest::Test
|
|||||||
|
|
||||||
def test_assign_from_case
|
def test_assign_from_case
|
||||||
# Example from the shopify forums
|
# 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)
|
template = Liquid::Template.parse(code)
|
||||||
assert_equal("menswear", template.render!("collection" => { 'handle' => 'menswear-jackets' }))
|
assert_equal("menswear", template.render!("collection" => { 'handle' => 'menswear-jackets' }))
|
||||||
assert_equal("menswear", template.render!("collection" => { 'handle' => 'menswear-t-shirts' }))
|
assert_equal("menswear", template.render!("collection" => { 'handle' => 'menswear-t-shirts' }))
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class TemplateTest < Minitest::Test
|
|||||||
t = Template.new
|
t = Template.new
|
||||||
t.assigns['number'] = -> {
|
t.assigns['number'] = -> {
|
||||||
@global ||= 0
|
@global ||= 0
|
||||||
@global += 1
|
@global += 1
|
||||||
}
|
}
|
||||||
assert_equal('1', t.parse("{{number}}").render!)
|
assert_equal('1', t.parse("{{number}}").render!)
|
||||||
assert_equal('1', t.parse("{{number}}").render!)
|
assert_equal('1', t.parse("{{number}}").render!)
|
||||||
@@ -95,7 +95,7 @@ class TemplateTest < Minitest::Test
|
|||||||
t = Template.new
|
t = Template.new
|
||||||
assigns = { 'number' => -> {
|
assigns = { 'number' => -> {
|
||||||
@global ||= 0
|
@global ||= 0
|
||||||
@global += 1
|
@global += 1
|
||||||
} }
|
} }
|
||||||
assert_equal('1', t.parse("{{number}}").render!(assigns))
|
assert_equal('1', t.parse("{{number}}").render!(assigns))
|
||||||
assert_equal('1', t.parse("{{number}}").render!(assigns))
|
assert_equal('1', t.parse("{{number}}").render!(assigns))
|
||||||
@@ -243,7 +243,7 @@ class TemplateTest < Minitest::Test
|
|||||||
|
|
||||||
def test_exception_renderer_that_returns_string
|
def test_exception_renderer_that_returns_string
|
||||||
exception = nil
|
exception = nil
|
||||||
handler = ->(e) {
|
handler = ->(e) {
|
||||||
exception = e
|
exception = e
|
||||||
'<!-- error -->'
|
'<!-- error -->'
|
||||||
}
|
}
|
||||||
@@ -267,20 +267,20 @@ class TemplateTest < Minitest::Test
|
|||||||
|
|
||||||
def test_global_filter_option_on_render
|
def test_global_filter_option_on_render
|
||||||
global_filter_proc = ->(output) { "#{output} filtered" }
|
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)
|
assert_equal('bob filtered', rendered_template)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_global_filter_option_when_native_filters_exist
|
def test_global_filter_option_when_native_filters_exist
|
||||||
global_filter_proc = ->(output) { "#{output} filtered" }
|
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)
|
assert_equal('BOB filtered', rendered_template)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_undefined_variables
|
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)
|
result = t.render({ 'x' => 33, 'z' => { 'a' => 32, 'c' => { 'e' => 31 } } }, strict_variables: true)
|
||||||
|
|
||||||
assert_equal('33 32 ', result)
|
assert_equal('33 32 ', result)
|
||||||
@@ -295,8 +295,8 @@ class TemplateTest < Minitest::Test
|
|||||||
|
|
||||||
def test_nil_value_does_not_raise
|
def test_nil_value_does_not_raise
|
||||||
Liquid::Template.error_mode = :strict
|
Liquid::Template.error_mode = :strict
|
||||||
t = Template.parse("some{{x}}thing")
|
t = Template.parse("some{{x}}thing")
|
||||||
result = t.render!({ 'x' => nil }, strict_variables: true)
|
result = t.render!({ 'x' => nil }, strict_variables: true)
|
||||||
|
|
||||||
assert_equal(0, t.errors.count)
|
assert_equal(0, t.errors.count)
|
||||||
assert_equal('something', result)
|
assert_equal('something', result)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class TrimModeTest < Minitest::Test
|
|||||||
# Make sure the trim isn't applied to standard tags
|
# Make sure the trim isn't applied to standard tags
|
||||||
def test_standard_tags
|
def test_standard_tags
|
||||||
whitespace = ' '
|
whitespace = ' '
|
||||||
text = <<-END_TEMPLATE
|
text = <<-END_TEMPLATE
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
{% if true %}
|
{% if true %}
|
||||||
@@ -110,58 +110,58 @@ class TrimModeTest < Minitest::Test
|
|||||||
|
|
||||||
# Make sure the trim isn't too agressive
|
# Make sure the trim isn't too agressive
|
||||||
def test_no_trim_output
|
def test_no_trim_output
|
||||||
text = '<p>{{- \'John\' -}}</p>'
|
text = '<p>{{- \'John\' -}}</p>'
|
||||||
expected = '<p>John</p>'
|
expected = '<p>John</p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Make sure the trim isn't too agressive
|
# Make sure the trim isn't too agressive
|
||||||
def test_no_trim_tags
|
def test_no_trim_tags
|
||||||
text = '<p>{%- if true -%}yes{%- endif -%}</p>'
|
text = '<p>{%- if true -%}yes{%- endif -%}</p>'
|
||||||
expected = '<p>yes</p>'
|
expected = '<p>yes</p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
text = '<p>{%- if false -%}no{%- endif -%}</p>'
|
text = '<p>{%- if false -%}no{%- endif -%}</p>'
|
||||||
expected = '<p></p>'
|
expected = '<p></p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_single_line_outer_tag
|
def test_single_line_outer_tag
|
||||||
text = '<p> {%- if true %} yes {% endif -%} </p>'
|
text = '<p> {%- if true %} yes {% endif -%} </p>'
|
||||||
expected = '<p> yes </p>'
|
expected = '<p> yes </p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
text = '<p> {%- if false %} no {% endif -%} </p>'
|
text = '<p> {%- if false %} no {% endif -%} </p>'
|
||||||
expected = '<p></p>'
|
expected = '<p></p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_single_line_inner_tag
|
def test_single_line_inner_tag
|
||||||
text = '<p> {% if true -%} yes {%- endif %} </p>'
|
text = '<p> {% if true -%} yes {%- endif %} </p>'
|
||||||
expected = '<p> yes </p>'
|
expected = '<p> yes </p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
text = '<p> {% if false -%} no {%- endif %} </p>'
|
text = '<p> {% if false -%} no {%- endif %} </p>'
|
||||||
expected = '<p> </p>'
|
expected = '<p> </p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_single_line_post_tag
|
def test_single_line_post_tag
|
||||||
text = '<p> {% if true -%} yes {% endif -%} </p>'
|
text = '<p> {% if true -%} yes {% endif -%} </p>'
|
||||||
expected = '<p> yes </p>'
|
expected = '<p> yes </p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
text = '<p> {% if false -%} no {% endif -%} </p>'
|
text = '<p> {% if false -%} no {% endif -%} </p>'
|
||||||
expected = '<p> </p>'
|
expected = '<p> </p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_single_line_pre_tag
|
def test_single_line_pre_tag
|
||||||
text = '<p> {%- if true %} yes {%- endif %} </p>'
|
text = '<p> {%- if true %} yes {%- endif %} </p>'
|
||||||
expected = '<p> yes </p>'
|
expected = '<p> yes </p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
text = '<p> {%- if false %} no {%- endif %} </p>'
|
text = '<p> {%- if false %} no {%- endif %} </p>'
|
||||||
expected = '<p> </p>'
|
expected = '<p> </p>'
|
||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
end
|
end
|
||||||
@@ -330,7 +330,7 @@ class TrimModeTest < Minitest::Test
|
|||||||
assert_template_result(expected, text)
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
whitespace = ' '
|
whitespace = ' '
|
||||||
text = <<-END_TEMPLATE
|
text = <<-END_TEMPLATE
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
{% if false -%}
|
{% if false -%}
|
||||||
@@ -504,7 +504,7 @@ class TrimModeTest < Minitest::Test
|
|||||||
|
|
||||||
def test_raw_output
|
def test_raw_output
|
||||||
whitespace = ' '
|
whitespace = ' '
|
||||||
text = <<-END_TEMPLATE
|
text = <<-END_TEMPLATE
|
||||||
<div>
|
<div>
|
||||||
{% raw %}
|
{% raw %}
|
||||||
{%- if true -%}
|
{%- if true -%}
|
||||||
|
|||||||
@@ -52,13 +52,13 @@ class VariableTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_preset_assigns
|
def test_preset_assigns
|
||||||
template = Template.parse(%({{ test }}))
|
template = Template.parse(%({{ test }}))
|
||||||
template.assigns['test'] = 'worked'
|
template.assigns['test'] = 'worked'
|
||||||
assert_equal('worked', template.render!)
|
assert_equal('worked', template.render!)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_reuse_parsed_template
|
def test_reuse_parsed_template
|
||||||
template = Template.parse(%({{ greeting }} {{ name }}))
|
template = Template.parse(%({{ greeting }} {{ name }}))
|
||||||
template.assigns['greeting'] = 'Goodbye'
|
template.assigns['greeting'] = 'Goodbye'
|
||||||
assert_equal('Hello Tobi', template.render!('greeting' => 'Hello', 'name' => 'Tobi'))
|
assert_equal('Hello Tobi', template.render!('greeting' => 'Hello', 'name' => 'Tobi'))
|
||||||
assert_equal('Hello ', template.render!('greeting' => 'Hello', 'unknown' => 'Tobi'))
|
assert_equal('Hello ', template.render!('greeting' => 'Hello', 'unknown' => 'Tobi'))
|
||||||
@@ -68,7 +68,7 @@ class VariableTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_assigns_not_polluted_from_template
|
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'
|
template.assigns['test'] = 'baz'
|
||||||
assert_equal('bazbar', template.render!)
|
assert_equal('bazbar', template.render!)
|
||||||
assert_equal('bazbar', template.render!)
|
assert_equal('bazbar', template.render!)
|
||||||
@@ -77,8 +77,8 @@ class VariableTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_hash_with_default_proc
|
def test_hash_with_default_proc
|
||||||
template = Template.parse(%(Hello {{ test }}))
|
template = Template.parse(%(Hello {{ test }}))
|
||||||
assigns = Hash.new { |_h, k| raise "Unknown variable '#{k}'" }
|
assigns = Hash.new { |_h, k| raise "Unknown variable '#{k}'" }
|
||||||
assigns['test'] = 'Tobi'
|
assigns['test'] = 'Tobi'
|
||||||
assert_equal('Hello Tobi', template.render!(assigns))
|
assert_equal('Hello Tobi', template.render!(assigns))
|
||||||
assigns.delete('test')
|
assigns.delete('test')
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ class StubFileSystem
|
|||||||
|
|
||||||
def initialize(values)
|
def initialize(values)
|
||||||
@file_read_count = 0
|
@file_read_count = 0
|
||||||
@values = values
|
@values = values
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_template_file(template_path)
|
def read_template_file(template_path)
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class BlockUnitTest < Minitest::Test
|
|||||||
|
|
||||||
assert_equal 'hello', template.render
|
assert_equal 'hello', template.render
|
||||||
|
|
||||||
buf = +''
|
buf = +''
|
||||||
output = template.render({}, output: buf)
|
output = template.render({}, output: buf)
|
||||||
assert_equal 'hello', output
|
assert_equal 'hello', output
|
||||||
assert_equal 'hello', buf
|
assert_equal 'hello', buf
|
||||||
@@ -81,7 +81,7 @@ class BlockUnitTest < Minitest::Test
|
|||||||
|
|
||||||
assert_equal 'foohellobar', template.render
|
assert_equal 'foohellobar', template.render
|
||||||
|
|
||||||
buf = +''
|
buf = +''
|
||||||
output = template.render({}, output: buf)
|
output = template.render({}, output: buf)
|
||||||
assert_equal 'foohellobar', output
|
assert_equal 'foohellobar', output
|
||||||
assert_equal 'foohellobar', buf
|
assert_equal 'foohellobar', buf
|
||||||
|
|||||||
@@ -75,9 +75,9 @@ class ConditionUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_contains_works_on_arrays
|
def test_contains_works_on_arrays
|
||||||
@context = Liquid::Context.new
|
@context = Liquid::Context.new
|
||||||
@context['array'] = [1, 2, 3, 4, 5]
|
@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_false(array_expr, 'contains', 0)
|
||||||
assert_evaluates_true(array_expr, 'contains', 1)
|
assert_evaluates_true(array_expr, 'contains', 1)
|
||||||
@@ -142,7 +142,7 @@ class ConditionUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_left_or_right_may_contain_operators
|
def test_left_or_right_may_contain_operators
|
||||||
@context = Liquid::Context.new
|
@context = Liquid::Context.new
|
||||||
@context['one'] = @context['another'] = "gnomeslab-and-or-liquid"
|
@context['one'] = @context['another'] = "gnomeslab-and-or-liquid"
|
||||||
|
|
||||||
assert_evaluates_true(VariableLookup.new("one"), '==', VariableLookup.new("another"))
|
assert_evaluates_true(VariableLookup.new("one"), '==', VariableLookup.new("another"))
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ end
|
|||||||
class CounterDrop < Liquid::Drop
|
class CounterDrop < Liquid::Drop
|
||||||
def count
|
def count
|
||||||
@count ||= 0
|
@count ||= 0
|
||||||
@count += 1
|
@count += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -55,9 +55,9 @@ class ArrayLike
|
|||||||
end
|
end
|
||||||
|
|
||||||
def [](index)
|
def [](index)
|
||||||
@counts ||= []
|
@counts ||= []
|
||||||
@counts[index] ||= 0
|
@counts[index] ||= 0
|
||||||
@counts[index] += 1
|
@counts[index] += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_liquid
|
def to_liquid
|
||||||
@@ -265,7 +265,7 @@ class ContextUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_access_hashes_with_hash_notation
|
def test_access_hashes_with_hash_notation
|
||||||
@context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
|
@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(5, @context['products["count"]'])
|
||||||
assert_equal('deepsnow', @context['products["tags"][0]'])
|
assert_equal('deepsnow', @context['products["tags"][0]'])
|
||||||
@@ -285,8 +285,8 @@ class ContextUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_access_hashes_with_hash_access_variables
|
def test_access_hashes_with_hash_access_variables
|
||||||
@context['var'] = 'tags'
|
@context['var'] = 'tags'
|
||||||
@context['nested'] = { 'var' => 'tags' }
|
@context['nested'] = { 'var' => 'tags' }
|
||||||
@context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
|
@context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
|
||||||
|
|
||||||
assert_equal('deepsnow', @context['products[var].first'])
|
assert_equal('deepsnow', @context['products[var].first'])
|
||||||
@@ -295,7 +295,7 @@ class ContextUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_hash_notation_only_for_hash_access
|
def test_hash_notation_only_for_hash_access
|
||||||
@context['array'] = [1, 2, 3, 4, 5]
|
@context['array'] = [1, 2, 3, 4, 5]
|
||||||
@context['hash'] = { 'first' => 'Hello' }
|
@context['hash'] = { 'first' => 'Hello' }
|
||||||
|
|
||||||
assert_equal(1, @context['array.first'])
|
assert_equal(1, @context['array.first'])
|
||||||
assert_nil(@context['array["first"]'])
|
assert_nil(@context['array["first"]'])
|
||||||
@@ -407,7 +407,7 @@ class ContextUnitTest < Minitest::Test
|
|||||||
def test_lambda_is_called_once
|
def test_lambda_is_called_once
|
||||||
@context['callcount'] = proc {
|
@context['callcount'] = proc {
|
||||||
@global ||= 0
|
@global ||= 0
|
||||||
@global += 1
|
@global += 1
|
||||||
@global.to_s
|
@global.to_s
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,7 +421,7 @@ class ContextUnitTest < Minitest::Test
|
|||||||
def test_nested_lambda_is_called_once
|
def test_nested_lambda_is_called_once
|
||||||
@context['callcount'] = { "lambda" => proc {
|
@context['callcount'] = { "lambda" => proc {
|
||||||
@global ||= 0
|
@global ||= 0
|
||||||
@global += 1
|
@global += 1
|
||||||
@global.to_s
|
@global.to_s
|
||||||
} }
|
} }
|
||||||
|
|
||||||
@@ -435,7 +435,7 @@ class ContextUnitTest < Minitest::Test
|
|||||||
def test_lambda_in_array_is_called_once
|
def test_lambda_in_array_is_called_once
|
||||||
@context['callcount'] = [1, 2, proc {
|
@context['callcount'] = [1, 2, proc {
|
||||||
@global ||= 0
|
@global ||= 0
|
||||||
@global += 1
|
@global += 1
|
||||||
@global.to_s
|
@global.to_s
|
||||||
}, 4, 5]
|
}, 4, 5]
|
||||||
|
|
||||||
@@ -507,15 +507,15 @@ class ContextUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_new_isolated_subcontext_inherits_static_environment
|
def test_new_isolated_subcontext_inherits_static_environment
|
||||||
super_context = Context.build(static_environments: { 'my_environment_value' => 'my value' })
|
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'])
|
assert_equal('my value', subcontext['my_environment_value'])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_new_isolated_subcontext_inherits_resource_limits
|
def test_new_isolated_subcontext_inherits_resource_limits
|
||||||
resource_limits = ResourceLimits.new({})
|
resource_limits = ResourceLimits.new({})
|
||||||
super_context = Context.new({}, {}, {}, false, resource_limits)
|
super_context = Context.new({}, {}, {}, false, resource_limits)
|
||||||
subcontext = super_context.new_isolated_subcontext
|
subcontext = super_context.new_isolated_subcontext
|
||||||
assert_equal(resource_limits, subcontext.resource_limits)
|
assert_equal(resource_limits, subcontext.resource_limits)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -532,19 +532,19 @@ class ContextUnitTest < Minitest::Test
|
|||||||
}
|
}
|
||||||
super_context = Context.new({}, {}, StaticRegisters.new(registers))
|
super_context = Context.new({}, {}, StaticRegisters.new(registers))
|
||||||
super_context.registers[:my_register] = :my_alt_value
|
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])
|
assert_equal(:my_value, subcontext.registers[:my_register])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_new_isolated_subcontext_inherits_static_registers
|
def test_new_isolated_subcontext_inherits_static_registers
|
||||||
super_context = Context.build(registers: { my_register: :my_value })
|
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])
|
assert_equal(:my_value, subcontext.registers[:my_register])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_new_isolated_subcontext_registers_do_not_pollute_context
|
def test_new_isolated_subcontext_registers_do_not_pollute_context
|
||||||
super_context = Context.build(registers: { my_register: :my_value })
|
super_context = Context.build(registers: { my_register: :my_value })
|
||||||
subcontext = super_context.new_isolated_subcontext
|
subcontext = super_context.new_isolated_subcontext
|
||||||
subcontext.registers[:my_register] = :my_alt_value
|
subcontext.registers[:my_register] = :my_alt_value
|
||||||
assert_equal(:my_value, super_context.registers[:my_register])
|
assert_equal(:my_value, super_context.registers[:my_register])
|
||||||
end
|
end
|
||||||
@@ -558,8 +558,8 @@ class ContextUnitTest < Minitest::Test
|
|||||||
|
|
||||||
super_context = Context.new
|
super_context = Context.new
|
||||||
super_context.add_filters([my_filter])
|
super_context.add_filters([my_filter])
|
||||||
subcontext = super_context.new_isolated_subcontext
|
subcontext = super_context.new_isolated_subcontext
|
||||||
template = Template.parse('{{ 123 | my_filter }}')
|
template = Template.parse('{{ 123 | my_filter }}')
|
||||||
assert_equal('my filter result', template.render(subcontext))
|
assert_equal('my filter result', template.render(subcontext))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class PartialCacheUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_reads_from_the_file_system_only_once_per_file
|
def test_reads_from_the_file_system_only_once_per_file
|
||||||
file_system = StubFileSystem.new('my_partial' => 'some partial body')
|
file_system = StubFileSystem.new('my_partial' => 'some partial body')
|
||||||
context = Liquid::Context.build(
|
context = Liquid::Context.build(
|
||||||
registers: { file_system: file_system }
|
registers: { file_system: file_system }
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class PartialCacheUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_cache_state_is_stored_per_context
|
def test_cache_state_is_stored_per_context
|
||||||
parse_context = Liquid::ParseContext.new
|
parse_context = Liquid::ParseContext.new
|
||||||
shared_file_system = StubFileSystem.new(
|
shared_file_system = StubFileSystem.new(
|
||||||
'my_partial' => 'my shared value'
|
'my_partial' => 'my shared value'
|
||||||
)
|
)
|
||||||
@@ -71,7 +71,7 @@ class PartialCacheUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_cache_is_not_broken_when_a_different_parse_context_is_used
|
def test_cache_is_not_broken_when_a_different_parse_context_is_used
|
||||||
file_system = StubFileSystem.new('my_partial' => 'some partial body')
|
file_system = StubFileSystem.new('my_partial' => 'some partial body')
|
||||||
context = Liquid::Context.build(
|
context = Liquid::Context.build(
|
||||||
registers: { file_system: file_system }
|
registers: { file_system: file_system }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,41 +6,41 @@ class RegexpUnitTest < Minitest::Test
|
|||||||
include Liquid
|
include Liquid
|
||||||
|
|
||||||
def test_empty
|
def test_empty
|
||||||
assert_equal([], ''.scan(QuotedFragment))
|
assert_equal [], ''.scan(QUOTED_FRAGMENT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_quote
|
def test_quote
|
||||||
assert_equal(['"arg 1"'], '"arg 1"'.scan(QuotedFragment))
|
assert_equal ['"arg 1"'], '"arg 1"'.scan(QUOTED_FRAGMENT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_words
|
def test_words
|
||||||
assert_equal(['arg1', 'arg2'], 'arg1 arg2'.scan(QuotedFragment))
|
assert_equal ['arg1', 'arg2'], 'arg1 arg2'.scan(QUOTED_FRAGMENT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tags
|
def test_tags
|
||||||
assert_equal(['<tr>', '</tr>'], '<tr> </tr>'.scan(QuotedFragment))
|
assert_equal ['<tr>', '</tr>'], '<tr> </tr>'.scan(QUOTED_FRAGMENT)
|
||||||
assert_equal(['<tr></tr>'], '<tr></tr>'.scan(QuotedFragment))
|
assert_equal ['<tr></tr>'], '<tr></tr>'.scan(QUOTED_FRAGMENT)
|
||||||
assert_equal(['<style', 'class="hello">', '</style>'], %(<style class="hello">' </style>).scan(QuotedFragment))
|
assert_equal ['<style', 'class="hello">', '</style>'], %(<style class="hello">' </style>).scan(QUOTED_FRAGMENT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_double_quoted_words
|
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
|
end
|
||||||
|
|
||||||
def test_single_quoted_words
|
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
|
end
|
||||||
|
|
||||||
def test_quoted_words_in_the_middle
|
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
|
end
|
||||||
|
|
||||||
def test_variable_parser
|
def test_variable_parser
|
||||||
assert_equal(['var'], 'var'.scan(VariableParser))
|
assert_equal ['var'], 'var'.scan(VARIABLE_PARSER)
|
||||||
assert_equal(['var', 'method'], 'var.method'.scan(VariableParser))
|
assert_equal ['var', 'method'], 'var.method'.scan(VARIABLE_PARSER)
|
||||||
assert_equal(['var', '[method]'], 'var[method]'.scan(VariableParser))
|
assert_equal ['var', '[method]'], 'var[method]'.scan(VARIABLE_PARSER)
|
||||||
assert_equal(['var', '[method]', '[0]'], 'var[method][0]'.scan(VariableParser))
|
assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VARIABLE_PARSER)
|
||||||
assert_equal(['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser))
|
assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VARIABLE_PARSER)
|
||||||
assert_equal(['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser))
|
assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VARIABLE_PARSER)
|
||||||
end
|
end
|
||||||
end # RegexpTest
|
end # RegexpTest
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ class StaticRegistersUnitTest < Minitest::Test
|
|||||||
include Liquid
|
include Liquid
|
||||||
|
|
||||||
def set
|
def set
|
||||||
static_register = StaticRegisters.new
|
static_register = StaticRegisters.new
|
||||||
static_register[nil] = true
|
static_register[nil] = true
|
||||||
static_register[1] = :one
|
static_register[1] = :one
|
||||||
static_register[:one] = "one"
|
static_register[:one] = "one"
|
||||||
static_register["two"] = "three"
|
static_register["two"] = "three"
|
||||||
static_register["two"] = 3
|
static_register["two"] = 3
|
||||||
static_register[false] = nil
|
static_register[false] = nil
|
||||||
@@ -77,10 +77,10 @@ class StaticRegistersUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_with_static
|
def set_with_static
|
||||||
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
|
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
|
||||||
static_register[nil] = false
|
static_register[nil] = false
|
||||||
static_register["two"] = 4
|
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 => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
|
||||||
assert_equal({ nil => false, "two" => 4, true => "foo" }, static_register.registers)
|
assert_equal({ nil => false, "two" => 4, true => "foo" }, static_register.registers)
|
||||||
@@ -154,23 +154,23 @@ class StaticRegistersUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_new_static_retains_static
|
def test_new_static_retains_static
|
||||||
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
|
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
|
||||||
static_register["one"] = 1
|
static_register["one"] = 1
|
||||||
static_register["two"] = 2
|
static_register["two"] = 2
|
||||||
static_register["three"] = 3
|
static_register["three"] = 3
|
||||||
|
|
||||||
new_register = StaticRegisters.new(static_register)
|
new_register = StaticRegisters.new(static_register)
|
||||||
assert_equal({}, new_register.registers)
|
assert_equal({}, new_register.registers)
|
||||||
|
|
||||||
new_register["one"] = 4
|
new_register["one"] = 4
|
||||||
new_register["two"] = 5
|
new_register["two"] = 5
|
||||||
new_register["three"] = 6
|
new_register["three"] = 6
|
||||||
|
|
||||||
newest_register = StaticRegisters.new(new_register)
|
newest_register = StaticRegisters.new(new_register)
|
||||||
assert_equal({}, newest_register.registers)
|
assert_equal({}, newest_register.registers)
|
||||||
|
|
||||||
newest_register["one"] = 7
|
newest_register["one"] = 7
|
||||||
newest_register["two"] = 8
|
newest_register["two"] = 8
|
||||||
newest_register["three"] = 9
|
newest_register["three"] = 9
|
||||||
|
|
||||||
assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers)
|
assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers)
|
||||||
@@ -182,23 +182,23 @@ class StaticRegistersUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_multiple_instances_are_unique
|
def test_multiple_instances_are_unique
|
||||||
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
|
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
|
||||||
static_register["one"] = 1
|
static_register["one"] = 1
|
||||||
static_register["two"] = 2
|
static_register["two"] = 2
|
||||||
static_register["three"] = 3
|
static_register["three"] = 3
|
||||||
|
|
||||||
new_register = StaticRegisters.new(foo: :bar)
|
new_register = StaticRegisters.new(foo: :bar)
|
||||||
assert_equal({}, new_register.registers)
|
assert_equal({}, new_register.registers)
|
||||||
|
|
||||||
new_register["one"] = 4
|
new_register["one"] = 4
|
||||||
new_register["two"] = 5
|
new_register["two"] = 5
|
||||||
new_register["three"] = 6
|
new_register["three"] = 6
|
||||||
|
|
||||||
newest_register = StaticRegisters.new(bar: :foo)
|
newest_register = StaticRegisters.new(bar: :foo)
|
||||||
assert_equal({}, newest_register.registers)
|
assert_equal({}, newest_register.registers)
|
||||||
|
|
||||||
newest_register["one"] = 7
|
newest_register["one"] = 7
|
||||||
newest_register["two"] = 8
|
newest_register["two"] = 8
|
||||||
newest_register["three"] = 9
|
newest_register["three"] = 9
|
||||||
|
|
||||||
assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers)
|
assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers)
|
||||||
@@ -210,9 +210,9 @@ class StaticRegistersUnitTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_can_update_static_directly_and_updates_all_instances
|
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 = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
|
||||||
static_register["one"] = 1
|
static_register["one"] = 1
|
||||||
static_register["two"] = 2
|
static_register["two"] = 2
|
||||||
static_register["three"] = 3
|
static_register["three"] = 3
|
||||||
|
|
||||||
new_register = StaticRegisters.new(static_register)
|
new_register = StaticRegisters.new(static_register)
|
||||||
@@ -220,9 +220,9 @@ class StaticRegistersUnitTest < Minitest::Test
|
|||||||
|
|
||||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
|
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
|
||||||
|
|
||||||
new_register["one"] = 4
|
new_register["one"] = 4
|
||||||
new_register["two"] = 5
|
new_register["two"] = 5
|
||||||
new_register["three"] = 6
|
new_register["three"] = 6
|
||||||
new_register.static["four"] = 10
|
new_register.static["four"] = 10
|
||||||
|
|
||||||
newest_register = StaticRegisters.new(new_register)
|
newest_register = StaticRegisters.new(new_register)
|
||||||
@@ -230,9 +230,9 @@ class StaticRegistersUnitTest < Minitest::Test
|
|||||||
|
|
||||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil, "four" => 10 }, new_register.static)
|
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil, "four" => 10 }, new_register.static)
|
||||||
|
|
||||||
newest_register["one"] = 7
|
newest_register["one"] = 7
|
||||||
newest_register["two"] = 8
|
newest_register["two"] = 8
|
||||||
newest_register["three"] = 9
|
newest_register["three"] = 9
|
||||||
new_register.static["four"] = 5
|
new_register.static["four"] = 5
|
||||||
new_register.static["five"] = 15
|
new_register.static["five"] = 15
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class TagUnitTest < Minitest::Test
|
|||||||
|
|
||||||
assert_equal 'hello', template.render
|
assert_equal 'hello', template.render
|
||||||
|
|
||||||
buf = +''
|
buf = +''
|
||||||
output = template.render({}, output: buf)
|
output = template.render({}, output: buf)
|
||||||
assert_equal 'hello', output
|
assert_equal 'hello', output
|
||||||
assert_equal 'hello', buf
|
assert_equal 'hello', buf
|
||||||
@@ -51,7 +51,7 @@ class TagUnitTest < Minitest::Test
|
|||||||
|
|
||||||
assert_equal 'foohellobar', template.render
|
assert_equal 'foohellobar', template.render
|
||||||
|
|
||||||
buf = +''
|
buf = +''
|
||||||
output = template.render({}, output: buf)
|
output = template.render({}, output: buf)
|
||||||
assert_equal 'foohellobar', output
|
assert_equal 'foohellobar', output
|
||||||
assert_equal 'foohellobar', buf
|
assert_equal 'foohellobar', buf
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class TemplateUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_with_cache_classes_tags_returns_the_same_class
|
def test_with_cache_classes_tags_returns_the_same_class
|
||||||
original_cache_setting = Liquid.cache_classes
|
original_cache_setting = Liquid.cache_classes
|
||||||
Liquid.cache_classes = true
|
Liquid.cache_classes = true
|
||||||
|
|
||||||
original_klass = Class.new
|
original_klass = Class.new
|
||||||
Object.send(:const_set, :CustomTag, original_klass)
|
Object.send(:const_set, :CustomTag, original_klass)
|
||||||
@@ -42,7 +42,7 @@ class TemplateUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_without_cache_classes_tags_reloads_the_class
|
def test_without_cache_classes_tags_reloads_the_class
|
||||||
original_cache_setting = Liquid.cache_classes
|
original_cache_setting = Liquid.cache_classes
|
||||||
Liquid.cache_classes = false
|
Liquid.cache_classes = false
|
||||||
|
|
||||||
original_klass = Class.new
|
original_klass = Class.new
|
||||||
Object.send(:const_set, :CustomTag, original_klass)
|
Object.send(:const_set, :CustomTag, original_klass)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class TokenizerTest < Minitest::Test
|
|||||||
|
|
||||||
def tokenize(source)
|
def tokenize(source)
|
||||||
tokenizer = Liquid::Tokenizer.new(source)
|
tokenizer = Liquid::Tokenizer.new(source)
|
||||||
tokens = []
|
tokens = []
|
||||||
while (t = tokenizer.shift)
|
while (t = tokenizer.shift)
|
||||||
tokens << t
|
tokens << t
|
||||||
end
|
end
|
||||||
@@ -42,7 +42,7 @@ class TokenizerTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tokenize_line_numbers(source)
|
def tokenize_line_numbers(source)
|
||||||
tokenizer = Liquid::Tokenizer.new(source, true)
|
tokenizer = Liquid::Tokenizer.new(source, true)
|
||||||
line_numbers = []
|
line_numbers = []
|
||||||
loop do
|
loop do
|
||||||
line_number = tokenizer.line_number
|
line_number = tokenizer.line_number
|
||||||
|
|||||||
Reference in New Issue
Block a user