liquid 4.0.3 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +89 -0
- data/README.md +10 -4
- data/lib/liquid/block.rb +31 -14
- data/lib/liquid/block_body.rb +169 -57
- data/lib/liquid/condition.rb +48 -21
- data/lib/liquid/context.rb +111 -52
- data/lib/liquid/document.rb +47 -9
- data/lib/liquid/drop.rb +4 -2
- data/lib/liquid/errors.rb +20 -18
- data/lib/liquid/expression.rb +28 -32
- data/lib/liquid/extensions.rb +2 -0
- data/lib/liquid/file_system.rb +6 -4
- data/lib/liquid/forloop_drop.rb +54 -4
- data/lib/liquid/i18n.rb +5 -3
- data/lib/liquid/interrupts.rb +3 -1
- data/lib/liquid/lexer.rb +30 -23
- data/lib/liquid/locales/en.yml +8 -5
- data/lib/liquid/parse_context.rb +20 -4
- data/lib/liquid/parse_tree_visitor.rb +2 -2
- data/lib/liquid/parser.rb +30 -18
- data/lib/liquid/parser_switching.rb +17 -3
- data/lib/liquid/partial_cache.rb +24 -0
- data/lib/liquid/profiler/hooks.rb +26 -14
- data/lib/liquid/profiler.rb +67 -86
- data/lib/liquid/range_lookup.rb +13 -3
- data/lib/liquid/registers.rb +51 -0
- data/lib/liquid/resource_limits.rb +47 -8
- data/lib/liquid/standardfilters.rb +551 -114
- data/lib/liquid/strainer_factory.rb +41 -0
- data/lib/liquid/strainer_template.rb +62 -0
- data/lib/liquid/tablerowloop_drop.rb +64 -5
- data/lib/liquid/tag/disableable.rb +22 -0
- data/lib/liquid/tag/disabler.rb +21 -0
- data/lib/liquid/tag.rb +28 -6
- data/lib/liquid/tags/assign.rb +36 -18
- data/lib/liquid/tags/break.rb +16 -3
- data/lib/liquid/tags/capture.rb +24 -18
- data/lib/liquid/tags/case.rb +61 -27
- data/lib/liquid/tags/comment.rb +18 -3
- data/lib/liquid/tags/continue.rb +16 -12
- data/lib/liquid/tags/cycle.rb +37 -25
- data/lib/liquid/tags/decrement.rb +22 -20
- data/lib/liquid/tags/echo.rb +41 -0
- data/lib/liquid/tags/for.rb +90 -87
- data/lib/liquid/tags/if.rb +50 -32
- data/lib/liquid/tags/ifchanged.rb +11 -10
- data/lib/liquid/tags/include.rb +49 -60
- data/lib/liquid/tags/increment.rb +23 -17
- data/lib/liquid/tags/inline_comment.rb +43 -0
- data/lib/liquid/tags/raw.rb +25 -11
- data/lib/liquid/tags/render.rb +109 -0
- data/lib/liquid/tags/table_row.rb +45 -19
- data/lib/liquid/tags/unless.rb +38 -19
- data/lib/liquid/template.rb +52 -72
- data/lib/liquid/template_factory.rb +9 -0
- data/lib/liquid/tokenizer.rb +18 -10
- data/lib/liquid/usage.rb +8 -0
- data/lib/liquid/utils.rb +13 -3
- data/lib/liquid/variable.rb +49 -44
- data/lib/liquid/variable_lookup.rb +18 -10
- data/lib/liquid/version.rb +2 -1
- data/lib/liquid.rb +18 -6
- metadata +20 -108
- data/lib/liquid/strainer.rb +0 -66
- data/lib/liquid/truffle.rb +0 -5
- data/test/fixtures/en_locale.yml +0 -9
- data/test/integration/assign_test.rb +0 -48
- data/test/integration/blank_test.rb +0 -106
- data/test/integration/block_test.rb +0 -12
- data/test/integration/capture_test.rb +0 -50
- data/test/integration/context_test.rb +0 -32
- data/test/integration/document_test.rb +0 -19
- data/test/integration/drop_test.rb +0 -273
- data/test/integration/error_handling_test.rb +0 -260
- data/test/integration/filter_test.rb +0 -178
- data/test/integration/hash_ordering_test.rb +0 -23
- data/test/integration/output_test.rb +0 -123
- data/test/integration/parse_tree_visitor_test.rb +0 -247
- data/test/integration/parsing_quirks_test.rb +0 -122
- data/test/integration/render_profiling_test.rb +0 -154
- data/test/integration/security_test.rb +0 -80
- data/test/integration/standard_filter_test.rb +0 -776
- data/test/integration/tags/break_tag_test.rb +0 -15
- data/test/integration/tags/continue_tag_test.rb +0 -15
- data/test/integration/tags/for_tag_test.rb +0 -410
- data/test/integration/tags/if_else_tag_test.rb +0 -188
- data/test/integration/tags/include_tag_test.rb +0 -253
- data/test/integration/tags/increment_tag_test.rb +0 -23
- data/test/integration/tags/raw_tag_test.rb +0 -31
- data/test/integration/tags/standard_tag_test.rb +0 -296
- data/test/integration/tags/statements_test.rb +0 -111
- data/test/integration/tags/table_row_test.rb +0 -64
- data/test/integration/tags/unless_else_tag_test.rb +0 -26
- data/test/integration/template_test.rb +0 -332
- data/test/integration/trim_mode_test.rb +0 -529
- data/test/integration/variable_test.rb +0 -96
- data/test/test_helper.rb +0 -116
- data/test/truffle/truffle_test.rb +0 -9
- data/test/unit/block_unit_test.rb +0 -58
- data/test/unit/condition_unit_test.rb +0 -166
- data/test/unit/context_unit_test.rb +0 -489
- data/test/unit/file_system_unit_test.rb +0 -35
- data/test/unit/i18n_unit_test.rb +0 -37
- data/test/unit/lexer_unit_test.rb +0 -51
- data/test/unit/parser_unit_test.rb +0 -82
- data/test/unit/regexp_unit_test.rb +0 -44
- data/test/unit/strainer_unit_test.rb +0 -164
- data/test/unit/tag_unit_test.rb +0 -21
- data/test/unit/tags/case_tag_unit_test.rb +0 -10
- data/test/unit/tags/for_tag_unit_test.rb +0 -13
- data/test/unit/tags/if_tag_unit_test.rb +0 -8
- data/test/unit/template_unit_test.rb +0 -78
- data/test/unit/tokenizer_unit_test.rb +0 -55
- data/test/unit/variable_unit_test.rb +0 -162
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 5.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Lütke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '13.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '13.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,14 +70,19 @@ files:
|
|
70
70
|
- lib/liquid/parse_tree_visitor.rb
|
71
71
|
- lib/liquid/parser.rb
|
72
72
|
- lib/liquid/parser_switching.rb
|
73
|
+
- lib/liquid/partial_cache.rb
|
73
74
|
- lib/liquid/profiler.rb
|
74
75
|
- lib/liquid/profiler/hooks.rb
|
75
76
|
- lib/liquid/range_lookup.rb
|
77
|
+
- lib/liquid/registers.rb
|
76
78
|
- lib/liquid/resource_limits.rb
|
77
79
|
- lib/liquid/standardfilters.rb
|
78
|
-
- lib/liquid/
|
80
|
+
- lib/liquid/strainer_factory.rb
|
81
|
+
- lib/liquid/strainer_template.rb
|
79
82
|
- lib/liquid/tablerowloop_drop.rb
|
80
83
|
- lib/liquid/tag.rb
|
84
|
+
- lib/liquid/tag/disableable.rb
|
85
|
+
- lib/liquid/tag/disabler.rb
|
81
86
|
- lib/liquid/tags/assign.rb
|
82
87
|
- lib/liquid/tags/break.rb
|
83
88
|
- lib/liquid/tags/capture.rb
|
@@ -86,74 +91,30 @@ files:
|
|
86
91
|
- lib/liquid/tags/continue.rb
|
87
92
|
- lib/liquid/tags/cycle.rb
|
88
93
|
- lib/liquid/tags/decrement.rb
|
94
|
+
- lib/liquid/tags/echo.rb
|
89
95
|
- lib/liquid/tags/for.rb
|
90
96
|
- lib/liquid/tags/if.rb
|
91
97
|
- lib/liquid/tags/ifchanged.rb
|
92
98
|
- lib/liquid/tags/include.rb
|
93
99
|
- lib/liquid/tags/increment.rb
|
100
|
+
- lib/liquid/tags/inline_comment.rb
|
94
101
|
- lib/liquid/tags/raw.rb
|
102
|
+
- lib/liquid/tags/render.rb
|
95
103
|
- lib/liquid/tags/table_row.rb
|
96
104
|
- lib/liquid/tags/unless.rb
|
97
105
|
- lib/liquid/template.rb
|
106
|
+
- lib/liquid/template_factory.rb
|
98
107
|
- lib/liquid/tokenizer.rb
|
99
|
-
- lib/liquid/
|
108
|
+
- lib/liquid/usage.rb
|
100
109
|
- lib/liquid/utils.rb
|
101
110
|
- lib/liquid/variable.rb
|
102
111
|
- lib/liquid/variable_lookup.rb
|
103
112
|
- lib/liquid/version.rb
|
104
|
-
- test/fixtures/en_locale.yml
|
105
|
-
- test/integration/assign_test.rb
|
106
|
-
- test/integration/blank_test.rb
|
107
|
-
- test/integration/block_test.rb
|
108
|
-
- test/integration/capture_test.rb
|
109
|
-
- test/integration/context_test.rb
|
110
|
-
- test/integration/document_test.rb
|
111
|
-
- test/integration/drop_test.rb
|
112
|
-
- test/integration/error_handling_test.rb
|
113
|
-
- test/integration/filter_test.rb
|
114
|
-
- test/integration/hash_ordering_test.rb
|
115
|
-
- test/integration/output_test.rb
|
116
|
-
- test/integration/parse_tree_visitor_test.rb
|
117
|
-
- test/integration/parsing_quirks_test.rb
|
118
|
-
- test/integration/render_profiling_test.rb
|
119
|
-
- test/integration/security_test.rb
|
120
|
-
- test/integration/standard_filter_test.rb
|
121
|
-
- test/integration/tags/break_tag_test.rb
|
122
|
-
- test/integration/tags/continue_tag_test.rb
|
123
|
-
- test/integration/tags/for_tag_test.rb
|
124
|
-
- test/integration/tags/if_else_tag_test.rb
|
125
|
-
- test/integration/tags/include_tag_test.rb
|
126
|
-
- test/integration/tags/increment_tag_test.rb
|
127
|
-
- test/integration/tags/raw_tag_test.rb
|
128
|
-
- test/integration/tags/standard_tag_test.rb
|
129
|
-
- test/integration/tags/statements_test.rb
|
130
|
-
- test/integration/tags/table_row_test.rb
|
131
|
-
- test/integration/tags/unless_else_tag_test.rb
|
132
|
-
- test/integration/template_test.rb
|
133
|
-
- test/integration/trim_mode_test.rb
|
134
|
-
- test/integration/variable_test.rb
|
135
|
-
- test/test_helper.rb
|
136
|
-
- test/truffle/truffle_test.rb
|
137
|
-
- test/unit/block_unit_test.rb
|
138
|
-
- test/unit/condition_unit_test.rb
|
139
|
-
- test/unit/context_unit_test.rb
|
140
|
-
- test/unit/file_system_unit_test.rb
|
141
|
-
- test/unit/i18n_unit_test.rb
|
142
|
-
- test/unit/lexer_unit_test.rb
|
143
|
-
- test/unit/parser_unit_test.rb
|
144
|
-
- test/unit/regexp_unit_test.rb
|
145
|
-
- test/unit/strainer_unit_test.rb
|
146
|
-
- test/unit/tag_unit_test.rb
|
147
|
-
- test/unit/tags/case_tag_unit_test.rb
|
148
|
-
- test/unit/tags/for_tag_unit_test.rb
|
149
|
-
- test/unit/tags/if_tag_unit_test.rb
|
150
|
-
- test/unit/template_unit_test.rb
|
151
|
-
- test/unit/tokenizer_unit_test.rb
|
152
|
-
- test/unit/variable_unit_test.rb
|
153
113
|
homepage: http://www.liquidmarkup.org
|
154
114
|
licenses:
|
155
115
|
- MIT
|
156
|
-
metadata:
|
116
|
+
metadata:
|
117
|
+
allowed_push_host: https://rubygems.org
|
157
118
|
post_install_message:
|
158
119
|
rdoc_options: []
|
159
120
|
require_paths:
|
@@ -162,64 +123,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
123
|
requirements:
|
163
124
|
- - ">="
|
164
125
|
- !ruby/object:Gem::Version
|
165
|
-
version: 2.
|
126
|
+
version: 2.7.0
|
166
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
128
|
requirements:
|
168
129
|
- - ">="
|
169
130
|
- !ruby/object:Gem::Version
|
170
131
|
version: 1.3.7
|
171
132
|
requirements: []
|
172
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.3.3
|
173
134
|
signing_key:
|
174
135
|
specification_version: 4
|
175
136
|
summary: A secure, non-evaling end user template engine with aesthetic markup.
|
176
|
-
test_files:
|
177
|
-
- test/unit/lexer_unit_test.rb
|
178
|
-
- test/unit/block_unit_test.rb
|
179
|
-
- test/unit/variable_unit_test.rb
|
180
|
-
- test/unit/parser_unit_test.rb
|
181
|
-
- test/unit/tags/if_tag_unit_test.rb
|
182
|
-
- test/unit/tags/case_tag_unit_test.rb
|
183
|
-
- test/unit/tags/for_tag_unit_test.rb
|
184
|
-
- test/unit/context_unit_test.rb
|
185
|
-
- test/unit/tokenizer_unit_test.rb
|
186
|
-
- test/unit/tag_unit_test.rb
|
187
|
-
- test/unit/i18n_unit_test.rb
|
188
|
-
- test/unit/template_unit_test.rb
|
189
|
-
- test/unit/condition_unit_test.rb
|
190
|
-
- test/unit/file_system_unit_test.rb
|
191
|
-
- test/unit/regexp_unit_test.rb
|
192
|
-
- test/unit/strainer_unit_test.rb
|
193
|
-
- test/integration/output_test.rb
|
194
|
-
- test/integration/hash_ordering_test.rb
|
195
|
-
- test/integration/variable_test.rb
|
196
|
-
- test/integration/blank_test.rb
|
197
|
-
- test/integration/parse_tree_visitor_test.rb
|
198
|
-
- test/integration/assign_test.rb
|
199
|
-
- test/integration/trim_mode_test.rb
|
200
|
-
- test/integration/context_test.rb
|
201
|
-
- test/integration/capture_test.rb
|
202
|
-
- test/integration/tags/increment_tag_test.rb
|
203
|
-
- test/integration/tags/for_tag_test.rb
|
204
|
-
- test/integration/tags/standard_tag_test.rb
|
205
|
-
- test/integration/tags/table_row_test.rb
|
206
|
-
- test/integration/tags/include_tag_test.rb
|
207
|
-
- test/integration/tags/raw_tag_test.rb
|
208
|
-
- test/integration/tags/statements_test.rb
|
209
|
-
- test/integration/tags/if_else_tag_test.rb
|
210
|
-
- test/integration/tags/unless_else_tag_test.rb
|
211
|
-
- test/integration/tags/continue_tag_test.rb
|
212
|
-
- test/integration/tags/break_tag_test.rb
|
213
|
-
- test/integration/block_test.rb
|
214
|
-
- test/integration/standard_filter_test.rb
|
215
|
-
- test/integration/drop_test.rb
|
216
|
-
- test/integration/error_handling_test.rb
|
217
|
-
- test/integration/template_test.rb
|
218
|
-
- test/integration/document_test.rb
|
219
|
-
- test/integration/security_test.rb
|
220
|
-
- test/integration/render_profiling_test.rb
|
221
|
-
- test/integration/parsing_quirks_test.rb
|
222
|
-
- test/integration/filter_test.rb
|
223
|
-
- test/truffle/truffle_test.rb
|
224
|
-
- test/fixtures/en_locale.yml
|
225
|
-
- test/test_helper.rb
|
137
|
+
test_files: []
|
data/lib/liquid/strainer.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module Liquid
|
4
|
-
# Strainer is the parent class for the filters system.
|
5
|
-
# New filters are mixed into the strainer class which is then instantiated for each liquid template render run.
|
6
|
-
#
|
7
|
-
# The Strainer only allows method calls defined in filters given to it via Strainer.global_filter,
|
8
|
-
# Context#add_filters or Template.register_filter
|
9
|
-
class Strainer #:nodoc:
|
10
|
-
@@global_strainer = Class.new(Strainer) do
|
11
|
-
@filter_methods = Set.new
|
12
|
-
end
|
13
|
-
@@strainer_class_cache = Hash.new do |hash, filters|
|
14
|
-
hash[filters] = Class.new(@@global_strainer) do
|
15
|
-
@filter_methods = @@global_strainer.filter_methods.dup
|
16
|
-
filters.each { |f| add_filter(f) }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def initialize(context)
|
21
|
-
@context = context
|
22
|
-
end
|
23
|
-
|
24
|
-
class << self
|
25
|
-
attr_reader :filter_methods
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.add_filter(filter)
|
29
|
-
raise ArgumentError, "Expected module but got: #{filter.class}" unless filter.is_a?(Module)
|
30
|
-
unless self.include?(filter)
|
31
|
-
invokable_non_public_methods = (filter.private_instance_methods + filter.protected_instance_methods).select { |m| invokable?(m) }
|
32
|
-
if invokable_non_public_methods.any?
|
33
|
-
raise MethodOverrideError, "Filter overrides registered public methods as non public: #{invokable_non_public_methods.join(', ')}"
|
34
|
-
else
|
35
|
-
send(:include, filter)
|
36
|
-
@filter_methods.merge(filter.public_instance_methods.map(&:to_s))
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.global_filter(filter)
|
42
|
-
@@strainer_class_cache.clear
|
43
|
-
@@global_strainer.add_filter(filter)
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.invokable?(method)
|
47
|
-
@filter_methods.include?(method.to_s)
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.create(context, filters = [])
|
51
|
-
@@strainer_class_cache[filters].new(context)
|
52
|
-
end
|
53
|
-
|
54
|
-
def invoke(method, *args)
|
55
|
-
if self.class.invokable?(method)
|
56
|
-
send(method, *args)
|
57
|
-
elsif @context && @context.strict_filters
|
58
|
-
raise Liquid::UndefinedFilter, "undefined filter #{method}"
|
59
|
-
else
|
60
|
-
args.first
|
61
|
-
end
|
62
|
-
rescue ::ArgumentError => e
|
63
|
-
raise Liquid::ArgumentError, e.message, e.backtrace
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/lib/liquid/truffle.rb
DELETED
data/test/fixtures/en_locale.yml
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class AssignTest < Minitest::Test
|
4
|
-
include Liquid
|
5
|
-
|
6
|
-
def test_assign_with_hyphen_in_variable_name
|
7
|
-
template_source = <<-END_TEMPLATE
|
8
|
-
{% assign this-thing = 'Print this-thing' %}
|
9
|
-
{{ this-thing }}
|
10
|
-
END_TEMPLATE
|
11
|
-
template = Template.parse(template_source)
|
12
|
-
rendered = template.render!
|
13
|
-
assert_equal "Print this-thing", rendered.strip
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_assigned_variable
|
17
|
-
assert_template_result('.foo.',
|
18
|
-
'{% assign foo = values %}.{{ foo[0] }}.',
|
19
|
-
'values' => %w(foo bar baz))
|
20
|
-
|
21
|
-
assert_template_result('.bar.',
|
22
|
-
'{% assign foo = values %}.{{ foo[1] }}.',
|
23
|
-
'values' => %w(foo bar baz))
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_assign_with_filter
|
27
|
-
assert_template_result('.bar.',
|
28
|
-
'{% assign foo = values | split: "," %}.{{ foo[1] }}.',
|
29
|
-
'values' => "foo,bar,baz")
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_assign_syntax_error
|
33
|
-
assert_match_syntax_error(/assign/,
|
34
|
-
'{% assign foo not values %}.',
|
35
|
-
'values' => "foo,bar,baz")
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_assign_uses_error_mode
|
39
|
-
with_error_mode(:strict) do
|
40
|
-
assert_raises(SyntaxError) do
|
41
|
-
Template.parse("{% assign foo = ('X' | downcase) %}")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
with_error_mode(:lax) do
|
45
|
-
assert Template.parse("{% assign foo = ('X' | downcase) %}")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end # AssignTest
|
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class FoobarTag < Liquid::Tag
|
4
|
-
def render(*args)
|
5
|
-
" "
|
6
|
-
end
|
7
|
-
|
8
|
-
Liquid::Template.register_tag('foobar', FoobarTag)
|
9
|
-
end
|
10
|
-
|
11
|
-
class BlankTestFileSystem
|
12
|
-
def read_template_file(template_path)
|
13
|
-
template_path
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class BlankTest < Minitest::Test
|
18
|
-
include Liquid
|
19
|
-
N = 10
|
20
|
-
|
21
|
-
def wrap_in_for(body)
|
22
|
-
"{% for i in (1..#{N}) %}#{body}{% endfor %}"
|
23
|
-
end
|
24
|
-
|
25
|
-
def wrap_in_if(body)
|
26
|
-
"{% if true %}#{body}{% endif %}"
|
27
|
-
end
|
28
|
-
|
29
|
-
def wrap(body)
|
30
|
-
wrap_in_for(body) + wrap_in_if(body)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_new_tags_are_not_blank_by_default
|
34
|
-
assert_template_result(" " * N, wrap_in_for("{% foobar %}"))
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_loops_are_blank
|
38
|
-
assert_template_result("", wrap_in_for(" "))
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_if_else_are_blank
|
42
|
-
assert_template_result("", "{% if true %} {% elsif false %} {% else %} {% endif %}")
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_unless_is_blank
|
46
|
-
assert_template_result("", wrap("{% unless true %} {% endunless %}"))
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_mark_as_blank_only_during_parsing
|
50
|
-
assert_template_result(" " * (N + 1), wrap(" {% if false %} this never happens, but still, this block is not blank {% endif %}"))
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_comments_are_blank
|
54
|
-
assert_template_result("", wrap(" {% comment %} whatever {% endcomment %} "))
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_captures_are_blank
|
58
|
-
assert_template_result("", wrap(" {% capture foo %} whatever {% endcapture %} "))
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_nested_blocks_are_blank_but_only_if_all_children_are
|
62
|
-
assert_template_result("", wrap(wrap(" ")))
|
63
|
-
assert_template_result("\n but this is not " * (N + 1),
|
64
|
-
wrap('{% if true %} {% comment %} this is blank {% endcomment %} {% endif %}
|
65
|
-
{% if true %} but this is not {% endif %}'))
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_assigns_are_blank
|
69
|
-
assert_template_result("", wrap(' {% assign foo = "bar" %} '))
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_whitespace_is_blank
|
73
|
-
assert_template_result("", wrap(" "))
|
74
|
-
assert_template_result("", wrap("\t"))
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_whitespace_is_not_blank_if_other_stuff_is_present
|
78
|
-
body = " x "
|
79
|
-
assert_template_result(body * (N + 1), wrap(body))
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_increment_is_not_blank
|
83
|
-
assert_template_result(" 0" * 2 * (N + 1), wrap("{% assign foo = 0 %} {% increment foo %} {% decrement foo %}"))
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_cycle_is_not_blank
|
87
|
-
assert_template_result(" " * ((N + 1) / 2) + " ", wrap("{% cycle ' ', ' ' %}"))
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_raw_is_not_blank
|
91
|
-
assert_template_result(" " * (N + 1), wrap(" {% raw %} {% endraw %}"))
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_include_is_blank
|
95
|
-
Liquid::Template.file_system = BlankTestFileSystem.new
|
96
|
-
assert_template_result "foobar" * (N + 1), wrap("{% include 'foobar' %}")
|
97
|
-
assert_template_result " foobar " * (N + 1), wrap("{% include ' foobar ' %}")
|
98
|
-
assert_template_result " " * (N + 1), wrap(" {% include ' ' %} ")
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_case_is_blank
|
102
|
-
assert_template_result("", wrap(" {% assign foo = 'bar' %} {% case foo %} {% when 'bar' %} {% when 'whatever' %} {% else %} {% endcase %} "))
|
103
|
-
assert_template_result("", wrap(" {% assign foo = 'else' %} {% case foo %} {% when 'bar' %} {% when 'whatever' %} {% else %} {% endcase %} "))
|
104
|
-
assert_template_result(" x " * (N + 1), wrap(" {% assign foo = 'else' %} {% case foo %} {% when 'bar' %} {% when 'whatever' %} {% else %} x {% endcase %} "))
|
105
|
-
end
|
106
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class BlockTest < Minitest::Test
|
4
|
-
include Liquid
|
5
|
-
|
6
|
-
def test_unexpected_end_tag
|
7
|
-
exc = assert_raises(SyntaxError) do
|
8
|
-
Template.parse("{% if true %}{% endunless %}")
|
9
|
-
end
|
10
|
-
assert_equal exc.message, "Liquid syntax error: 'endunless' is not a valid delimiter for if tags. use endif"
|
11
|
-
end
|
12
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CaptureTest < Minitest::Test
|
4
|
-
include Liquid
|
5
|
-
|
6
|
-
def test_captures_block_content_in_variable
|
7
|
-
assert_template_result("test string", "{% capture 'var' %}test string{% endcapture %}{{var}}", {})
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_capture_with_hyphen_in_variable_name
|
11
|
-
template_source = <<-END_TEMPLATE
|
12
|
-
{% capture this-thing %}Print this-thing{% endcapture %}
|
13
|
-
{{ this-thing }}
|
14
|
-
END_TEMPLATE
|
15
|
-
template = Template.parse(template_source)
|
16
|
-
rendered = template.render!
|
17
|
-
assert_equal "Print this-thing", rendered.strip
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_capture_to_variable_from_outer_scope_if_existing
|
21
|
-
template_source = <<-END_TEMPLATE
|
22
|
-
{% assign var = '' %}
|
23
|
-
{% if true %}
|
24
|
-
{% capture var %}first-block-string{% endcapture %}
|
25
|
-
{% endif %}
|
26
|
-
{% if true %}
|
27
|
-
{% capture var %}test-string{% endcapture %}
|
28
|
-
{% endif %}
|
29
|
-
{{var}}
|
30
|
-
END_TEMPLATE
|
31
|
-
template = Template.parse(template_source)
|
32
|
-
rendered = template.render!
|
33
|
-
assert_equal "test-string", rendered.gsub(/\s/, '')
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_assigning_from_capture
|
37
|
-
template_source = <<-END_TEMPLATE
|
38
|
-
{% assign first = '' %}
|
39
|
-
{% assign second = '' %}
|
40
|
-
{% for number in (1..3) %}
|
41
|
-
{% capture first %}{{number}}{% endcapture %}
|
42
|
-
{% assign second = first %}
|
43
|
-
{% endfor %}
|
44
|
-
{{ first }}-{{ second }}
|
45
|
-
END_TEMPLATE
|
46
|
-
template = Template.parse(template_source)
|
47
|
-
rendered = template.render!
|
48
|
-
assert_equal "3-3", rendered.gsub(/\s/, '')
|
49
|
-
end
|
50
|
-
end # CaptureTest
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ContextTest < Minitest::Test
|
4
|
-
include Liquid
|
5
|
-
|
6
|
-
def test_override_global_filter
|
7
|
-
global = Module.new do
|
8
|
-
def notice(output)
|
9
|
-
"Global #{output}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
local = Module.new do
|
14
|
-
def notice(output)
|
15
|
-
"Local #{output}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
with_global_filter(global) do
|
20
|
-
assert_equal 'Global test', Template.parse("{{'test' | notice }}").render!
|
21
|
-
assert_equal 'Local test', Template.parse("{{'test' | notice }}").render!({}, filters: [local])
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_has_key_will_not_add_an_error_for_missing_keys
|
26
|
-
with_error_mode :strict do
|
27
|
-
context = Context.new
|
28
|
-
context.key?('unknown')
|
29
|
-
assert_empty context.errors
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class DocumentTest < Minitest::Test
|
4
|
-
include Liquid
|
5
|
-
|
6
|
-
def test_unexpected_outer_tag
|
7
|
-
exc = assert_raises(SyntaxError) do
|
8
|
-
Template.parse("{% else %}")
|
9
|
-
end
|
10
|
-
assert_equal exc.message, "Liquid syntax error: Unexpected outer 'else' tag"
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_unknown_tag
|
14
|
-
exc = assert_raises(SyntaxError) do
|
15
|
-
Template.parse("{% foo %}")
|
16
|
-
end
|
17
|
-
assert_equal exc.message, "Liquid syntax error: Unknown tag 'foo'"
|
18
|
-
end
|
19
|
-
end
|