liquid 5.2.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e15bedf89a61f8c69c63cb18007fea0639ba1da3e06126dbcc569bea596c300
4
- data.tar.gz: 8bee4895c2d61314d9e1bede8bf9839c5fd1771031452ee9a07cac47dcfa460b
3
+ metadata.gz: c0e965825a9194672f6d2b9c3011db0125eb3dbbb6d44cacf67559140c3f0f9b
4
+ data.tar.gz: d1d98d881037c5ff8cc2b9da99d3b3e002eb1ca1d2bda593c806830c1607a98a
5
5
  SHA512:
6
- metadata.gz: da978fffe487c1256d718df59a34bdb86f5c8dc9dd66b85d8169dfef0ab5d0fbf3feffb932b1ea30bea71ef573ceee8d8c021b78ee12f2988f365c0d0fa39e87
7
- data.tar.gz: 45360ea60c3059c64508caf7e14cf7fbac0dd6198c6fba7ac4a525653f8f508348223770174b2872f8e54cd5a80ab0bfa70d13ad62975cefe0dd93247e694480
6
+ metadata.gz: fa9caca36072ca79bb727b7bdb9a671e082039c3c999d6cbb79bf8b1feec0d514159daedf2b54f561e66ca5ab7e11273956fb49afbae3580004d3e1d3780b9ab
7
+ data.tar.gz: a766a7b068287a7db0a70222a149f8a52a659e93c6593bb53a31e5cee279cbc65b7db14eaa1cc0e89e816bd76020bf352814cd9c2c6b4e32436f743ab0c8e629
data/History.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Liquid Change Log
2
2
 
