liquid 4.0.0 → 5.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +235 -2
  3. data/README.md +58 -8
  4. data/lib/liquid/block.rb +51 -20
  5. data/lib/liquid/block_body.rb +216 -82
  6. data/lib/liquid/condition.rb +83 -32
  7. data/lib/liquid/const.rb +8 -0
  8. data/lib/liquid/context.rb +130 -59
  9. data/lib/liquid/deprecations.rb +22 -0
  10. data/lib/liquid/document.rb +47 -9
  11. data/lib/liquid/drop.rb +8 -2
  12. data/lib/liquid/environment.rb +159 -0
  13. data/lib/liquid/errors.rb +23 -20
  14. data/lib/liquid/expression.rb +114 -31
  15. data/lib/liquid/extensions.rb +8 -0
  16. data/lib/liquid/file_system.rb +6 -4
  17. data/lib/liquid/forloop_drop.rb +51 -4
  18. data/lib/liquid/i18n.rb +5 -3
  19. data/lib/liquid/interrupts.rb +3 -1
  20. data/lib/liquid/lexer.rb +165 -39
  21. data/lib/liquid/locales/en.yml +16 -6
  22. data/lib/liquid/parse_context.rb +62 -7
  23. data/lib/liquid/parse_tree_visitor.rb +42 -0
  24. data/lib/liquid/parser.rb +31 -19
  25. data/lib/liquid/parser_switching.rb +42 -3
  26. data/lib/liquid/partial_cache.rb +33 -0
  27. data/lib/liquid/profiler/hooks.rb +26 -14
  28. data/lib/liquid/profiler.rb +67 -86
  29. data/lib/liquid/range_lookup.rb +26 -6
  30. data/lib/liquid/registers.rb +51 -0
  31. data/lib/liquid/resource_limits.rb +47 -8
  32. data/lib/liquid/snippet_drop.rb +22 -0
  33. data/lib/liquid/standardfilters.rb +813 -137
  34. data/lib/liquid/strainer_template.rb +62 -0
  35. data/lib/liquid/tablerowloop_drop.rb +64 -5
  36. data/lib/liquid/tag/disableable.rb +22 -0
  37. data/lib/liquid/tag/disabler.rb +13 -0
  38. data/lib/liquid/tag.rb +42 -6
  39. data/lib/liquid/tags/assign.rb +46 -18
  40. data/lib/liquid/tags/break.rb +15 -4
  41. data/lib/liquid/tags/capture.rb +26 -18
  42. data/lib/liquid/tags/case.rb +108 -32
  43. data/lib/liquid/tags/comment.rb +76 -4
  44. data/lib/liquid/tags/continue.rb +15 -13
  45. data/lib/liquid/tags/cycle.rb +117 -34
  46. data/lib/liquid/tags/decrement.rb +30 -23
  47. data/lib/liquid/tags/doc.rb +81 -0
  48. data/lib/liquid/tags/echo.rb +39 -0
  49. data/lib/liquid/tags/for.rb +109 -96
  50. data/lib/liquid/tags/if.rb +72 -41
  51. data/lib/liquid/tags/ifchanged.rb +10 -11
  52. data/lib/liquid/tags/include.rb +89 -63
  53. data/lib/liquid/tags/increment.rb +31 -20
  54. data/lib/liquid/tags/inline_comment.rb +28 -0
  55. data/lib/liquid/tags/raw.rb +25 -13
  56. data/lib/liquid/tags/render.rb +151 -0
  57. data/lib/liquid/tags/snippet.rb +45 -0
  58. data/lib/liquid/tags/table_row.rb +104 -21
  59. data/lib/liquid/tags/unless.rb +37 -20
  60. data/lib/liquid/tags.rb +51 -0
  61. data/lib/liquid/template.rb +90 -106
  62. data/lib/liquid/template_factory.rb +9 -0
  63. data/lib/liquid/tokenizer.rb +143 -13
  64. data/lib/liquid/usage.rb +8 -0
  65. data/lib/liquid/utils.rb +114 -5
  66. data/lib/liquid/variable.rb +119 -45
  67. data/lib/liquid/variable_lookup.rb +35 -13
  68. data/lib/liquid/version.rb +3 -1
  69. data/lib/liquid.rb +31 -18
  70. metadata +56 -107
  71. data/lib/liquid/strainer.rb +0 -66
  72. data/test/fixtures/en_locale.yml +0 -9
  73. data/test/integration/assign_test.rb +0 -48
  74. data/test/integration/blank_test.rb +0 -106
  75. data/test/integration/capture_test.rb +0 -50
  76. data/test/integration/context_test.rb +0 -32
  77. data/test/integration/document_test.rb +0 -19
  78. data/test/integration/drop_test.rb +0 -273
  79. data/test/integration/error_handling_test.rb +0 -260
  80. data/test/integration/filter_test.rb +0 -178
  81. data/test/integration/hash_ordering_test.rb +0 -23
  82. data/test/integration/output_test.rb +0 -123
  83. data/test/integration/parsing_quirks_test.rb +0 -118
  84. data/test/integration/render_profiling_test.rb +0 -154
  85. data/test/integration/security_test.rb +0 -66
  86. data/test/integration/standard_filter_test.rb +0 -535
  87. data/test/integration/tags/break_tag_test.rb +0 -15
  88. data/test/integration/tags/continue_tag_test.rb +0 -15
  89. data/test/integration/tags/for_tag_test.rb +0 -410
  90. data/test/integration/tags/if_else_tag_test.rb +0 -188
  91. data/test/integration/tags/include_tag_test.rb +0 -238
  92. data/test/integration/tags/increment_tag_test.rb +0 -23
  93. data/test/integration/tags/raw_tag_test.rb +0 -31
  94. data/test/integration/tags/standard_tag_test.rb +0 -296
  95. data/test/integration/tags/statements_test.rb +0 -111
  96. data/test/integration/tags/table_row_test.rb +0 -64
  97. data/test/integration/tags/unless_else_tag_test.rb +0 -26
  98. data/test/integration/template_test.rb +0 -323
  99. data/test/integration/trim_mode_test.rb +0 -525
  100. data/test/integration/variable_test.rb +0 -92
  101. data/test/test_helper.rb +0 -117
  102. data/test/unit/block_unit_test.rb +0 -58
  103. data/test/unit/condition_unit_test.rb +0 -158
  104. data/test/unit/context_unit_test.rb +0 -483
  105. data/test/unit/file_system_unit_test.rb +0 -35
  106. data/test/unit/i18n_unit_test.rb +0 -37
  107. data/test/unit/lexer_unit_test.rb +0 -51
  108. data/test/unit/parser_unit_test.rb +0 -82
  109. data/test/unit/regexp_unit_test.rb +0 -44
  110. data/test/unit/strainer_unit_test.rb +0 -148
  111. data/test/unit/tag_unit_test.rb +0 -21
  112. data/test/unit/tags/case_tag_unit_test.rb +0 -10
  113. data/test/unit/tags/for_tag_unit_test.rb +0 -13
  114. data/test/unit/tags/if_tag_unit_test.rb +0 -8
  115. data/test/unit/template_unit_test.rb +0 -78
  116. data/test/unit/tokenizer_unit_test.rb +0 -55
  117. data/test/unit/variable_unit_test.rb +0 -162
