liquid2 0.3.1 → 0.4.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/liquid2/context.rb +4 -2
- data/lib/liquid2/environment.rb +23 -3
- data/lib/liquid2/parser.rb +5 -1
- data/lib/liquid2/scanner.rb +19 -19
- data/lib/liquid2/version.rb +1 -1
- data/sig/liquid2.rbs +15 -3
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 474a8dc5c84a97344741bc74d459cc904f1da7025af450c834fb8d416eb98518
|
4
|
+
data.tar.gz: 2dda5436fd261f0208123baa7f7f917f2406531e0bf295db085528a8fa7a5baa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 489dd5089b45f07779de0ee25ee4a8fa5b028a8721bf1423a6ca6884ebde6647d36e9e9450e650c2816c1a63a5b6f1554d8e2d8fa7712c106792a3dbeefe0205
|
7
|
+
data.tar.gz: 7b5e904527625b34d0e177168abbd00198f393b303b9504ee68a37cda3a2f1ef7a407333b15dec96907271610ca715f0e08f49c695466f8f7ddff22a1056b6d4
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## [0.4.0] - 25-08-11
|
2
|
+
|
3
|
+
- Fixed a bug where the parser would raise a `Liquid2::LiquidSyntaxError` if environment arguments `markup_out_end` and `markup_tag_end` where identical. See [#23](https://github.com/jg-rp/ruby-liquid2/issues/23).
|
4
|
+
- Added `Liquid2::Environment.persistent_namespaces`. It is an array of symbols indicating which namespaces from `Liquid2::RenderContext.tag_namespaces` should be preserved when calling `Liquid2::RenderContext#copy`. This is important for some tags - like `{% extends %}` - that need to share state with partial templates rendered with `{% render %}`.
|
5
|
+
- Added the `auto_trim` argument to `Liquid2::Environment`. `auto_trim` can be `'-'`, `'~'` or `nil` (the default). When not `nil`, it sets the automatic whitespace trimming applied to the left side of template text when no explicit whitespace control is given. `+` is also available as whitespace control in tags, outputs statements and comments. A `+` will ensure no trimming is applied, even if `auto_trim` is set.
|
6
|
+
|
1
7
|
## [0.3.1] - 25-06-24
|
2
8
|
|
3
9
|
- Added support for custom markup delimiters. See [#16](https://github.com/jg-rp/ruby-liquid2/pull/16).
|
data/README.md
CHANGED
data/lib/liquid2/context.rb
CHANGED
@@ -219,8 +219,10 @@ module Liquid2
|
|
219
219
|
loop_carry: loop_carry,
|
220
220
|
local_namespace_carry: @assign_score)
|
221
221
|
|
222
|
-
|
223
|
-
|
222
|
+
@env.persistent_namespaces.each do |ns|
|
223
|
+
context.tag_namespace[ns] = @tag_namespace[ns] if @tag_namespace[ns]
|
224
|
+
end
|
225
|
+
|
224
226
|
context
|
225
227
|
end
|
226
228
|
|
data/lib/liquid2/environment.rb
CHANGED
@@ -51,8 +51,14 @@ module Liquid2
|
|
51
51
|
:re_double_quote_string_special, :re_single_quote_string_special, :re_markup_start,
|
52
52
|
:re_markup_end, :re_markup_end_chars, :re_up_to_markup_start, :re_punctuation,
|
53
53
|
:re_up_to_inline_comment_end, :re_up_to_raw_end, :re_block_comment_chunk,
|
54
|
-
:re_up_to_doc_end, :re_line_statement_comment
|
55
|
-
|
54
|
+
:re_up_to_doc_end, :re_line_statement_comment, :persistent_namespaces,
|
55
|
+
:universal_markup_end
|
56
|
+
|
57
|
+
# @param arithmetic_operators [bool] When `true`, arithmetic operators `+`, `-`, `*`, `/`, `%`
|
58
|
+
# and `**` are enabled.
|
59
|
+
# @auto_trim ['-' | '~' | nil] Whitespace trimming to apply to the left of text when
|
60
|
+
# neither `-` or `~` is given for any tag, output statement or comment. The default is
|
61
|
+
# `nil`, which means no automatic whitespace trimming is applied.
|
56
62
|
# @param context_depth_limit [Integer] The maximum number of times a render context can
|
57
63
|
# be extended or copied before a `Liquid2::LiquidResourceLimitError`` is raised.
|
58
64
|
# @param globals [Hash[String, untyped]?] Variables that are available to all templates
|
@@ -91,6 +97,7 @@ module Liquid2
|
|
91
97
|
def initialize(
|
92
98
|
arithmetic_operators: false,
|
93
99
|
context_depth_limit: 30,
|
100
|
+
auto_trim: nil,
|
94
101
|
falsy_undefined: true,
|
95
102
|
globals: nil,
|
96
103
|
loader: nil,
|
@@ -117,6 +124,10 @@ module Liquid2
|
|
117
124
|
# keyword argument.
|
118
125
|
@filters = {}
|
119
126
|
|
127
|
+
# An array of symbols indicating which namespaces from RenderContext.tag_namespaces
|
128
|
+
# should be preserved when using RenderContext#copy.
|
129
|
+
@persistent_namespaces = [:extends]
|
130
|
+
|
120
131
|
# When `true`, arithmetic operators `+`, `-`, `*`, `/`, `%` and `**` are enabled.
|
121
132
|
# Defaults to `false`.
|
122
133
|
@arithmetic_operators = arithmetic_operators
|
@@ -125,6 +136,11 @@ module Liquid2
|
|
125
136
|
# a Liquid2::LiquidResourceLimitError is raised.
|
126
137
|
@context_depth_limit = context_depth_limit
|
127
138
|
|
139
|
+
# The default whitespace trimming applied to the left of text content when neither
|
140
|
+
# `-` or `~` is specified. Defaults to `nil`, which means no automatic whitespace
|
141
|
+
# trimming.
|
142
|
+
@auto_trim = auto_trim
|
143
|
+
|
128
144
|
# Variables that are available to all templates rendered from this environment.
|
129
145
|
@globals = globals
|
130
146
|
|
@@ -185,6 +201,10 @@ module Liquid2
|
|
185
201
|
# The string of characters that indicate the end of a Liquid tag.
|
186
202
|
@markup_tag_end = markup_tag_end
|
187
203
|
|
204
|
+
# Indicates if tag and output end delimiters are identical. This is used by the
|
205
|
+
# parser when parsing output statements.
|
206
|
+
@universal_markup_end = markup_tag_end == markup_out_end
|
207
|
+
|
188
208
|
# The string of characters that indicate the start of a Liquid comment. This should
|
189
209
|
# include a single trailing `#`. Additional, variable length hashes will be handled
|
190
210
|
# by the tokenizer. It is not possible to change comment syntax to not use `#`.
|
@@ -408,7 +428,7 @@ module Liquid2
|
|
408
428
|
|
409
429
|
# Trim _text_.
|
410
430
|
def trim(text, left_trim, right_trim)
|
411
|
-
case left_trim
|
431
|
+
case left_trim || @auto_trim
|
412
432
|
when "-"
|
413
433
|
text.lstrip!
|
414
434
|
when "~"
|
data/lib/liquid2/parser.rb
CHANGED
@@ -43,6 +43,10 @@ module Liquid2
|
|
43
43
|
@pos = 0
|
44
44
|
@eof = [:token_eof, nil, length - 1]
|
45
45
|
@whitespace_carry = nil
|
46
|
+
|
47
|
+
# If both tags and output statements share the same end delimiter, we expect
|
48
|
+
# `:token_tag_end` to close an output statement as the scanner scans for tags first.
|
49
|
+
@output_end = @env.universal_markup_end ? :token_tag_end : :token_output_end
|
46
50
|
end
|
47
51
|
|
48
52
|
# Return the current token without advancing the pointer.
|
@@ -691,7 +695,7 @@ module Liquid2
|
|
691
695
|
def parse_output
|
692
696
|
expr = parse_filtered_expression
|
693
697
|
carry_whitespace_control
|
694
|
-
eat(
|
698
|
+
eat(@output_end)
|
695
699
|
Output.new(expr.token, expr)
|
696
700
|
end
|
697
701
|
|
data/lib/liquid2/scanner.rb
CHANGED
@@ -240,10 +240,10 @@ module Liquid2
|
|
240
240
|
|
241
241
|
# Miro benchmarks show no performance gain using scan_byte and peek_byte over scan here.
|
242
242
|
case @scanner.scan(@re_markup_end)
|
243
|
-
when @s_out_end
|
244
|
-
@tokens << [:token_output_end, nil, @start]
|
245
243
|
when @s_tag_end
|
246
244
|
@tokens << [:token_tag_end, nil, @start]
|
245
|
+
when @s_out_end
|
246
|
+
@tokens << [:token_output_end, nil, @start]
|
247
247
|
else
|
248
248
|
# Unexpected token
|
249
249
|
return nil if @scanner.eos?
|
@@ -306,10 +306,10 @@ module Liquid2
|
|
306
306
|
accept_whitespace_control
|
307
307
|
|
308
308
|
case @scanner.scan(@re_markup_end)
|
309
|
-
when @s_out_end
|
310
|
-
@tokens << [:token_output_end, nil, @start]
|
311
309
|
when @s_tag_end
|
312
310
|
@tokens << [:token_tag_end, nil, @start]
|
311
|
+
when @s_out_end
|
312
|
+
@tokens << [:token_output_end, nil, @start]
|
313
313
|
else
|
314
314
|
# Unexpected token
|
315
315
|
return nil if @scanner.eos?
|
@@ -326,12 +326,12 @@ module Liquid2
|
|
326
326
|
accept_whitespace_control
|
327
327
|
|
328
328
|
case @scanner.scan(@re_markup_end)
|
329
|
-
when @s_out_end
|
330
|
-
@tokens << [:token_output_end, nil, @start]
|
331
|
-
@start = @scanner.pos
|
332
329
|
when @s_tag_end
|
333
330
|
@tokens << [:token_tag_end, nil, @start]
|
334
331
|
@start = @scanner.pos
|
332
|
+
when @s_out_end
|
333
|
+
@tokens << [:token_output_end, nil, @start]
|
334
|
+
@start = @scanner.pos
|
335
335
|
end
|
336
336
|
|
337
337
|
if @scanner.skip_until(@re_up_to_raw_end)
|
@@ -347,12 +347,12 @@ module Liquid2
|
|
347
347
|
accept_whitespace_control
|
348
348
|
|
349
349
|
case @scanner.scan(@re_markup_end)
|
350
|
-
when @s_out_end
|
351
|
-
@tokens << [:token_output_end, nil, @start]
|
352
|
-
@start = @scanner.pos
|
353
350
|
when @s_tag_end
|
354
351
|
@tokens << [:token_tag_end, nil, @start]
|
355
352
|
@start = @scanner.pos
|
353
|
+
when @s_out_end
|
354
|
+
@tokens << [:token_output_end, nil, @start]
|
355
|
+
@start = @scanner.pos
|
356
356
|
end
|
357
357
|
|
358
358
|
comment_depth = 1
|
@@ -393,12 +393,12 @@ module Liquid2
|
|
393
393
|
accept_whitespace_control
|
394
394
|
|
395
395
|
case @scanner.scan(@re_markup_end)
|
396
|
-
when @s_out_end
|
397
|
-
@tokens << [:token_output_end, nil, @start]
|
398
|
-
@start = @scanner.pos
|
399
396
|
when @s_tag_end
|
400
397
|
@tokens << [:token_tag_end, nil, @start]
|
401
398
|
@start = @scanner.pos
|
399
|
+
when @s_out_end
|
400
|
+
@tokens << [:token_output_end, nil, @start]
|
401
|
+
@start = @scanner.pos
|
402
402
|
end
|
403
403
|
|
404
404
|
if @scanner.skip_until(@re_up_to_doc_end)
|
@@ -434,12 +434,12 @@ module Liquid2
|
|
434
434
|
else
|
435
435
|
accept_whitespace_control
|
436
436
|
case @scanner.scan(@re_markup_end)
|
437
|
-
when @s_out_end
|
438
|
-
@tokens << [:token_output_end, nil, @start]
|
439
|
-
@start = @scanner.pos
|
440
437
|
when @s_tag_end
|
441
438
|
@tokens << [:token_tag_end, nil, @start]
|
442
439
|
@start = @scanner.pos
|
440
|
+
when @s_out_end
|
441
|
+
@tokens << [:token_output_end, nil, @start]
|
442
|
+
@start = @scanner.pos
|
443
443
|
end
|
444
444
|
|
445
445
|
:lex_markup
|
@@ -485,12 +485,12 @@ module Liquid2
|
|
485
485
|
@tokens << [:token_tag_end, nil, @start]
|
486
486
|
accept_whitespace_control
|
487
487
|
case @scanner.scan(@re_markup_end)
|
488
|
-
when @s_out_end
|
489
|
-
@tokens << [:token_output_end, nil, @start]
|
490
|
-
@start = @scanner.pos
|
491
488
|
when @s_tag_end
|
492
489
|
@tokens << [:token_tag_end, nil, @start]
|
493
490
|
@start = @scanner.pos
|
491
|
+
when @s_out_end
|
492
|
+
@tokens << [:token_output_end, nil, @start]
|
493
|
+
@start = @scanner.pos
|
494
494
|
end
|
495
495
|
|
496
496
|
return :lex_markup
|
data/lib/liquid2/version.rb
CHANGED
data/sig/liquid2.rbs
CHANGED
@@ -62,6 +62,8 @@ module Liquid2
|
|
62
62
|
# keyword argument.
|
63
63
|
@filters: Hash[String, [_Filter, (Integer | nil)]]
|
64
64
|
|
65
|
+
@persistent_namespaces: Array[Symbol]
|
66
|
+
|
65
67
|
@local_namespace_limit: Integer?
|
66
68
|
|
67
69
|
@context_depth_limit: Integer
|
@@ -90,6 +92,8 @@ module Liquid2
|
|
90
92
|
|
91
93
|
@arithmetic_operators: bool
|
92
94
|
|
95
|
+
@auto_trim: '-' | '~' | nil
|
96
|
+
|
93
97
|
# The string of characters that indicate the start of a Liquid output statement.
|
94
98
|
@markup_out_start: String
|
95
99
|
|
@@ -102,6 +106,8 @@ module Liquid2
|
|
102
106
|
# The string of characters that indicate the end of a Liquid tag.
|
103
107
|
@markup_tag_end: String
|
104
108
|
|
109
|
+
@universal_markup_end: bool
|
110
|
+
|
105
111
|
# The string of characters that indicate the start of a Liquid comment. This should
|
106
112
|
# include a single trailing `#`. Additional, variable length hashes will be handled
|
107
113
|
# by the tokenizer. It is not possible to change comment syntax to not use `#`.
|
@@ -154,6 +160,8 @@ module Liquid2
|
|
154
160
|
|
155
161
|
attr_reader tags: Hash[String, _Tag]
|
156
162
|
|
163
|
+
attr_reader persistent_namespaces: Array[Symbol]
|
164
|
+
|
157
165
|
attr_reader local_namespace_limit: Integer?
|
158
166
|
|
159
167
|
attr_reader context_depth_limit: Integer
|
@@ -184,6 +192,8 @@ module Liquid2
|
|
184
192
|
|
185
193
|
attr_reader markup_tag_start: String
|
186
194
|
|
195
|
+
attr_reader universal_markup_end: bool
|
196
|
+
|
187
197
|
attr_reader re_tag_name: Regexp
|
188
198
|
|
189
199
|
attr_reader re_word: Regexp
|
@@ -216,7 +226,7 @@ module Liquid2
|
|
216
226
|
|
217
227
|
attr_reader re_line_statement_comment: Regexp
|
218
228
|
|
219
|
-
def initialize: (?arithmetic_operators: bool, ?context_depth_limit: ::Integer, ?falsy_undefined: bool, ?globals: untyped?, ?loader: TemplateLoader?, ?local_namespace_limit: Integer?, ?loop_iteration_limit: Integer?, ?markup_comment_prefix: ::String, ?markup_comment_suffix: ::String, ?markup_out_end: ::String, ?markup_out_start: ::String, ?markup_tag_end: ::String, ?markup_tag_start: ::String, ?output_stream_limit: Integer?, ?parser: singleton(Parser), ?scanner: singleton(Scanner), ?shorthand_indexes: bool, ?suppress_blank_control_flow_blocks: bool, ?undefined: singleton(Undefined)) -> void
|
229
|
+
def initialize: (?arithmetic_operators: bool, ?context_depth_limit: ::Integer, ?auto_trim: '-' | '~' | nil, ?falsy_undefined: bool, ?globals: untyped?, ?loader: TemplateLoader?, ?local_namespace_limit: Integer?, ?loop_iteration_limit: Integer?, ?markup_comment_prefix: ::String, ?markup_comment_suffix: ::String, ?markup_out_end: ::String, ?markup_out_start: ::String, ?markup_tag_end: ::String, ?markup_tag_start: ::String, ?output_stream_limit: Integer?, ?parser: singleton(Parser), ?scanner: singleton(Scanner), ?shorthand_indexes: bool, ?suppress_blank_control_flow_blocks: bool, ?undefined: singleton(Undefined)) -> void
|
220
230
|
|
221
231
|
# @param source [String] template source text.
|
222
232
|
# @return [Template]
|
@@ -387,6 +397,8 @@ module Liquid2
|
|
387
397
|
|
388
398
|
@whitespace_carry: String?
|
389
399
|
|
400
|
+
@output_end: Symbol
|
401
|
+
|
390
402
|
# Parse Liquid template text into a syntax tree.
|
391
403
|
# @param source [String]
|
392
404
|
# @return [Array[Node | String]]
|
@@ -512,13 +524,13 @@ module Liquid2
|
|
512
524
|
|
513
525
|
MEMBERSHIP: 6
|
514
526
|
|
515
|
-
PREFIX: 7
|
516
|
-
|
517
527
|
ADD_SUB: 8
|
518
528
|
|
519
529
|
MUL_DIV: 9
|
520
530
|
|
521
531
|
POW: 10
|
532
|
+
|
533
|
+
PREFIX: 11
|
522
534
|
end
|
523
535
|
|
524
536
|
PRECEDENCES: Hash[Symbol, Integer]
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|