3
- ## 5.2.0 2021-03-01
3
+ ## 5.3.0 2022-03-22
4
+
5
+ ### Fixes
6
+ * StandardFilter: Fix missing @context on iterations (#1525) [Thierry Joyal]
7
+ * Test under Ruby 3.1 (#1533) [petergoldstein]
8
+ * Fix warning about block and default value in `static_registers.rb` (#1531) [Peter Zhu]
9
+
10
+ ### Deprecation
11
+ * Condition#evaluate to require mandatory context argument in Liquid 6.0.0 (#1527) [Thierry Joyal]
12
+
13
+ ## 5.2.0 2022-03-01
4
14
 
5
15
  ### Features
6
16
  * Add `remove_last`, and `replace_last` filters (#1422) [Anders Hagbard]
@@ -10,7 +20,6 @@
10
20
  * Fix some internal errors in filters from invalid input (#1476) [Dylan Thacker-Smith]
11
21
  * Allow dash in filter kwarg name for consistency with Liquid::C (#1518) [CP Clermont]
12
22
 
13
-
14
23
  ## 5.1.0 / 2021-09-09
15
24
 
16
25
  ### Features
@@ -61,7 +61,7 @@ module Liquid
61
61
  @child_condition = nil
62
62
  end
63
63
 
64
- def evaluate(context = Context.new)
64
+ def evaluate(context = deprecated_default_context)
65
65
  condition = self
66
66
  result = nil
67
67
  loop do
@@ -150,6 +150,12 @@ module Liquid
150
150
  end
151
151
  end
152
152
 
153
+ def deprecated_default_context
154
+ warn("DEPRECATION WARNING: Condition#evaluate without a context argument is deprecated" \
155
+ " and will be removed from Liquid 6.0.0.")
156
+ Context.new
157
+ end
158
+
153
159
  class ParseTreeVisitor < Liquid::ParseTreeVisitor
154
160
  def children
155
161
  [
@@ -582,8 +582,9 @@ module Liquid
582
582
 
583
583
  def each
584
584
  @input.each do |e|
585
+ e = e.respond_to?(:to_liquid) ? e.to_liquid : e
585
586
  e.context = @context if e.respond_to?(:context=)
586
- yield(e.respond_to?(:to_liquid) ? e.to_liquid : e)
587
+ yield(e)
587
588
  end
588
589
  end
589
590
  end
@@ -31,7 +31,11 @@ module Liquid
31
31
  if @registers.key?(key)
32
32
  @registers.fetch(key)
33
33
  elsif default != UNDEFINED
34
- @static.fetch(key, default, &block)
34
+ if block_given?
35
+ @static.fetch(key, &block)
36
+ else
37
+ @static.fetch(key, default)
38
+ end
35
39
  else
36
40
  @static.fetch(key, &block)
37
41
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Liquid
5
- VERSION = "5.2.0"
5
+ VERSION = "5.3.0"
6
6
  end
@@ -24,7 +24,7 @@ class ContextSensitiveDrop < Liquid::Drop
24
24
  end
25
25
  end
26
26
 
27
- class Category < Liquid::Drop
27
+ class Category
28
28
  attr_accessor :name
29
29
 
30
30
  def initialize(name)
@@ -36,8 +36,9 @@ class Category < Liquid::Drop
36
36
  end
37
37
  end
38
38
 
39
- class CategoryDrop
39
+ class CategoryDrop < Liquid::Drop
40
40
  attr_accessor :category, :context
41
+
41
42
  def initialize(category)
42
43
  @category = category
43
44
  end
@@ -405,45 +406,42 @@ class ContextTest < Minitest::Test
405
406
  end
406
407
 
407
408
  def test_lambda_is_called_once
409
+ @global = 0
410
+
408
411
  @context['callcount'] = proc {
409
- @global ||= 0
410
- @global += 1
412
+ @global += 1
411
413
  @global.to_s
412
414
  }
413
415
 
414
416
  assert_equal('1', @context['callcount'])
415
417
  assert_equal('1', @context['callcount'])
416
418
  assert_equal('1', @context['callcount'])
417
-
418
- @global = nil
419
419
  end
420
420
 
421
421
  def test_nested_lambda_is_called_once
422
+ @global = 0
423
+
422
424
  @context['callcount'] = { "lambda" => proc {
423
- @global ||= 0
424
- @global += 1
425
+ @global += 1
425
426
  @global.to_s
426
427
  } }
427
428
 
428
429
  assert_equal('1', @context['callcount.lambda'])
429
430
  assert_equal('1', @context['callcount.lambda'])
430
431
  assert_equal('1', @context['callcount.lambda'])
431
-
432
- @global = nil
433
432
  end
434
433
 
435
434
  def test_lambda_in_array_is_called_once
435
+ @global = 0
436
+
436
437
  @context['callcount'] = [1, 2, proc {
437
- @global ||= 0
438
- @global += 1
438
+ @global += 1
439
439
  @global.to_s
440
440
  }, 4, 5]
441
441
 
442
442
  assert_equal('1', @context['callcount[2]'])
443
443
  assert_equal('1', @context['callcount[2]'])
444
444
  assert_equal('1', @context['callcount[2]'])
445
-
446
- @global = nil
447
445
  end
448
446
 
449
447
  def test_access_to_context_from_proc
@@ -3,6 +3,27 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class ProfilerTest < Minitest::Test
6
+ class TestDrop < Liquid::Drop
7
+ def initialize(value)
8
+ super()
9
+ @value = value
10
+ end
11
+
12
+ def to_s
13
+ artificial_execution_time
14
+
15
+ @value
16
+ end
17
+
18
+ private
19
+
20
+ # Monotonic clock precision fluctuate based on the operating system
21
+ # By introducing a small sleep we ensure ourselves to register a non zero unit of time
22
+ def artificial_execution_time
23
+ sleep(Process.clock_getres(Process::CLOCK_MONOTONIC))
24
+ end
25
+ end
26
+
6
27
  include Liquid
7
28
 
8
29
  class ProfilingFileSystem
@@ -198,16 +219,22 @@ class ProfilerTest < Minitest::Test
198
219
 
199
220
  def test_profiling_supports_self_time
200
221
  t = Template.parse("{% for item in collection %} {{ item }} {% endfor %}", profile: true)
201
- t.render!("collection" => ["one", "two"])
202
- leaf = t.profiler[0].children[0]
222
+ collection = [
223
+ TestDrop.new("one"),
224
+ TestDrop.new("two"),
225
+ ]
226
+ output = t.render!("collection" => collection)
227
+ assert_equal(" one two ", output)
203
228
 
204
- assert_operator(leaf.self_time, :>, 0)
229
+ leaf = t.profiler[0].children[0]
230
+ assert_operator(leaf.self_time, :>, 0.0)
205
231
  end
206
232
 
207
233
  def test_profiling_supports_total_time
208
- t = Template.parse("{% if true %} {% increment test %} {{ test }} {% endif %}", profile: true)
209
- t.render!
234
+ t = Template.parse("{% if true %} {{ test }} {% endif %}", profile: true)
235
+ output = t.render!("test" => TestDrop.new("one"))
236
+ assert_equal(" one ", output)
210
237
 
211
- assert_operator(t.profiler[0].total_time, :>, 0)
238
+ assert_operator(t.profiler[0].total_time, :>, 0.0)
212
239
  end
213
240
  end
@@ -3,10 +3,6 @@
3
3
 
4
4
  require 'test_helper'
5
5
 
6
- class Filters
7
- include Liquid::StandardFilters
8
- end
9
-
10
6
  class TestThing
11
7
  attr_reader :foo
12
8
 
@@ -29,8 +25,24 @@ class TestThing
29
25
  end
30
26
 
31
27
  class TestDrop < Liquid::Drop
32
- def test
33
- "testfoo"
28
+ def initialize(value:)
29
+ @value = value
30
+ end
31
+
32
+ attr_reader :value
33
+
34
+ def registers
35
+ @context.registers
36
+ end
37
+ end
38
+
39
+ class TestModel
40
+ def initialize(value:)
41
+ @value = value
42
+ end
43
+
44
+ def to_liquid
45
+ TestDrop.new(value: @value)
34
46
  end
35
47
  end
36
48
 
@@ -53,10 +65,13 @@ class NumberLikeThing < Liquid::Drop
53
65
  end
54
66
 
55
67
  class StandardFiltersTest < Minitest::Test
68
+ Filters = Class.new(Liquid::StrainerTemplate)
69
+ Filters.add_filter(Liquid::StandardFilters)
70
+
56
71
  include Liquid
57
72
 
58
73
  def setup
59
- @filters = Filters.new
74
+ @filters = Filters.new(Context.new)
60
75
  end
61
76
 
62
77
  def test_size
@@ -363,8 +378,9 @@ class StandardFiltersTest < Minitest::Test
363
378
  assert_equal(["foo"], @filters.uniq("foo"))
364
379
  assert_equal([1, 3, 2, 4], @filters.uniq([1, 1, 3, 2, 3, 1, 4, 3, 2, 1]))
365
380
  assert_equal([{ "a" => 1 }, { "a" => 3 }, { "a" => 2 }], @filters.uniq([{ "a" => 1 }, { "a" => 3 }, { "a" => 1 }, { "a" => 2 }], "a"))
366
- testdrop = TestDrop.new
367
- assert_equal([testdrop], @filters.uniq([testdrop, TestDrop.new], 'test'))
381
+ test_drop = TestDrop.new(value: "test")
382
+ test_drop_alternate = TestDrop.new(value: "test")
383
+ assert_equal([test_drop], @filters.uniq([test_drop, test_drop_alternate], 'value'))
368
384
  end
369
385
 
370
386
  def test_uniq_empty_array
@@ -423,6 +439,16 @@ class StandardFiltersTest < Minitest::Test
423
439
  assert_template_result("woot: 1", '{{ foo | map: "whatever" }}', "foo" => [t])
424
440
  end
425
441
 
442
+ def test_map_calls_context=
443
+ model = TestModel.new(value: "test")
444
+
445
+ template = Template.parse('{{ foo | map: "registers" }}')
446
+ template.registers[:test] = 1234
447
+ template.assigns['foo'] = [model]
448
+
449
+ assert_template_result("{:test=>1234}", template.render!)
450
+ end
451
+
426
452
  def test_map_on_hashes
427
453
  assert_template_result("4217", '{{ thing | map: "foo" | map: "bar" }}',
428
454
  "thing" => { "foo" => [{ "bar" => 42 }, { "bar" => 17 }] })
@@ -441,9 +467,9 @@ class StandardFiltersTest < Minitest::Test
441
467
  end
442
468
 
443
469
  def test_map_over_proc
444
- drop = TestDrop.new
470
+ drop = TestDrop.new(value: "testfoo")
445
471
  p = proc { drop }
446
- templ = '{{ procs | map: "test" }}'
472
+ templ = '{{ procs | map: "value" }}'
447
473
  assert_template_result("testfoo", templ, "procs" => [p])
448
474
  end
449
475
 
@@ -839,7 +865,7 @@ class StandardFiltersTest < Minitest::Test
839
865
  end
840
866
 
841
867
  def test_all_filters_never_raise_non_liquid_exception
842
- test_drop = TestDrop.new
868
+ test_drop = TestDrop.new(value: "test")
843
869
  test_drop.context = Context.new
844
870
  test_enum = TestEnumerable.new
845
871
  test_enum.context = Context.new
@@ -10,8 +10,8 @@ class ConditionUnitTest < Minitest::Test
10
10
  end
11
11
 
12
12
  def test_basic_condition
13
- assert_equal(false, Condition.new(1, '==', 2).evaluate)
14
- assert_equal(true, Condition.new(1, '==', 1).evaluate)
13
+ assert_equal(false, Condition.new(1, '==', 2).evaluate(Context.new))
14
+ assert_equal(true, Condition.new(1, '==', 1).evaluate(Context.new))
15
15
  end
16
16
 
17
17
  def test_default_operators_evalute_true
@@ -67,11 +67,11 @@ class ConditionUnitTest < Minitest::Test
67
67
  end
68
68
 
69
69
  def test_hash_compare_backwards_compatibility
70
- assert_nil(Condition.new({}, '>', 2).evaluate)
71
- assert_nil(Condition.new(2, '>', {}).evaluate)
72
- assert_equal(false, Condition.new({}, '==', 2).evaluate)
73
- assert_equal(true, Condition.new({ 'a' => 1 }, '==', 'a' => 1).evaluate)
74
- assert_equal(true, Condition.new({ 'a' => 2 }, 'contains', 'a').evaluate)
70
+ assert_nil(Condition.new({}, '>', 2).evaluate(Context.new))
71
+ assert_nil(Condition.new(2, '>', {}).evaluate(Context.new))
72
+ assert_equal(false, Condition.new({}, '==', 2).evaluate(Context.new))
73
+ assert_equal(true, Condition.new({ 'a' => 1 }, '==', 'a' => 1).evaluate(Context.new))
74
+ assert_equal(true, Condition.new({ 'a' => 2 }, 'contains', 'a').evaluate(Context.new))
75
75
  end
76
76
 
77
77
  def test_contains_works_on_arrays
@@ -106,30 +106,29 @@ class ConditionUnitTest < Minitest::Test
106
106
 
107
107
  def test_or_condition
108
108
  condition = Condition.new(1, '==', 2)
109
-
110
- assert_equal(false, condition.evaluate)
109
+ assert_equal(false, condition.evaluate(Context.new))
111
110
 
112
111
  condition.or(Condition.new(2, '==', 1))
113
112
 
114
- assert_equal(false, condition.evaluate)
113
+ assert_equal(false, condition.evaluate(Context.new))
115
114
 
116
115
  condition.or(Condition.new(1, '==', 1))
117
116
 
118
- assert_equal(true, condition.evaluate)
117
+ assert_equal(true, condition.evaluate(Context.new))
119
118
  end
120
119
 
121
120
  def test_and_condition
122
121
  condition = Condition.new(1, '==', 1)
123
122
 
124
- assert_equal(true, condition.evaluate)
123
+ assert_equal(true, condition.evaluate(Context.new))
125
124
 
126
125
  condition.and(Condition.new(2, '==', 2))
127
126
 
128
- assert_equal(true, condition.evaluate)
127
+ assert_equal(true, condition.evaluate(Context.new))
129
128
 
130
129
  condition.and(Condition.new(2, '==', 1))
131
130
 
132
- assert_equal(false, condition.evaluate)
131
+ assert_equal(false, condition.evaluate(Context.new))
133
132
  end
134
133
 
135
134
  def test_should_allow_custom_proc_operator
@@ -148,6 +147,20 @@ class ConditionUnitTest < Minitest::Test
148
147
  assert_evaluates_true(VariableLookup.new("one"), '==', VariableLookup.new("another"))
149
148
  end
150
149
 
150
+ def test_default_context_is_deprecated
151
+ if Gem::Version.new(Liquid::VERSION) >= Gem::Version.new('6.0.0')
152
+ flunk("Condition#evaluate without a context argument is to be removed")
153
+ end
154
+
155
+ _out, err = capture_io do
156
+ assert_equal(true, Condition.new(1, '==', 1).evaluate)
157
+ end
158
+
159
+ expected = "DEPRECATION WARNING: Condition#evaluate without a context argument is deprecated" \
160
+ " and will be removed from Liquid 6.0.0."
161
+ assert_includes(err.lines.map(&:strip), expected)
162
+ end
163
+
151
164
  private
152
165
 
153
166
  def assert_evaluates_true(left, op, right)
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: 5.2.0
4
+ version: 5.3.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: 2022-03-01 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -193,61 +193,61 @@ signing_key:
193
193
  specification_version: 4
194
194
  summary: A secure, non-evaling end user template engine with aesthetic markup.
195
195
  test_files:
196
- - test/integration/tag/disableable_test.rb
197
- - test/integration/parsing_quirks_test.rb
198
- - test/integration/context_test.rb
196
+ - test/unit/parser_unit_test.rb
197
+ - test/unit/static_registers_unit_test.rb
198
+ - test/unit/tag_unit_test.rb
199
+ - test/unit/strainer_factory_unit_test.rb
200
+ - test/unit/partial_cache_unit_test.rb
201
+ - test/unit/strainer_template_unit_test.rb
202
+ - test/unit/lexer_unit_test.rb
203
+ - test/unit/parse_tree_visitor_test.rb
204
+ - test/unit/i18n_unit_test.rb
205
+ - test/unit/tokenizer_unit_test.rb
206
+ - test/unit/template_factory_unit_test.rb
207
+ - test/unit/condition_unit_test.rb
208
+ - test/unit/block_unit_test.rb
209
+ - test/unit/file_system_unit_test.rb
210
+ - test/unit/variable_unit_test.rb
211
+ - test/unit/template_unit_test.rb
212
+ - test/unit/tags/if_tag_unit_test.rb
213
+ - test/unit/tags/case_tag_unit_test.rb
214
+ - test/unit/tags/for_tag_unit_test.rb
215
+ - test/unit/regexp_unit_test.rb
216
+ - test/test_helper.rb
217
+ - test/integration/document_test.rb
218
+ - test/integration/tag_test.rb
199
219
  - test/integration/filter_kwarg_test.rb
200
- - test/integration/capture_test.rb
201
220
  - test/integration/trim_mode_test.rb
221
+ - test/integration/profiler_test.rb
222
+ - test/integration/security_test.rb
223
+ - test/integration/capture_test.rb
224
+ - test/integration/parsing_quirks_test.rb
225
+ - test/integration/blank_test.rb
226
+ - test/integration/template_test.rb
227
+ - test/integration/tag/disableable_test.rb
228
+ - test/integration/variable_test.rb
202
229
  - test/integration/output_test.rb
203
- - test/integration/tags/raw_tag_test.rb
204
- - test/integration/tags/continue_tag_test.rb
205
- - test/integration/tags/increment_tag_test.rb
206
- - test/integration/tags/if_else_tag_test.rb
207
- - test/integration/tags/table_row_test.rb
208
- - test/integration/tags/include_tag_test.rb
230
+ - test/integration/drop_test.rb
231
+ - test/integration/standard_filter_test.rb
232
+ - test/integration/expression_test.rb
233
+ - test/integration/block_test.rb
234
+ - test/integration/hash_ordering_test.rb
235
+ - test/integration/filter_test.rb
209
236
  - test/integration/tags/break_tag_test.rb
210
- - test/integration/tags/unless_else_tag_test.rb
211
237
  - test/integration/tags/standard_tag_test.rb
212
- - test/integration/tags/for_tag_test.rb
213
- - test/integration/tags/statements_test.rb
214
238
  - test/integration/tags/liquid_tag_test.rb
239
+ - test/integration/tags/table_row_test.rb
215
240
  - test/integration/tags/render_tag_test.rb
241
+ - test/integration/tags/include_tag_test.rb
242
+ - test/integration/tags/increment_tag_test.rb
243
+ - test/integration/tags/if_else_tag_test.rb
244
+ - test/integration/tags/continue_tag_test.rb
216
245
  - test/integration/tags/echo_test.rb
217
- - test/integration/drop_test.rb
246
+ - test/integration/tags/raw_tag_test.rb
247
+ - test/integration/tags/for_tag_test.rb
248
+ - test/integration/tags/statements_test.rb
249
+ - test/integration/tags/unless_else_tag_test.rb
250
+ - test/integration/context_test.rb
218
251
  - test/integration/error_handling_test.rb
219
- - test/integration/template_test.rb
220
- - test/integration/expression_test.rb
221
- - test/integration/standard_filter_test.rb
222
- - test/integration/tag_test.rb
223
- - test/integration/hash_ordering_test.rb
224
- - test/integration/security_test.rb
225
- - test/integration/blank_test.rb
226
- - test/integration/filter_test.rb
227
- - test/integration/document_test.rb
228
- - test/integration/block_test.rb
229
- - test/integration/profiler_test.rb
230
- - test/integration/variable_test.rb
231
252
  - test/integration/assign_test.rb
232
- - test/unit/template_unit_test.rb
233
- - test/unit/tag_unit_test.rb
234
- - test/unit/condition_unit_test.rb
235
- - test/unit/strainer_template_unit_test.rb
236
- - test/unit/lexer_unit_test.rb
237
- - test/unit/partial_cache_unit_test.rb
238
- - test/unit/template_factory_unit_test.rb
239
- - test/unit/tags/if_tag_unit_test.rb
240
- - test/unit/tags/case_tag_unit_test.rb
241
- - test/unit/tags/for_tag_unit_test.rb
242
- - test/unit/static_registers_unit_test.rb
243
- - test/unit/regexp_unit_test.rb
244
- - test/unit/i18n_unit_test.rb
245
- - test/unit/parse_tree_visitor_test.rb
246
- - test/unit/variable_unit_test.rb
247
- - test/unit/tokenizer_unit_test.rb
248
- - test/unit/file_system_unit_test.rb
249
- - test/unit/block_unit_test.rb
250
- - test/unit/strainer_factory_unit_test.rb
251
- - test/unit/parser_unit_test.rb
252
- - test/test_helper.rb
253
253
  - test/fixtures/en_locale.yml