data/lib/liquid.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright (c) 2005 Tobias Luetke
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining
@@ -19,14 +21,17 @@
19
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
23
 
24
+ require "strscan"
25
+
22
26
  module Liquid
23
27
  FilterSeparator = /\|/
24
- ArgumentSeparator = ','.freeze
25
- FilterArgumentSeparator = ':'.freeze
26
- VariableAttributeSeparator = '.'.freeze
27
- WhitespaceControl = '-'.freeze
28
+ ArgumentSeparator = ','
29
+ FilterArgumentSeparator = ':'
30
+ VariableAttributeSeparator = '.'
31
+ WhitespaceControl = '-'
28
32
  TagStart = /\{\%/
29
33
  TagEnd = /\%\}/
34
+ TagName = /#|\w+/
30
35
  VariableSignature = /\(?[\w\-\.\[\]]\)?/
31
36
  VariableSegment = /[\w\-]/
32
37
  VariableStart = /\{\{/
@@ -34,46 +39,54 @@ module Liquid
34
39
  VariableIncompleteEnd = /\}\}?/
35
40
  QuotedString = /"[^"]*"|'[^']*'/
36
41
  QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
37
- TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o
42
+ TagAttributes = /(\w[\w-]*)\s*\:\s*(#{QuotedFragment})/o
38
43
  AnyStartingTag = /#{TagStart}|#{VariableStart}/o
39
44
  PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
40
45
  TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
41
- VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o
46
+ VariableParser = /\[(?>[^\[\]]+|\g<0>)*\]|#{VariableSegment}+\??/o
42
47
 
43
- singleton_class.send(:attr_accessor, :cache_classes)
44
- self.cache_classes = true
48
+ RAISE_EXCEPTION_LAMBDA = ->(_e) { raise }
49
+ HAS_STRING_SCANNER_SCAN_BYTE = StringScanner.instance_methods.include?(:scan_byte)
45
50
  end
46
51
 
47
52
  require "liquid/version"
53
+ require "liquid/deprecations"
54
+ require "liquid/const"
55
+ require 'liquid/standardfilters'
56
+ require 'liquid/file_system'
57
+ require 'liquid/parser_switching'
58
+ require 'liquid/tag'
59
+ require 'liquid/block'
60
+ require 'liquid/parse_tree_visitor'
61
+ require 'liquid/interrupts'
62
+ require 'liquid/tags'
63
+ require "liquid/environment"
48
64
  require 'liquid/lexer'
49
65
  require 'liquid/parser'
50
66
  require 'liquid/i18n'
51
67
  require 'liquid/drop'
52
68
  require 'liquid/tablerowloop_drop'
53
69
  require 'liquid/forloop_drop'
70
+ require 'liquid/snippet_drop'
54
71
  require 'liquid/extensions'
55
72
  require 'liquid/errors'
56
73
  require 'liquid/interrupts'
57
- require 'liquid/strainer'
58
- require 'liquid/expression'
74
+ require 'liquid/strainer_template'
59
75
  require 'liquid/context'
60
- require 'liquid/parser_switching'
61
76
  require 'liquid/tag'
62
- require 'liquid/block'
63
77
  require 'liquid/block_body'
64
78
  require 'liquid/document'
65
79
  require 'liquid/variable'
66
80
  require 'liquid/variable_lookup'
67
81
  require 'liquid/range_lookup'
68
- require 'liquid/file_system'
69
82
  require 'liquid/resource_limits'
83
+ require 'liquid/expression'
70
84
  require 'liquid/template'
71
- require 'liquid/standardfilters'
72
85
  require 'liquid/condition'
73
86
  require 'liquid/utils'
74
87
  require 'liquid/tokenizer'
75
88
  require 'liquid/parse_context'
76
-
77
- # Load all the tags of the standard library
78
- #
79
- Dir["#{__dir__}/liquid/tags/*.rb"].each { |f| require f }
89
+ require 'liquid/partial_cache'
90
+ require 'liquid/usage'
91
+ require 'liquid/registers'
92
+ require 'liquid/template_factory'
metadata CHANGED
@@ -1,29 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Lütke
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2016-12-14 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: strscan
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 3.1.1
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 3.1.1
26
+ - !ruby/object:Gem::Dependency
27
+ name: bigdecimal
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: rake
15
42
  requirement: !ruby/object:Gem::Requirement
16
43
  requirements:
17
44
  - - "~>"
18
45
  - !ruby/object:Gem::Version
19
- version: '11.3'
46
+ version: '13.0'
20
47
  type: :development
21
48
  prerelease: false
22
49
  version_requirements: !ruby/object:Gem::Requirement
23
50
  requirements:
24
51
  - - "~>"
25
52
  - !ruby/object:Gem::Version
26
- version: '11.3'
53
+ version: '13.0'
27
54
  - !ruby/object:Gem::Dependency
28
55
  name: minitest
29
56
  requirement: !ruby/object:Gem::Requirement
@@ -38,7 +65,6 @@ dependencies:
38
65
  - - ">="
39
66
  - !ruby/object:Gem::Version
40
67
  version: '0'
41
- description:
42
68
  email:
43
69
  - tobi@leetsoft.com
44
70
  executables: []
@@ -54,9 +80,12 @@ files:
54
80
  - lib/liquid/block.rb
55
81
  - lib/liquid/block_body.rb
56
82
  - lib/liquid/condition.rb
83
+ - lib/liquid/const.rb
57
84
  - lib/liquid/context.rb
85
+ - lib/liquid/deprecations.rb
58
86
  - lib/liquid/document.rb
59
87
  - lib/liquid/drop.rb
88
+ - lib/liquid/environment.rb
60
89
  - lib/liquid/errors.rb
61
90
  - lib/liquid/expression.rb
62
91
  - lib/liquid/extensions.rb
@@ -67,16 +96,23 @@ files:
67
96
  - lib/liquid/lexer.rb
68
97
  - lib/liquid/locales/en.yml
69
98
  - lib/liquid/parse_context.rb
99
+ - lib/liquid/parse_tree_visitor.rb
70
100
  - lib/liquid/parser.rb
71
101
  - lib/liquid/parser_switching.rb
102
+ - lib/liquid/partial_cache.rb
72
103
  - lib/liquid/profiler.rb
73
104
  - lib/liquid/profiler/hooks.rb
74
105
  - lib/liquid/range_lookup.rb
106
+ - lib/liquid/registers.rb
75
107
  - lib/liquid/resource_limits.rb
108
+ - lib/liquid/snippet_drop.rb
76
109
  - lib/liquid/standardfilters.rb
77
- - lib/liquid/strainer.rb
110
+ - lib/liquid/strainer_template.rb
78
111
  - lib/liquid/tablerowloop_drop.rb
79
112
  - lib/liquid/tag.rb
113
+ - lib/liquid/tag/disableable.rb
114
+ - lib/liquid/tag/disabler.rb
115
+ - lib/liquid/tags.rb
80
116
  - lib/liquid/tags/assign.rb
81
117
  - lib/liquid/tags/break.rb
82
118
  - lib/liquid/tags/capture.rb
@@ -85,71 +121,32 @@ files:
85
121
  - lib/liquid/tags/continue.rb
86
122
  - lib/liquid/tags/cycle.rb
87
123
  - lib/liquid/tags/decrement.rb
124
+ - lib/liquid/tags/doc.rb
125
+ - lib/liquid/tags/echo.rb
88
126
  - lib/liquid/tags/for.rb
89
127
  - lib/liquid/tags/if.rb
90
128
  - lib/liquid/tags/ifchanged.rb
91
129
  - lib/liquid/tags/include.rb
92
130
  - lib/liquid/tags/increment.rb
131
+ - lib/liquid/tags/inline_comment.rb
93
132
  - lib/liquid/tags/raw.rb
133
+ - lib/liquid/tags/render.rb
134
+ - lib/liquid/tags/snippet.rb
94
135
  - lib/liquid/tags/table_row.rb
95
136
  - lib/liquid/tags/unless.rb
96
137
  - lib/liquid/template.rb
138
+ - lib/liquid/template_factory.rb
97
139
  - lib/liquid/tokenizer.rb
140
+ - lib/liquid/usage.rb
98
141
  - lib/liquid/utils.rb
99
142
  - lib/liquid/variable.rb
100
143
  - lib/liquid/variable_lookup.rb
101
144
  - lib/liquid/version.rb
102
- - test/fixtures/en_locale.yml
103
- - test/integration/assign_test.rb
104
- - test/integration/blank_test.rb
105
- - test/integration/capture_test.rb
106
- - test/integration/context_test.rb
107
- - test/integration/document_test.rb
108
- - test/integration/drop_test.rb
109
- - test/integration/error_handling_test.rb
110
- - test/integration/filter_test.rb
111
- - test/integration/hash_ordering_test.rb
112
- - test/integration/output_test.rb
113
- - test/integration/parsing_quirks_test.rb
114
- - test/integration/render_profiling_test.rb
115
- - test/integration/security_test.rb
116
- - test/integration/standard_filter_test.rb
117
- - test/integration/tags/break_tag_test.rb
118
- - test/integration/tags/continue_tag_test.rb
119
- - test/integration/tags/for_tag_test.rb
120
- - test/integration/tags/if_else_tag_test.rb
121
- - test/integration/tags/include_tag_test.rb
122
- - test/integration/tags/increment_tag_test.rb
123
- - test/integration/tags/raw_tag_test.rb
124
- - test/integration/tags/standard_tag_test.rb
125
- - test/integration/tags/statements_test.rb
126
- - test/integration/tags/table_row_test.rb
127
- - test/integration/tags/unless_else_tag_test.rb
128
- - test/integration/template_test.rb
129
- - test/integration/trim_mode_test.rb
130
- - test/integration/variable_test.rb
131
- - test/test_helper.rb
132
- - test/unit/block_unit_test.rb
133
- - test/unit/condition_unit_test.rb
134
- - test/unit/context_unit_test.rb
135
- - test/unit/file_system_unit_test.rb
136
- - test/unit/i18n_unit_test.rb
137
- - test/unit/lexer_unit_test.rb
138
- - test/unit/parser_unit_test.rb
139
- - test/unit/regexp_unit_test.rb
140
- - test/unit/strainer_unit_test.rb
141
- - test/unit/tag_unit_test.rb
142
- - test/unit/tags/case_tag_unit_test.rb
143
- - test/unit/tags/for_tag_unit_test.rb
144
- - test/unit/tags/if_tag_unit_test.rb
145
- - test/unit/template_unit_test.rb
146
- - test/unit/tokenizer_unit_test.rb
147
- - test/unit/variable_unit_test.rb
148
- homepage: http://www.liquidmarkup.org
145
+ homepage: https://shopify.github.io/liquid/
149
146
  licenses:
150
147
  - MIT
151
- metadata: {}
152
- post_install_message:
148
+ metadata:
149
+ allowed_push_host: https://rubygems.org
153
150
  rdoc_options: []
154
151
  require_paths:
155
152
  - lib
@@ -157,62 +154,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
154
  requirements:
158
155
  - - ">="
159
156
  - !ruby/object:Gem::Version
160
- version: 2.1.0
157
+ version: 3.0.0
161
158
  required_rubygems_version: !ruby/object:Gem::Requirement
162
159
  requirements:
163
160
  - - ">="
164
161
  - !ruby/object:Gem::Version
165
162
  version: 1.3.7
166
163
  requirements: []
167
- rubyforge_project:
168
- rubygems_version: 2.4.5
169
- signing_key:
164
+ rubygems_version: 3.7.2
170
165
  specification_version: 4
171
166
  summary: A secure, non-evaling end user template engine with aesthetic markup.
172
- test_files:
173
- - test/fixtures/en_locale.yml
174
- - test/integration/assign_test.rb
175
- - test/integration/blank_test.rb
176
- - test/integration/capture_test.rb
177
- - test/integration/context_test.rb
178
- - test/integration/document_test.rb
179
- - test/integration/drop_test.rb
180
- - test/integration/error_handling_test.rb
181
- - test/integration/filter_test.rb
182
- - test/integration/hash_ordering_test.rb
183
- - test/integration/output_test.rb
184
- - test/integration/parsing_quirks_test.rb
185
- - test/integration/render_profiling_test.rb
186
- - test/integration/security_test.rb
187
- - test/integration/standard_filter_test.rb
188
- - test/integration/tags/break_tag_test.rb
189
- - test/integration/tags/continue_tag_test.rb
190
- - test/integration/tags/for_tag_test.rb
191
- - test/integration/tags/if_else_tag_test.rb
192
- - test/integration/tags/include_tag_test.rb
193
- - test/integration/tags/increment_tag_test.rb
194
- - test/integration/tags/raw_tag_test.rb
195
- - test/integration/tags/standard_tag_test.rb
196
- - test/integration/tags/statements_test.rb
197
- - test/integration/tags/table_row_test.rb
198
- - test/integration/tags/unless_else_tag_test.rb
199
- - test/integration/template_test.rb
200
- - test/integration/trim_mode_test.rb
201
- - test/integration/variable_test.rb
202
- - test/test_helper.rb
203
- - test/unit/block_unit_test.rb
204
- - test/unit/condition_unit_test.rb
205
- - test/unit/context_unit_test.rb
206
- - test/unit/file_system_unit_test.rb
207
- - test/unit/i18n_unit_test.rb
208
- - test/unit/lexer_unit_test.rb
209
- - test/unit/parser_unit_test.rb
210
- - test/unit/regexp_unit_test.rb
211
- - test/unit/strainer_unit_test.rb
212
- - test/unit/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/tags/if_tag_unit_test.rb
216
- - test/unit/template_unit_test.rb
217
- - test/unit/tokenizer_unit_test.rb
218
- - test/unit/variable_unit_test.rb
167
+ test_files: []
@@ -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.class.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
@@ -1,9 +0,0 @@
1
- ---
2
- simple: "less is more"
3
- whatever: "something %{something}"
4
- errors:
5
- i18n:
6
- undefined_interpolation: "undefined key %{key}"
7
- unknown_translation: "translation '%{name}' wasn't found"
8
- syntax:
9
- oops: "something wasn't right"
@@ -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,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