liquid2 0.1.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 (84) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.rubocop.yml +46 -0
  4. data/.ruby-version +1 -0
  5. data/.vscode/settings.json +32 -0
  6. data/CHANGELOG.md +5 -0
  7. data/LICENSE.txt +21 -0
  8. data/LICENSE_SHOPIFY.txt +20 -0
  9. data/README.md +219 -0
  10. data/Rakefile +23 -0
  11. data/Steepfile +26 -0
  12. data/lib/liquid2/context.rb +297 -0
  13. data/lib/liquid2/environment.rb +287 -0
  14. data/lib/liquid2/errors.rb +79 -0
  15. data/lib/liquid2/expression.rb +20 -0
  16. data/lib/liquid2/expressions/arguments.rb +25 -0
  17. data/lib/liquid2/expressions/array.rb +20 -0
  18. data/lib/liquid2/expressions/blank.rb +41 -0
  19. data/lib/liquid2/expressions/boolean.rb +20 -0
  20. data/lib/liquid2/expressions/filtered.rb +136 -0
  21. data/lib/liquid2/expressions/identifier.rb +43 -0
  22. data/lib/liquid2/expressions/lambda.rb +53 -0
  23. data/lib/liquid2/expressions/logical.rb +71 -0
  24. data/lib/liquid2/expressions/loop.rb +79 -0
  25. data/lib/liquid2/expressions/path.rb +33 -0
  26. data/lib/liquid2/expressions/range.rb +28 -0
  27. data/lib/liquid2/expressions/relational.rb +119 -0
  28. data/lib/liquid2/expressions/template_string.rb +20 -0
  29. data/lib/liquid2/filter.rb +95 -0
  30. data/lib/liquid2/filters/array.rb +202 -0
  31. data/lib/liquid2/filters/date.rb +20 -0
  32. data/lib/liquid2/filters/default.rb +16 -0
  33. data/lib/liquid2/filters/json.rb +15 -0
  34. data/lib/liquid2/filters/math.rb +87 -0
  35. data/lib/liquid2/filters/size.rb +11 -0
  36. data/lib/liquid2/filters/slice.rb +17 -0
  37. data/lib/liquid2/filters/sort.rb +96 -0
  38. data/lib/liquid2/filters/string.rb +204 -0
  39. data/lib/liquid2/loader.rb +59 -0
  40. data/lib/liquid2/loaders/file_system_loader.rb +76 -0
  41. data/lib/liquid2/loaders/mixins.rb +52 -0
  42. data/lib/liquid2/node.rb +113 -0
  43. data/lib/liquid2/nodes/comment.rb +18 -0
  44. data/lib/liquid2/nodes/output.rb +24 -0
  45. data/lib/liquid2/nodes/tags/assign.rb +35 -0
  46. data/lib/liquid2/nodes/tags/block_comment.rb +26 -0
  47. data/lib/liquid2/nodes/tags/capture.rb +40 -0
  48. data/lib/liquid2/nodes/tags/case.rb +111 -0
  49. data/lib/liquid2/nodes/tags/cycle.rb +63 -0
  50. data/lib/liquid2/nodes/tags/decrement.rb +29 -0
  51. data/lib/liquid2/nodes/tags/doc.rb +24 -0
  52. data/lib/liquid2/nodes/tags/echo.rb +31 -0
  53. data/lib/liquid2/nodes/tags/extends.rb +3 -0
  54. data/lib/liquid2/nodes/tags/for.rb +155 -0
  55. data/lib/liquid2/nodes/tags/if.rb +84 -0
  56. data/lib/liquid2/nodes/tags/include.rb +123 -0
  57. data/lib/liquid2/nodes/tags/increment.rb +29 -0
  58. data/lib/liquid2/nodes/tags/inline_comment.rb +28 -0
  59. data/lib/liquid2/nodes/tags/liquid.rb +29 -0
  60. data/lib/liquid2/nodes/tags/macro.rb +3 -0
  61. data/lib/liquid2/nodes/tags/raw.rb +30 -0
  62. data/lib/liquid2/nodes/tags/render.rb +137 -0
  63. data/lib/liquid2/nodes/tags/tablerow.rb +143 -0
  64. data/lib/liquid2/nodes/tags/translate.rb +3 -0
  65. data/lib/liquid2/nodes/tags/unless.rb +23 -0
  66. data/lib/liquid2/nodes/tags/with.rb +3 -0
  67. data/lib/liquid2/parser.rb +917 -0
  68. data/lib/liquid2/scanner.rb +595 -0
  69. data/lib/liquid2/static_analysis.rb +301 -0
  70. data/lib/liquid2/tag.rb +22 -0
  71. data/lib/liquid2/template.rb +182 -0
  72. data/lib/liquid2/undefined.rb +131 -0
  73. data/lib/liquid2/utils/cache.rb +80 -0
  74. data/lib/liquid2/utils/chain_hash.rb +40 -0
  75. data/lib/liquid2/utils/unescape.rb +119 -0
  76. data/lib/liquid2/version.rb +5 -0
  77. data/lib/liquid2.rb +90 -0
  78. data/performance/benchmark.rb +73 -0
  79. data/performance/memory_profile.rb +62 -0
  80. data/performance/profile.rb +71 -0
  81. data/sig/liquid2.rbs +2348 -0
  82. data.tar.gz.sig +0 -0
  83. metadata +164 -0
  84. metadata.gz.sig +0 -0
data/sig/liquid2.rbs ADDED
@@ -0,0 +1,2348 @@
1
+ module Liquid2
2
+ interface _HasToken
3
+ def token: () -> [Symbol, String?, Integer]
4
+ end
5
+
6
+ interface _Tag
7
+ def parse: ([Symbol, String?, Integer], Parser) -> Tag
8
+ end
9
+
10
+ # TODO: Revisit this. I can't find a way to define a callable interface with arbitrary
11
+ # arguments that type checks against lambda literals.
12
+ interface _Filter
13
+ # def call: (untyped left, *untyped, **untyped) -> untyped
14
+ def parameters: () -> untyped
15
+ def respond_to?: (Symbol) -> bool
16
+ end
17
+
18
+ interface _Undefined
19
+ def new: (String name, ?node: (_HasToken | nil)) -> Undefined
20
+ end
21
+
22
+ VERSION: String
23
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
24
+
25
+ DEFAULT_ENVIRONMENT: Environment
26
+
27
+ def self.parse: (String source, ?globals: Hash[String, untyped]?) -> Template
28
+
29
+ def self.render: (String source, ?Hash[String, untyped]? data) -> String
30
+
31
+ def self.to_liquid_string: (untyped obj) -> String
32
+
33
+ def self.to_output_string: (untyped obj) -> String
34
+
35
+ def self.to_liquid_int: (untyped obj, ?default: ::Integer) -> Integer
36
+
37
+ # Return `true` if _obj_ is Liquid truthy.
38
+ # @param context [RenderContext]
39
+ # @param obj [Object]
40
+ # @return [bool]
41
+ def self.truthy?: (RenderContext context, untyped obj) -> bool
42
+
43
+ # Return `true` if _obj_ is undefined.
44
+ def self.undefined?: (untyped obj) -> bool
45
+
46
+ alias self.to_s self.to_liquid_string
47
+
48
+ alias self.to_output_s self.to_output_string
49
+
50
+ alias self.to_i self.to_liquid_int
51
+
52
+ # Template parsing and rendering configuration.
53
+ #
54
+ # A Liquid::Environment is where you might register custom tags and filters,
55
+ # or store global context data that should be available to all templates.
56
+ class Environment
57
+ # A mapping of tag names to objects responding to `parse`.
58
+ @tags: Hash[String, _Tag]
59
+
60
+ # A mapping of filter names to objects responding to `#call(left, ...)`,
61
+ # along with a flag to indicate if the callable accepts a `context`
62
+ # keyword argument.
63
+ @filters: Hash[String, [_Filter, (Integer | nil)]]
64
+
65
+ @local_namespace_limit: Integer?
66
+
67
+ @context_depth_limit: Integer
68
+
69
+ @loop_iteration_limit: Integer?
70
+
71
+ @output_stream_limit: Integer?
72
+
73
+ @suppress_blank_control_flow_blocks: bool
74
+
75
+ @shorthand_indexes: bool
76
+
77
+ @undefined: singleton(Undefined)
78
+
79
+ @loader: TemplateLoader
80
+
81
+ @globals: Hash[String, untyped]?
82
+
83
+ @scanner: StringScanner
84
+
85
+ attr_reader tags: Hash[String, _Tag]
86
+
87
+ attr_reader local_namespace_limit: Integer?
88
+
89
+ attr_reader context_depth_limit: Integer
90
+
91
+ attr_reader loop_iteration_limit: Integer?
92
+
93
+ attr_reader output_stream_limit: Integer?
94
+
95
+ attr_reader filters: Hash[String, [_Filter, (Integer | nil)]]
96
+
97
+ attr_reader suppress_blank_control_flow_blocks: bool
98
+
99
+ attr_reader shorthand_indexes: bool
100
+
101
+ def initialize: (?context_depth_limit: ::Integer, ?globals: Hash[String, untyped]?, ?loader: TemplateLoader?, ?local_namespace_limit: Integer?, ?loop_iteration_limit: Integer?, ?output_stream_limit: Integer?, ?shorthand_indexes: bool, ?suppress_blank_control_flow_blocks: bool, ?undefined: singleton(Undefined)) -> void
102
+
103
+ # @param source [String] template source text.
104
+ # @return [Template]
105
+ def parse: (String source, ?name: String, ?path: String?, ?up_to_date: Proc::_Callable?, ?globals: Hash[String, untyped]?, ?overlay: Hash[String, untyped]?) -> Template
106
+
107
+ def render: (String source, ?Hash[String, untyped]?) -> String
108
+
109
+ # Add or replace a filter. The same callable can be registered multiple times with
110
+ # different names.
111
+ #
112
+ # If _callable_ accepts a keyword parameter called `context`, the active render
113
+ # context will be passed to `#call`.
114
+ #
115
+ # @param name [String] The name of the filter, as used by template authors.
116
+ # @param callable [responds to call] An object that responds to `#call(left, ...)`
117
+ # and `#parameters`. Like a Proc or Method.
118
+ def register_filter: (String name, _Filter callable) -> void
119
+
120
+ # Remove a filter from the filter register.
121
+ # @param name [String] The name of the filter.
122
+ # @return [callable | nil] The callable implementing the removed filter, or nil
123
+ # if _name_ did not exist in the filter register.
124
+ def delete_filter: (String name) -> ([_Filter, (Integer | nil)] | nil)
125
+
126
+ def setup_tags_and_filters: () -> void
127
+
128
+ def undefined: (String name, ?node: _HasToken?) -> Undefined
129
+
130
+ def trim: (String text, String? left_trim, String? right_trim) -> void
131
+
132
+ # Load and parse a template using the configured template loader.
133
+ # @param name [String] The template's name.
134
+ # @param globals [Hash[String, untyped]?] Render context variables to attach to the template.
135
+ # @param context [RenderContext?] An optional render context that can be used to
136
+ # narrow the template search space.
137
+ # @param kwargs Arbitrary arguments that can be used to narrow the template search
138
+ # space.
139
+ # @return [Template]
140
+ def get_template: (String name, ?globals: Hash[String, untyped]?, ?context: RenderContext?, **untyped) -> Template
141
+
142
+ # Merge environment globals with another namespace.
143
+ def make_globals: ((Hash[String, untyped] | nil) namespace) -> Hash[String, untyped]?
144
+ end
145
+ end
146
+
147
+ module Liquid2
148
+ # Liquid template source text lexical scanner.
149
+ #
150
+ # This is a single pass tokenizer. We support tag and output delimiters inside string
151
+ # literals, so we must scan expressions as we go.
152
+ #
153
+ # We give comment and raw tags special consideration here.
154
+ class Scanner
155
+ @source: String
156
+
157
+ @scanner: StringScanner
158
+
159
+ # A pointer to the start of the current token.
160
+ @start: Integer
161
+
162
+ # Tokens are arrays of (kind, value, start index)
163
+ @tokens: Array[[Symbol, String?, Integer]]
164
+
165
+ attr_reader tokens: Array[[Symbol, String?, Integer]]
166
+
167
+ RE_MARKUP_START: ::Regexp
168
+
169
+ RE_WHITESPACE: ::Regexp
170
+
171
+ RE_LINE_SPACE: ::Regexp
172
+
173
+ RE_WORD: ::Regexp
174
+
175
+ RE_INT: ::Regexp
176
+
177
+ RE_FLOAT: ::Regexp
178
+
179
+ RE_PUNCTUATION: ::Regexp
180
+
181
+ RE_SINGLE_QUOTE_STRING_SPECIAL: ::Regexp
182
+
183
+ RE_DOUBLE_QUOTE_STRING_SPECIAL: ::Regexp
184
+
185
+ # Keywords and symbols that get their own token kind.
186
+ TOKEN_MAP: Hash[String, Symbol]
187
+
188
+ def self.tokenize: (String source, StringScanner scanner) -> Array[[Symbol, String?, Integer]]
189
+
190
+ # @param source [String]
191
+ # @param scanner [StringScanner]
192
+ def initialize: (String source, StringScanner scanner) -> void
193
+
194
+ def run: () -> void
195
+
196
+ # @param kind [Symbol]
197
+ # @param value [String?]
198
+ # @return void
199
+ def emit: (Symbol kind, String? value) -> void
200
+
201
+ def skip_trivia: () -> void
202
+
203
+ def skip_line_trivia: () -> void
204
+
205
+ def accept_whitespace_control: () -> bool
206
+
207
+ def lex_markup: () -> Symbol?
208
+
209
+ def lex_expression: () -> Symbol?
210
+
211
+ def lex_doc: () -> Symbol?
212
+
213
+ def lex_raw: () -> Symbol?
214
+
215
+ def lex_comment: () -> Symbol?
216
+
217
+ def lex_block_comment: () -> Symbol?
218
+
219
+ def lex_inside_inline_comment: () -> Symbol?
220
+
221
+ def lex_line_statements: () -> Symbol?
222
+
223
+ def lex_inside_line_statement: () -> Symbol?
224
+
225
+ # Scan a string literal surrounded by _quote_.
226
+ # Assumes the opening quote has already been consumed and emitted.
227
+ def scan_string: (("\"" | "'"), Symbol, Regexp) -> void
228
+ end
229
+ end
230
+
231
+ module Liquid2
232
+ # Liquid template parser.
233
+ class Parser
234
+ @env: Environment
235
+
236
+ @tokens: Array[[Symbol, String?, Integer]]
237
+
238
+ @pos: Integer
239
+
240
+ @eof: [Symbol, String?, Integer]
241
+
242
+ @whitespace_carry: String?
243
+
244
+ # Parse Liquid template text into a syntax tree.
245
+ # @param source [String]
246
+ # @return [Array[Node | String]]
247
+ def self.parse: (Environment env, String source, ?scanner: StringScanner?) -> Array[Node | String]
248
+
249
+ # @param env [Environment]
250
+ # @param tokens [Array[[Symbol, String?, Integer]]]
251
+ def initialize: (Environment env, Array[[Symbol, String?, Integer]] tokens, Integer length) -> void
252
+
253
+ # Return the current token without advancing the pointer.
254
+ # An EOF token is returned if there are no tokens left.
255
+ def current: () -> [Symbol, String?, Integer]
256
+
257
+ # Return the kind of the current token without advancing the pointer.
258
+ def current_kind: () -> Symbol
259
+
260
+ # Return the next token and advance the pointer.
261
+ def next: () -> [Symbol, String?, Integer]
262
+
263
+ # Return the kind of the next token and advance the pointer
264
+ def next_kind: () -> Symbol
265
+
266
+ def peek: (?::Integer offset) -> [Symbol, String?, Integer]
267
+
268
+ def peek_kind: (?::Integer offset) -> Symbol
269
+
270
+ def previous: () -> [Symbol, String?, Integer]
271
+
272
+ # Consume the next token if its kind matches _kind_, raise an error if it does not.
273
+ # @param kind [Symbol]
274
+ # @return [Token] The consumed token.
275
+ def eat: (Symbol kind, ?String? message) -> [Symbol, String?, Integer]
276
+
277
+ # Consume the next token if its kind is in _kinds_, raise an error if it does not.
278
+ # @param kind [Symbol]
279
+ # @return [Token] The consumed token.
280
+ def eat_one_of: (*Symbol kinds) -> [Symbol, String?, Integer]
281
+
282
+ # @param name [String]
283
+ # @return The :token_tag_name token.
284
+ def eat_empty_tag: (String name) -> [Symbol, String?, Integer]
285
+
286
+ # Return `true` if we're at the start of a tag named _name_.
287
+ # @param name [String]
288
+ # @return [bool]
289
+ def tag?: (String name) -> bool
290
+
291
+ # Return `true` if the current token is a word matching _text_.
292
+ # @param text [String]
293
+ # @return [bool]
294
+ def word?: (String text) -> bool
295
+
296
+ # Return the next tag name without advancing the pointer.
297
+ # Assumes the current token is :token_tag_start.
298
+ # @return [String]
299
+ def peek_tag_name: () -> String
300
+
301
+ # Advance the pointer if the current token is a whitespace control token.
302
+ def skip_whitespace_control: () -> void
303
+
304
+ # Advance the pointer if the current token is a whitespace control token, and
305
+ # remember the token's value for the next text node.
306
+ def carry_whitespace_control: () -> void
307
+
308
+ # Raise a syntax error if we're not at the start of an expression.
309
+ def expect_expression: () -> void
310
+
311
+ # @return [Array[Node | String]]
312
+ def parse: () -> Array[Node | String]
313
+
314
+ # Parse Liquid markup until we find a tag token in _end_block_.
315
+ # @param end_block [responds to include?] An array or set of tag names that will
316
+ # indicate the end of the block.
317
+ # @return [Block]
318
+ def parse_block: (Set[String] end_block) -> Block
319
+
320
+ # @return [FilteredExpression|TernaryExpression]
321
+ def parse_filtered_expression: () -> (FilteredExpression | TernaryExpression)
322
+
323
+ # @return [LoopExpression]
324
+ def parse_loop_expression: () -> LoopExpression
325
+
326
+ def parse_line_statements: () -> Block
327
+
328
+ # Parse a _primary_ expression.
329
+ # A primary expression is a literal, a path (to a variable), or a logical
330
+ # expression composed of other primary expressions.
331
+ def parse_primary: (?precedence: Integer, ?infix: bool) -> untyped
332
+
333
+ # Parse a string literal without interpolation..
334
+ # @return [String]
335
+ # @raises [LiquidTypeError].
336
+ def parse_string: () -> String
337
+
338
+ def parse_identifier: (?trailing_question: bool) -> Identifier
339
+
340
+ # Parse comma separated expression.
341
+ # Leading commas should be consumed by the caller.
342
+ # @return [Array[Expression]]
343
+ def parse_positional_arguments: () -> Array[untyped]
344
+
345
+ # Parse comma name/value pairs.
346
+ # Leading commas should be consumed by the caller.
347
+ # @return [Array<KeywordArgument>]
348
+ def parse_keyword_arguments: () -> Array[KeywordArgument]
349
+
350
+ class Precedence
351
+ LOWEST: 1
352
+
353
+ LOGICAL_RIGHT: 2
354
+
355
+ LOGICAL_OR: 3
356
+
357
+ LOGICAL_AND: 4
358
+
359
+ RELATIONAL: 5
360
+
361
+ MEMBERSHIP: 6
362
+
363
+ PREFIX: 7
364
+ end
365
+
366
+ PRECEDENCES: Hash[Symbol, Integer]
367
+
368
+ BINARY_OPERATORS: Set[Symbol]
369
+
370
+ TERMINATE_EXPRESSION: Set[Symbol]
371
+
372
+ TERMINATE_FILTER: Set[Symbol]
373
+
374
+ TERMINATE_GROUPED_EXPRESSION: Set[Symbol]
375
+
376
+ TERMINATE_LAMBDA_PARAM: Set[Symbol]
377
+
378
+ KEYWORD_ARGUMENT_DELIMITERS: Set[Symbol]
379
+
380
+ PRIMITIVE_TOKENS: Set[Symbol]
381
+
382
+ RESERVED_WORDS: Set[Symbol]
383
+
384
+ LOOP_KEYWORDS: Set[String]
385
+
386
+ WC_TOKENS: Set[Symbol]
387
+
388
+ PATH_PUNCTUATION: Set[Symbol]
389
+
390
+ # @return [Output]
391
+ def parse_output: () -> Output
392
+
393
+ def parse_tag: () -> Tag
394
+
395
+ def parse_comment: () -> Comment
396
+
397
+ def parse_path: () -> Path
398
+
399
+ def parse_bracketed_path_selector: () -> (String | Integer | Path)
400
+
401
+ def parse_shorthand_path_selector: () -> (String | Integer)
402
+
403
+ def parse_range_lambda_or_grouped_expression: () -> untyped
404
+
405
+ def parse_prefix_expression: () -> untyped
406
+
407
+ # @param left [Expression]
408
+ def parse_infix_expression: (untyped left) -> untyped
409
+
410
+ # @return [Array<Filter>]
411
+ def parse_filters: () -> Array[Filter]
412
+
413
+ # @return [Filter]
414
+ def parse_filter: () -> Filter
415
+
416
+ def parse_array_literal: (untyped left) -> ArrayLiteral
417
+
418
+ def parse_arrow_function: () -> untyped
419
+
420
+ # @param expr [Expression] The first parameter already passed by the caller.
421
+ # @return [Expression]
422
+ def parse_partial_arrow_function: (untyped expr) -> untyped
423
+
424
+ # @param left [Expression]
425
+ def parse_ternary_expression: (FilteredExpression left) -> TernaryExpression
426
+
427
+ def parse_string_literal: () -> (String | TemplateString)
428
+ end
429
+ end
430
+
431
+ module Liquid2
432
+ # A compiled template bound to a Liquid environment and ready to be rendered.
433
+ class Template
434
+ @env: Environment
435
+
436
+ @source: String
437
+
438
+ @ast: Array[Node | String]
439
+
440
+ @name: String
441
+
442
+ @path: String?
443
+
444
+ @globals: Hash[String, untyped]
445
+
446
+ @overlay: Hash[String, untyped]
447
+
448
+ @up_to_date: Proc::_Callable?
449
+
450
+ attr_reader env: Environment
451
+
452
+ attr_reader ast: Array[Node | String]
453
+
454
+ attr_reader name: String
455
+
456
+ attr_reader path: String?
457
+
458
+ attr_reader globals: Hash[String, untyped]
459
+
460
+ attr_reader overlay: Hash[String, untyped]
461
+
462
+ attr_reader up_to_date: Proc::_Callable?
463
+
464
+ # @param env [Environment]
465
+ # @param ast [RootNode]
466
+ # @param name [String] The template's name.
467
+ # @param path [String?] The path or other qualifying data to _name_.
468
+ # @param up_to_date [_Callable] A proc that returns `false` if the template has been
469
+ # modified and need to be reloaded.
470
+ # @param globals [Hash[String, untyped]] Global template variables.
471
+ # @param overlay [Hash[String, untyped]] Additional template variables. Could be from front matter
472
+ # or other meta data store, for example.
473
+ def initialize: (Environment env, String source, Array[Node | String] ast, ?name: String, ?path: String?, ?up_to_date: Proc::_Callable?, ?globals: Hash[String, untyped]?, ?overlay: Hash[String, untyped]?) -> void
474
+
475
+ def to_s: () -> String
476
+
477
+ def full_name: () -> String
478
+
479
+ def render: (?Hash[String, untyped]? globals) -> String
480
+
481
+ def analyze: (?include_partials: bool) -> StaticAnalysis::Result
482
+
483
+ def render_with_context: (RenderContext context, String buffer, ?partial: bool, ?block_scope: bool, ?namespace: Hash[String, untyped]?) -> void
484
+
485
+ # Merge templates globals with another namespace.
486
+ def make_globals: (Hash[String, untyped]? namespace) -> Hash[String, untyped]
487
+
488
+ def up_to_date?: () -> bool?
489
+
490
+ def comments: () -> Array[BlockComment | InlineComment | Comment]
491
+
492
+ # Return an array of variables used in this template, without path segments.
493
+ # @param include_partials [bool]
494
+ # @return [Array[String]]
495
+ def variables: (?include_partials: bool) -> Array[String]
496
+
497
+ # Return an array of variables used in this template, including path segments.
498
+ # @param include_partials [bool]
499
+ # @return [Array[String]]
500
+ def variable_paths: (?include_partials: bool) -> Array[String]
501
+
502
+ # Return an array of variables used in this template, each as an array of segments.
503
+ # @param include_partials [bool]
504
+ # @return [Array[Array[String | Integer | Segment]]]
505
+ def variable_segments: (?include_partials: bool) -> Array[untyped]
506
+
507
+ # Return an array of global variables used in this template, without path segments.
508
+ # @param include_partials [bool]
509
+ # @return [Array[String]]
510
+ def global_variables: (?include_partials: bool) -> Array[String]
511
+
512
+ # Return an array of global variables used in this template, including path segments.
513
+ # @param include_partials [bool]
514
+ # @return [Array[String]]
515
+ def global_variable_paths: (?include_partials: bool) -> Array[String]
516
+
517
+ # Return an array of global variables used in this template, each as an array of segments.
518
+ # @param include_partials [bool]
519
+ # @return [Array[Array[String | Integer | Segment]]]
520
+ def global_variable_segments: (?include_partials: bool) -> Array[untyped]
521
+
522
+ # Return the names of all filters used in this template.
523
+ # @param include_partials [bool]
524
+ # @return [Array[String]]
525
+ def filter_names: (?include_partials: bool) -> Array[String]
526
+
527
+ # Return the names of all tags used in this template.
528
+ # @param include_partials [bool]
529
+ # @return [Array[String]]
530
+ def tag_names: (?include_partials: bool) -> Array[String]
531
+ end
532
+
533
+ # Liquid template source text and meta data.
534
+ class TemplateSource
535
+ @source: String
536
+
537
+ @name: String
538
+
539
+ @up_to_date: Proc::_Callable?
540
+
541
+ @matter: Hash[String, untyped]?
542
+
543
+ attr_reader source: String
544
+
545
+ attr_reader name: String
546
+
547
+ attr_reader up_to_date: Proc::_Callable?
548
+
549
+ attr_reader matter: Hash[String, untyped]?
550
+
551
+ def initialize: (source: String, name: String, ?up_to_date: Proc::_Callable?, ?matter: Hash[String, untyped]?) -> void
552
+ end
553
+
554
+ # The base class for all template loaders.
555
+ class TemplateLoader
556
+ # Load and return template source text and any associated data.
557
+ # @param env [Environment] The current Liquid environment.
558
+ # @param name [String] A name or identifier for the target template source text.
559
+ # @param context [RenderContext?] The current render context, if one is available.
560
+ # @param *kwargs Arbitrary arguments that can be used to narrow the template source
561
+ # search space.
562
+ # @return [TemplateSource]
563
+ def get_source: (Environment env, String name, ?context: RenderContext?, **untyped kwargs) -> TemplateSource
564
+
565
+ def load: (Environment env, String name, ?globals: Hash[String, untyped]?, ?context: RenderContext?, **untyped kwargs) -> Template
566
+ end
567
+
568
+ # A template loader that reads templates from a hash.
569
+ class HashLoader < TemplateLoader
570
+ @templates: Hash[String, String]
571
+
572
+ # @param templates [Hash<String, String>] A mapping of template names to template source text.
573
+ def initialize: (Hash[String, String] templates) -> void
574
+
575
+ def get_source: (Environment env, String name, ?context: RenderContext?, **untyped kwargs) -> TemplateSource
576
+ end
577
+
578
+ # The default undefined type. Can be iterated over an indexed without error.
579
+ class Undefined
580
+ @name: untyped
581
+
582
+ @node: untyped
583
+
584
+ @force_default: bool
585
+
586
+ attr_reader force_default: bool
587
+
588
+ def initialize: (String name, ?node: _HasToken?) -> void
589
+
590
+ def []: (*untyped) ?{ (?) -> untyped } -> self
591
+
592
+ def key?: (*untyped) ?{ (?) -> untyped } -> false
593
+
594
+ def include?: (*untyped) ?{ (?) -> untyped } -> false
595
+
596
+ def member?: (*untyped) ?{ (?) -> untyped } -> false
597
+
598
+ def fetch: (*untyped) ?{ (?) -> untyped } -> self
599
+
600
+ def !: () -> true
601
+
602
+ def ==: (untyped other) -> untyped
603
+
604
+ alias eql? ==
605
+
606
+ def size: () -> 0
607
+
608
+ def length: () -> 0
609
+
610
+ def to_s: () -> ""
611
+
612
+ def to_i: () -> 0
613
+
614
+ def to_f: () -> ::Float
615
+
616
+ def each: (*untyped) ?{ (?) -> untyped } -> untyped
617
+
618
+ def each_with_index: (*untyped) ?{ (?) -> untyped } -> untyped
619
+
620
+ def join: (*untyped) -> ""
621
+
622
+ def to_liquid: (RenderContext _context) -> nil
623
+
624
+ def poke: () -> true
625
+ end
626
+
627
+ # An undefined type that always raises an exception.
628
+ class StrictUndefined < Undefined
629
+ @message: String
630
+
631
+ def initialize: (String name, ?node: Node?) -> void
632
+
633
+ def respond_to_missing?: () -> true
634
+
635
+ def method_missing: (*untyped) ?{ (?) -> untyped } -> untyped
636
+
637
+ def []: (*untyped) ?{ (?) -> untyped } -> untyped
638
+
639
+ def key?: (*untyped) ?{ (?) -> untyped } -> untyped
640
+
641
+ def include?: (*untyped) ?{ (?) -> untyped } -> untyped
642
+
643
+ def member?: (*untyped) ?{ (?) -> untyped } -> untyped
644
+
645
+ def fetch: (*untyped) ?{ (?) -> untyped } -> untyped
646
+
647
+ def !: () -> untyped
648
+
649
+ def ==: (untyped _other) -> untyped
650
+
651
+ def !=: (untyped _other) -> untyped
652
+
653
+ alias eql? ==
654
+
655
+ def size: () -> untyped
656
+
657
+ def length: () -> untyped
658
+
659
+ def to_s: () -> untyped
660
+
661
+ def to_i: () -> untyped
662
+
663
+ def to_f: () -> untyped
664
+
665
+ def each: (*untyped) ?{ (?) -> untyped } -> untyped
666
+
667
+ def each_with_index: (*untyped) ?{ (?) -> untyped } -> untyped
668
+
669
+ def join: (*untyped) -> untyped
670
+
671
+ def to_liquid: (RenderContext _context) -> untyped
672
+
673
+ def poke: () -> bool
674
+ end
675
+
676
+ # A strict undefined type that plays nicely with the _default_ filter.
677
+ class StrictDefaultUndefined < StrictUndefined
678
+ @force_default: bool
679
+
680
+ def initialize: (String name, ?node: Node?) -> void
681
+ end
682
+ end
683
+
684
+ module Liquid2
685
+
686
+ # The base class for all nodes in a Liquid syntax tree.
687
+ class Node
688
+ @token: [Symbol, String?, Integer]
689
+
690
+ @blank: bool
691
+
692
+ attr_accessor blank: bool
693
+
694
+ attr_reader token: [Symbol, String?, Integer]
695
+
696
+ # @param token [[Symbol, String?, Integer]]
697
+ def initialize: ([Symbol, String?, Integer] token) -> void
698
+
699
+ def render: (RenderContext context, String buffer) -> void
700
+
701
+ def render_with_disabled_tag_check: (RenderContext context, String buffer) -> void
702
+
703
+ # Return all children of this node.
704
+ def children: (RenderContext _static_context, ?include_partials: bool) -> ::Array[Node | String]
705
+
706
+ # Return this node's expressions.
707
+ def expressions: () -> ::Array[untyped]
708
+
709
+ # Return variables this node adds to the template local scope.
710
+ def template_scope: () -> ::Array[Identifier]
711
+
712
+ # Return variables this nodes adds to its block scope.
713
+ def block_scope: () -> ::Array[Identifier]
714
+
715
+ # Return information about a partial template loaded by this node.
716
+ def partial_scope: () -> Partial?
717
+ end
718
+
719
+ # Partial template meta data.
720
+ class Partial
721
+ @name: untyped
722
+
723
+ @scope: (:shared | :isolated | :inherited)
724
+
725
+ @in_scope: Array[Identifier]
726
+
727
+ attr_reader name: untyped
728
+
729
+ attr_reader scope: :shared | :isolated | :inherited
730
+
731
+ attr_reader in_scope: Array[Identifier]
732
+
733
+ # @param name [Expression | String] The name of the partial template.
734
+ # @param scope [:shared | :isolated | :inherited] A symbol indicating the kind of
735
+ # scope the partial template should have when loaded.
736
+ # @param in_scope [Array[Identifier]] Names that will be added to the scope of the
737
+ # partial template.
738
+ def initialize: (untyped name, (:shared | :isolated | :inherited) scope, Array[Identifier] in_scope) -> void
739
+ end
740
+
741
+ # An node representing a block of Liquid markup.
742
+ # Essentially an array of other nodes and strings.
743
+ # @param token [[Symbol, String?, Integer]]
744
+ # @param nodes [Array[Node | String]]
745
+ class Block < Node
746
+ @nodes: Array[Node | String]
747
+
748
+ def initialize: ([Symbol, String?, Integer] token, Array[Node | String] nodes) -> void
749
+
750
+ def render: (RenderContext context, String buffer) -> void
751
+ end
752
+
753
+ # A Liquid block guarded by an expression.
754
+ # Only if the expression evaluates to a truthy value will the block be rendered.
755
+ class ConditionalBlock < Node
756
+ @expression: untyped
757
+
758
+ @block: Block
759
+
760
+ @blank: bool
761
+
762
+ attr_reader expression: untyped
763
+
764
+ attr_reader block: Block
765
+
766
+ def initialize: ([Symbol, String?, Integer] token, untyped expression, Block block) -> void
767
+
768
+ def render: (RenderContext context, String buffer) -> void
769
+ end
770
+
771
+ # Base class for all Liquid tags.
772
+ class Tag < Node
773
+ # Render this node to the output buffer.
774
+ # @param context [RenderContext]
775
+ # @param buffer [StringIO]
776
+ def render: (RenderContext context, String buffer) -> void
777
+
778
+ # Return the tags name.
779
+ def name: () -> String
780
+ end
781
+ end
782
+
783
+ module Liquid2
784
+
785
+ # Hash-like object for resolving built-in dynamic objects.
786
+ class BuiltIn
787
+ def key?: (String key) -> bool
788
+
789
+ def fetch: (String key, ?::Symbol default) -> untyped
790
+
791
+ def []: (String key) -> untyped?
792
+ end
793
+
794
+ # Per render contextual information. A new RenderContext is created automatically
795
+ # every time `Template#render` is called.
796
+ class RenderContext
797
+ @env: Environment
798
+
799
+ @template: Template
800
+
801
+ @globals: _Namespace
802
+
803
+ @disabled_tags: (Array[String] | Set[String])
804
+
805
+ @copy_depth: Integer
806
+
807
+ @parent: RenderContext?
808
+
809
+ @loop_carry: Integer
810
+
811
+ # The current size of the local namespace. _size_ is a non-specific measure of the
812
+ # amount of memory used to store template local variables.
813
+ @assign_score: Integer
814
+
815
+ # A namespace for template local variables (those bound with `assign` or `capture`).
816
+ @locals: Hash[String, untyped]
817
+
818
+ # A namespace for `increment` and `decrement` counters.
819
+ @counters: Hash[String, Integer]
820
+
821
+ # Namespaces are searched from right to left. When a RenderContext is extended, the
822
+ # temporary namespace is pushed to the end of this queue.
823
+ @scope: ReadOnlyChainHash
824
+
825
+ # A namespace supporting stateful tags, such as `cycle` and `increment`.
826
+ # It's OK to use this hash for storing custom tag state.
827
+ @tag_namespace: Hash[Symbol, untyped]
828
+
829
+ # A stack of forloop objects used for populating forloop.parentloop.
830
+ @loops: Array[ForLoop]
831
+
832
+ # A stack of interrupts used to signal breaking and continuing `for` loops.
833
+ @interrupts: Array[:break | :continue]
834
+
835
+ attr_reader env: Environment
836
+
837
+ attr_reader template: Template
838
+
839
+ attr_reader globals: _Namespace
840
+
841
+ attr_reader disabled_tags: (Array[String] | Set[String])
842
+
843
+ attr_reader tag_namespace: Hash[Symbol, untyped]
844
+
845
+ attr_accessor interrupts: Array[:break | :continue]
846
+
847
+
848
+ BUILT_IN: BuiltIn
849
+
850
+ # @param template [Template]
851
+ # @param globals [Hash<String, Object>?]
852
+ # @param disabled_tags [Array<String>?]
853
+ # @param copy_depth [Integer?]
854
+ # @param parent [RenderContext?]
855
+ # @param loop_carry [Integer?]
856
+ # @param local_namespace_carry [Integer?]
857
+ def initialize: (Template template, ?globals: _Namespace?, ?disabled_tags: (Array[String] | Set[String])?, ?copy_depth: ::Integer, ?parent: RenderContext?, ?loop_carry: ::Integer, ?local_namespace_carry: ::Integer) -> void
858
+
859
+ def evaluate: (untyped obj) -> untyped
860
+
861
+ # Add _key_ to the local scope with value _value_.
862
+ # @param key [String]
863
+ # @param value [Object]
864
+ def assign: (String key, untyped value) -> void
865
+
866
+ alias []= assign
867
+
868
+ # Resolve _path_ to variable/data in the current scope.
869
+ # @param head [String|Integer] First segment of the path.
870
+ # @param path [Array<String|Integer>] Remaining path segments.
871
+ # @param node [Node?] An associated token to use for error context.
872
+ # @param default [Object?] A default value to return if the path can no be resolved.
873
+ # @return [Object]
874
+ def fetch: (untyped head, Array[untyped] path, node: _HasToken, ?default: untyped) -> untyped
875
+
876
+ # Resolve variable _name_ in the current scope.
877
+ # @param name [String]
878
+ def resolve: (untyped name) -> untyped
879
+
880
+ alias [] resolve
881
+
882
+ # Extend the scope of this context with the given namespace. Expects a block.
883
+ # @param namespace [Hash<String, Object>]
884
+ # @param template [Template?] Replace the current template for the duration of the block.
885
+ def extend: (untyped namespace, ?template: untyped?) { () -> untyped } -> untyped
886
+
887
+ # Copy this render context and add _namespace_ to the new scope.
888
+ # @param namespace [Hash<String, Object>]
889
+ # @param template [Template?] The template object bound to the new context.
890
+ # @param disabled_tags [Set<String>] Names of tags to disallow in the new context.
891
+ # @param carry_loop_iterations [bool] If true, pass the current loop iteration count to the
892
+ # new context.
893
+ # @param block_scope [bool] It true, retain the current scope in the new context. Otherwise
894
+ # only global variables will be included in the new context's scope.
895
+ def copy: (untyped namespace, ?template: untyped?, ?disabled_tags: untyped?, ?carry_loop_iterations: bool, ?block_scope: bool) -> untyped
896
+
897
+ # Push a new namespace and forloop for the duration of a block.
898
+ # @param namespace [Hash<String, Object>]
899
+ # @param forloop [ForLoop]
900
+ def loop: (untyped namespace, untyped forloop) { () -> untyped } -> untyped
901
+
902
+ # Return the last ForLoop object if one is available, or an instance of Undefined otherwise.
903
+ def parent_loop: (untyped node) -> untyped
904
+
905
+ # Get or set the stop index of a for loop.
906
+ def stop_index: (untyped key, ?index: untyped?) -> untyped
907
+
908
+ def raise_for_loop_limit: (?length: ::Integer) -> void
909
+
910
+ def raise_for_output_limit: (Integer length) -> void
911
+
912
+ def get_output_buffer: (untyped parent_buffer) -> untyped
913
+
914
+ # Mark _string_ as "safe" if auto escape is enabled.
915
+ def markup: (untyped string) -> untyped
916
+
917
+ def cycle: (untyped key, untyped length) -> untyped
918
+
919
+ def increment: (untyped name) -> untyped
920
+
921
+ def decrement: (untyped name) -> untyped
922
+
923
+ def assign_score: (untyped value) -> untyped
924
+
925
+ end
926
+ end
927
+
928
+ module Liquid2
929
+ # The base class for all Liquid errors.
930
+ class LiquidError < StandardError
931
+ FULL_MESSAGE: bool
932
+
933
+ @token: ([Symbol, String?, Integer] | nil)
934
+
935
+ @template_name: String?
936
+
937
+ @source: String?
938
+
939
+ attr_accessor token: ([Symbol, String?, Integer] | nil)
940
+
941
+ attr_accessor template_name: (String | nil)
942
+
943
+ attr_accessor source: (String | nil)
944
+
945
+ def initialize: (String message, ?[Symbol, String?, Integer]? token) -> void
946
+
947
+ def detailed_message: (?highlight: bool, **untyped kwargs) -> String
948
+
949
+ def full_message: (?highlight: bool, ?order: ::Symbol) -> String
950
+
951
+ def error_context: (String source, Integer index) -> [Integer, Integer, String]
952
+ end
953
+
954
+ class LiquidSyntaxError < LiquidError
955
+ end
956
+
957
+ class LiquidArgumentError < LiquidError
958
+ end
959
+
960
+ class LiquidTypeError < LiquidError
961
+ end
962
+
963
+ class LiquidTemplateNotFoundError < LiquidError
964
+ end
965
+
966
+ class LiquidFilterNotFoundError < LiquidError
967
+ end
968
+
969
+ class LiquidResourceLimitError < LiquidError
970
+ end
971
+
972
+ class UndefinedError < LiquidError
973
+ end
974
+
975
+ class DisabledTagError < LiquidError
976
+ end
977
+
978
+ # The standard _for_ tag.
979
+ class ForTag < Tag
980
+ @expression: LoopExpression
981
+
982
+ @block: Block
983
+
984
+ @default: Block?
985
+
986
+ @blank: bool
987
+
988
+ END_BLOCK: Set[String]
989
+
990
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> ForTag
991
+
992
+ # @param expression [LoopExpression]
993
+ # @param block [Block]
994
+ # @param default [Block?]
995
+ def initialize: ([Symbol, String?, Integer] token, LoopExpression expression, Block block, Block? default) -> void
996
+
997
+ def render: (RenderContext context, String buffer) -> void
998
+ end
999
+
1000
+ # The standard _break_ tag.
1001
+ class BreakTag < Tag
1002
+ def self.parse: ([Symbol, String?, Integer] token, Parser _parser) -> BreakTag
1003
+
1004
+ def render: (RenderContext context, String _buffer) -> void
1005
+ end
1006
+
1007
+ # The standard _continue_ tag.
1008
+ class ContinueTag < Tag
1009
+ def self.parse: ([Symbol, String?, Integer] token, Parser _parser) -> ContinueTag
1010
+
1011
+ def render: (RenderContext context, String _buffer) -> void
1012
+ end
1013
+
1014
+ # `for` loop helper variables.
1015
+ class ForLoop
1016
+ @name: String
1017
+
1018
+ @length: Integer
1019
+
1020
+ @parentloop: (ForLoop | Undefined)
1021
+
1022
+ @index: Integer
1023
+
1024
+ attr_reader name: String
1025
+
1026
+ attr_reader length: Integer
1027
+
1028
+ attr_reader parentloop: (ForLoop | Undefined)
1029
+
1030
+ KEYS: Set[String]
1031
+
1032
+ def initialize: (String name, Integer length, (ForLoop | Undefined) parent_loop) -> void
1033
+
1034
+ def key?: (String key) -> bool
1035
+
1036
+ def []: (String key) -> untyped
1037
+
1038
+ def fetch: (String key, ?::Symbol default) -> untyped
1039
+
1040
+ def next: () -> void
1041
+
1042
+ def index: () -> Integer
1043
+
1044
+ def index0: () -> Integer
1045
+
1046
+ def rindex: () -> Integer
1047
+
1048
+ def rindex0: () -> Integer
1049
+
1050
+ def first: () -> bool
1051
+
1052
+ def last: () -> bool
1053
+ end
1054
+
1055
+ interface _Namespace
1056
+ def key?: (String) -> bool
1057
+ def fetch: (String, ?::Symbol default) -> untyped
1058
+ def []: (String) -> untyped
1059
+ end
1060
+
1061
+ # Combine multiple hashes for sequential lookup.
1062
+ class ReadOnlyChainHash
1063
+ @hashes: Array[_Namespace]
1064
+
1065
+ # @param hashes
1066
+ def initialize: (*_Namespace hashes) -> void
1067
+
1068
+ def []: (String key) -> untyped
1069
+
1070
+ def size: () -> Integer
1071
+
1072
+ def key?: (String key) -> bool
1073
+
1074
+ def fetch: (String key, ?::Symbol default) -> untyped
1075
+
1076
+ def push: (_Namespace hash) -> untyped
1077
+
1078
+ alias << push
1079
+
1080
+ def pop: () -> (_Namespace | nil)
1081
+ end
1082
+ end
1083
+
1084
+ module Liquid2
1085
+ # Base class for all expressions.
1086
+ class Expression
1087
+ @token: [Symbol, String?, Integer]
1088
+
1089
+ attr_reader token: [Symbol, String?, Integer]
1090
+
1091
+ # @param token [[Symbol, String?, Integer]]
1092
+ def initialize: ([Symbol, String?, Integer] token) -> void
1093
+
1094
+ def children: () -> Array[untyped]
1095
+
1096
+ def scope: () -> Array[Identifier]?
1097
+ end
1098
+ end
1099
+
1100
+ module Liquid2
1101
+ class KeywordArgument < Expression
1102
+ @name: String
1103
+
1104
+ @sym: Symbol
1105
+
1106
+ @value: untyped
1107
+
1108
+ attr_reader name: String
1109
+
1110
+ attr_reader sym: Symbol
1111
+
1112
+ attr_reader value: untyped
1113
+
1114
+ # @param name [Token]
1115
+ # @param value [Expression]
1116
+ def initialize: ([Symbol, String?, Integer] token, String name, untyped value) -> void
1117
+
1118
+ def evaluate: (RenderContext context) -> [String, untyped]
1119
+ end
1120
+ end
1121
+
1122
+ module Liquid2
1123
+ # An array literal.
1124
+ class ArrayLiteral < Expression
1125
+ @items: Array[untyped]
1126
+
1127
+ # @param items [Array<Expression>]
1128
+ def initialize: ([Symbol, String?, Integer] token, Array[untyped] items) -> void
1129
+
1130
+ def evaluate: (RenderContext context) -> untyped
1131
+ end
1132
+ end
1133
+
1134
+ module Liquid2
1135
+ class Blank < Expression
1136
+ # @param token [Token]
1137
+ def initialize: ([Symbol, String?, Integer] token) -> void
1138
+
1139
+ def evaluate: (RenderContext _context) -> self
1140
+
1141
+ def ==: (untyped other) -> bool
1142
+
1143
+ alias eql? ==
1144
+ end
1145
+
1146
+ class Empty < Expression
1147
+ # @param token [Token]
1148
+ def initialize: ([Symbol, String?, Integer] token) -> void
1149
+
1150
+ def evaluate: (RenderContext _context) -> self
1151
+
1152
+ def ==: (untyped other) -> bool
1153
+
1154
+ alias eql? ==
1155
+ end
1156
+ end
1157
+
1158
+ module Liquid2
1159
+ class BooleanExpression < Expression
1160
+ @expr: untyped
1161
+
1162
+ # @param expr [Expression]
1163
+ def initialize: ([Symbol, String?, Integer] token, untyped expr) -> void
1164
+
1165
+ def evaluate: (RenderContext context) -> untyped
1166
+ end
1167
+ end
1168
+
1169
+ module Liquid2
1170
+ class FilteredExpression < Expression
1171
+ @left: Expression
1172
+
1173
+ @filters: Array[Filter]
1174
+
1175
+ attr_reader filters: Array[Filter]
1176
+
1177
+ def initialize: ([Symbol, String?, Integer] token, untyped left, Array[Filter] filters) -> void
1178
+
1179
+ def evaluate: (RenderContext context) -> untyped
1180
+ end
1181
+
1182
+ class TernaryExpression < Expression
1183
+ @left: FilteredExpression
1184
+
1185
+ @condition: BooleanExpression
1186
+
1187
+ @alternative: untyped?
1188
+
1189
+ @filters: Array[Filter]
1190
+
1191
+ @tail_filters: Array[Filter]
1192
+
1193
+ attr_reader filters: Array[Filter]
1194
+
1195
+ attr_reader tail_filters: Array[Filter]
1196
+
1197
+ # @param left [FilteredExpression]
1198
+ # @param condition [BooleanExpression]
1199
+ # @param alternative [Expression | nil]
1200
+ # @param filters [Array<Filter>]
1201
+ # @param tail_filters [Array<Filter>]
1202
+ def initialize: ([Symbol, String?, Integer] token, FilteredExpression left, BooleanExpression condition, untyped? alternative, Array[Filter] filters, Array[Filter] tail_filters) -> void
1203
+
1204
+ def evaluate: (RenderContext context) -> untyped
1205
+ end
1206
+
1207
+ class Filter < Expression
1208
+ @name: String
1209
+
1210
+ @args: Array[untyped]
1211
+
1212
+ attr_reader name: String
1213
+
1214
+ attr_reader args: Array[untyped]
1215
+
1216
+ # @param name [Token]
1217
+ # @param args [Array[Expression]]
1218
+ def initialize: ([Symbol, String?, Integer] token, String name, Array[untyped] args) -> void
1219
+
1220
+ def evaluate: (untyped left, RenderContext context) -> untyped
1221
+
1222
+ private
1223
+
1224
+ # @param context [RenderContext]
1225
+ # @return [positional arguments, keyword arguments] An array with two elements.
1226
+ # The first is an array of evaluates positional arguments. The second is a hash
1227
+ # of keyword names to evaluated keyword values.
1228
+ def evaluate_args: (RenderContext context) -> [Array[untyped], Hash[Symbol, untyped]]
1229
+ end
1230
+ end
1231
+
1232
+ module Liquid2
1233
+ class Identifier < Expression
1234
+ # TODO: make identifier behave like a string?
1235
+ @name: String
1236
+
1237
+ attr_reader name: String
1238
+
1239
+ # Try to cast _expr_ to an Identifier.
1240
+ # @param expr [Expression]
1241
+ def self.from: (untyped expr, ?trailing_question: bool) -> Identifier
1242
+
1243
+ def initialize: ([Symbol, String?, Integer] name) -> void
1244
+
1245
+ def evaluate: (RenderContext _context) -> untyped
1246
+ end
1247
+ end
1248
+
1249
+ module Liquid2
1250
+ class LogicalNot < Expression
1251
+ @expr: untyped
1252
+
1253
+ # @param expr [Expression]
1254
+ def initialize: ([Symbol, String?, Integer] token, untyped expr) -> void
1255
+
1256
+ def evaluate: (RenderContext context) -> untyped
1257
+ end
1258
+
1259
+ class LogicalAnd < Expression
1260
+ @left: untyped
1261
+
1262
+ @right: untyped
1263
+
1264
+ # @param left [Expression]
1265
+ # @param right [Expression]
1266
+ def initialize: ([Symbol, String?, Integer] token, untyped left, untyped right) -> void
1267
+
1268
+ def evaluate: (RenderContext context) -> untyped
1269
+ end
1270
+
1271
+ class LogicalOr < Expression
1272
+ @left: untyped
1273
+
1274
+ @right: untyped
1275
+
1276
+ # @param left [Expression]
1277
+ # @param right [Expression]
1278
+ def initialize: ([Symbol, String?, Integer] token, untyped left, untyped right) -> void
1279
+
1280
+ def evaluate: (RenderContext context) -> untyped
1281
+ end
1282
+
1283
+ # A logical expression with explicit parentheses.
1284
+ class GroupedExpression < Expression
1285
+ @expr: untyped
1286
+
1287
+ # @param expr [Expression]
1288
+ def initialize: ([Symbol, String?, Integer] token, untyped expr) -> void
1289
+
1290
+ def evaluate: (RenderContext context) -> untyped
1291
+ end
1292
+ end
1293
+
1294
+ module Liquid2
1295
+ class LoopExpression < Expression
1296
+ @identifier: Identifier
1297
+
1298
+ @enum: untyped
1299
+
1300
+ @limit: untyped?
1301
+
1302
+ @offset: untyped?
1303
+
1304
+ @reversed: bool
1305
+
1306
+ @cols: untyped?
1307
+
1308
+ @name: String
1309
+
1310
+ attr_reader identifier: Identifier
1311
+
1312
+ attr_reader enum: untyped
1313
+
1314
+ attr_reader limit: untyped?
1315
+
1316
+ attr_reader offset: untyped?
1317
+
1318
+ attr_reader reversed: bool
1319
+
1320
+ attr_reader cols: untyped?
1321
+
1322
+ attr_reader name: String
1323
+
1324
+ EMPTY_ENUM: untyped
1325
+
1326
+ def initialize: ([Symbol, String?, Integer] token, Identifier identifier, untyped enum, ?limit: untyped?, ?offset: untyped?, ?reversed: bool, ?cols: untyped?) -> void
1327
+
1328
+ def evaluate: (RenderContext context) -> Array[untyped]
1329
+
1330
+ def lazy_slice: (Enumerator[untyped] enum, Integer start_index, ?Integer? stop_index) -> Enumerable[untyped]
1331
+ end
1332
+ end
1333
+
1334
+ module Liquid2
1335
+ # A path to some variable data.
1336
+ # If the path has just one segment, it is often just called a "variable".
1337
+ class Path < Expression
1338
+ @segments: Array[String | Integer | Path]
1339
+ @head: (String | Integer | Path)
1340
+
1341
+ attr_reader segments: Array[String | Integer | Path]
1342
+ attr_reader head: (String | Integer | Path)
1343
+
1344
+ # @param segments [Array[String | Integer | Path]]
1345
+ def initialize: ([Symbol, String?, Integer] token, Array[String | Integer | Path] segments) -> void
1346
+
1347
+ def evaluate: (RenderContext context) -> untyped
1348
+ end
1349
+ end
1350
+
1351
+ module Liquid2
1352
+ # A range expression.
1353
+ class RangeExpression < Expression
1354
+ @start: untyped
1355
+
1356
+ @stop: untyped
1357
+
1358
+ # @param start [Expression]
1359
+ # @param stop [Expression]
1360
+ def initialize: ([Symbol, String?, Integer] token, untyped start, untyped stop) -> void
1361
+
1362
+ def evaluate: (RenderContext context) -> ::Range[Integer]
1363
+
1364
+ def to_s: () -> ::String
1365
+ end
1366
+ end
1367
+
1368
+ module Liquid2
1369
+ # Base class for all comparison expressions.
1370
+ class ComparisonExpression < Expression
1371
+ @left: untyped
1372
+
1373
+ @right: untyped
1374
+
1375
+ # @param left [Expression]
1376
+ # @param right [Expression]
1377
+ def initialize: ([Symbol, String?, Integer] token, untyped left, untyped right) -> void
1378
+
1379
+ def inner_evaluate: (RenderContext context) -> [untyped, untyped]
1380
+ end
1381
+
1382
+ class Eq < ComparisonExpression
1383
+ def evaluate: (RenderContext context) -> untyped
1384
+ end
1385
+
1386
+ class Ne < ComparisonExpression
1387
+ def evaluate: (RenderContext context) -> untyped
1388
+ end
1389
+
1390
+ class Le < ComparisonExpression
1391
+ def evaluate: (RenderContext context) -> untyped
1392
+ end
1393
+
1394
+ class Ge < ComparisonExpression
1395
+ def evaluate: (RenderContext context) -> untyped
1396
+ end
1397
+
1398
+ class Lt < ComparisonExpression
1399
+ def evaluate: (RenderContext context) -> untyped
1400
+ end
1401
+
1402
+ class Gt < ComparisonExpression
1403
+ def evaluate: (RenderContext context) -> untyped
1404
+ end
1405
+
1406
+ class Contains < ComparisonExpression
1407
+ def evaluate: (RenderContext context) -> untyped
1408
+ end
1409
+
1410
+ class In < ComparisonExpression
1411
+ def evaluate: (RenderContext context) -> untyped
1412
+ end
1413
+
1414
+ # Test _left_ and _right_ for Liquid equality.
1415
+ def self.eq?: (untyped left, untyped right) -> bool
1416
+
1417
+ # Return `true` if _left_ is considered less than _right_.
1418
+ def self.lt?: (untyped left, untyped right) -> bool
1419
+
1420
+ def self.contains?: (untyped left, untyped right) -> bool
1421
+ end
1422
+
1423
+ module Liquid2
1424
+ # The standard _assign_ tag.
1425
+ class AssignTag < Tag
1426
+ @name: Identifier
1427
+
1428
+ @expression: untyped
1429
+
1430
+ # @param parser [Parser]
1431
+ # @return [AssignTag]
1432
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> AssignTag
1433
+
1434
+ # @param name [Identifier]
1435
+ # @param expression [Expression]
1436
+ def initialize: ([Symbol, String?, Integer] token, Identifier name, untyped expression) -> void
1437
+
1438
+ def render: (RenderContext context, String _buffer) -> void
1439
+ end
1440
+ end
1441
+
1442
+ module Liquid2
1443
+ # The AST node representing output statements.
1444
+ class Output < Node
1445
+ @expression: (FilteredExpression | TernaryExpression)
1446
+
1447
+ @blank: bool
1448
+
1449
+ attr_reader expression: (FilteredExpression | TernaryExpression)
1450
+
1451
+ # @param expression [FilteredExpression]
1452
+ def initialize: ([Symbol, String?, Integer] token, (FilteredExpression | TernaryExpression) expression) -> void
1453
+
1454
+ def render: (RenderContext context, String buffer) -> void
1455
+ end
1456
+
1457
+ # `{# comment #}` style comments.
1458
+ class Comment < Node
1459
+ @text: String
1460
+
1461
+ attr_reader text: String
1462
+
1463
+ # @param text [String]
1464
+ def initialize: ([Symbol, String?, Integer] token, String text) -> void
1465
+
1466
+ def render: (RenderContext _context, String _buffer) -> void
1467
+ end
1468
+ end
1469
+
1470
+ module Liquid2
1471
+ # A StringIO subclass that raises an exception when the buffer reaches a limit.
1472
+ class LimitedStringIO < StringIO
1473
+ @limit: Integer
1474
+
1475
+ def initialize: (Integer limit, ?::String string) ?{ (?) -> untyped } -> void
1476
+
1477
+ def write: (*untyped) ?{ (?) -> untyped } -> Integer
1478
+ end
1479
+
1480
+ # A StringIO subclass with a _write_ method that is a no op.
1481
+ class NullIO < StringIO
1482
+ def write: (*untyped) ?{ (?) -> untyped } -> 0
1483
+ end
1484
+ end
1485
+
1486
+ module Liquid2
1487
+ # The standard _if_ tag
1488
+ class IfTag < Tag
1489
+ @expression: untyped
1490
+
1491
+ @block: Block
1492
+
1493
+ @alternatives: Array[ConditionalBlock]
1494
+
1495
+ @default: Block?
1496
+
1497
+ END_TAG: String
1498
+
1499
+ END_BLOCK: Set[String]
1500
+
1501
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> IfTag
1502
+
1503
+ # @return [ConditionalBlock]
1504
+ def self.parse_elsif: (Parser parser) -> ConditionalBlock
1505
+
1506
+ # @param expression [Expression]
1507
+ # @param block [Block]
1508
+ # @param alternatives [Array<[ConditionalBlock]>]
1509
+ # @param default [Block?]
1510
+ def initialize: ([Symbol, String?, Integer] token, untyped expression, Block block, Array[ConditionalBlock] alternatives, Block? default) -> void
1511
+
1512
+ def render: (RenderContext context, String buffer) -> void
1513
+ end
1514
+
1515
+ # The standard _unless_ tag
1516
+ class UnlessTag < IfTag
1517
+ END_TAG: String
1518
+
1519
+ END_BLOCK: Set[String]
1520
+ end
1521
+ end
1522
+
1523
+ module Liquid2
1524
+ # Replace escape sequences with their equivalent Unicode code point.
1525
+ # @param value [String]
1526
+ # @param quote [String] one of '"' or "'".
1527
+ # @param token [Node | Token]
1528
+ # @return [String] A new string without escape sequences.
1529
+ def self.unescape_string: (String value, String quote, [Symbol, String?, Integer] token) -> String
1530
+
1531
+ def self.decode_hex_char: (String value, Integer index, [Symbol, String?, Integer] token) -> [Integer, Integer]
1532
+
1533
+ def self.parse_hex_digits: (String digits, [Symbol, String?, Integer] token) -> Integer
1534
+
1535
+ def self.high_surrogate?: (Integer code_point) -> bool
1536
+
1537
+ def self.low_surrogate?: (Integer code_point) -> bool
1538
+
1539
+ def self.code_point_to_string: (Integer code_point, [Symbol, String?, Integer] token) -> String
1540
+ end
1541
+
1542
+ module Liquid2
1543
+ module Filters
1544
+ # Cast _obj_ to an enumerable for use in a Liquid filter.
1545
+ # @param obj [Object]
1546
+ # @return [Enumerable]
1547
+ def self.to_enumerable: (untyped obj) -> Enumerable[untyped]
1548
+
1549
+ # Cast _obj_ to a number.
1550
+ def self.to_number: (untyped obj, ?default: ::Integer) -> (Integer | Float | Numeric | BigDecimal)
1551
+
1552
+ # Case _obj_ to an Integer.
1553
+ def self.to_integer: (untyped obj) -> Integer
1554
+
1555
+ # Cast _obj_ to a number, favouring BigDecimal over Float.
1556
+ def self.to_decimal: (untyped obj, ?default: ::Integer) -> (Integer | BigDecimal | Numeric)
1557
+
1558
+ # Cast _obj_ to a date and time. Return `nil` if casting fails.
1559
+ def self.to_date: (untyped obj) -> untyped
1560
+
1561
+ def self.fetch: (untyped obj, untyped key) -> untyped
1562
+
1563
+ # Return the concatenation of items in _left_ separated by _sep_.
1564
+ def self.join: (untyped left, ?::String sep) -> untyped
1565
+
1566
+ # Return the absolute value of _left_.
1567
+ def self.abs: (untyped left) -> (Integer | Float | Numeric | BigDecimal)
1568
+
1569
+ # Return the maximum of _left_ and _right_.
1570
+ def self.at_least: (untyped left, untyped right) -> (Integer | Float | Numeric | BigDecimal)
1571
+
1572
+ # Return the minimum of _left_ and _right_.
1573
+ def self.at_most: (untyped left, untyped right) -> (Integer | Float | Numeric | BigDecimal)
1574
+
1575
+ # Return _left_ concatenated with _right_.
1576
+ # Coerce _left_ and _right_ to strings if they aren't strings already.
1577
+ def self.append: (untyped left, untyped right) -> String
1578
+
1579
+ # Return _left_ with the first character in uppercase and the rest lowercase.
1580
+ # Coerce _left_ to a string if it is not one already.
1581
+ def self.capitalize: (untyped left) -> String
1582
+
1583
+ # Return _left_ rounded up to the next whole number.
1584
+ def self.ceil: (untyped left) -> Integer
1585
+
1586
+ def self.compact: (untyped left, untyped key, context: RenderContext) -> Array[untyped]
1587
+
1588
+ # Return _left_ concatenated with _right_, or nil if _right_ is not an array.
1589
+ # Coerce _left_ to an arrays if it isn't an array already..
1590
+ def self.concat: (untyped left, untyped right) -> Array[untyped]
1591
+
1592
+ # Format date and time object _left_ with _format_.
1593
+ # Coerce _left_ to a `Time` if it is not a time-like object already.
1594
+ # Coerce _format_ to a string if it is not a string already.
1595
+ def self.date: (untyped left, untyped format) -> (Time | nil)
1596
+
1597
+ # Return _left_, or _default_ if _obj_ is `nil`, `false` or empty.
1598
+ # If _allow_false_ is `true`, _left_ is returned if _left_ is `false`.
1599
+ def self.default: (untyped left, ?untyped default, context: RenderContext, ?allow_false: bool) -> untyped
1600
+
1601
+ # Return the result of dividing _left_ by _right_.
1602
+ # If both _left_ and _right_ are integers, integer division is performed.
1603
+ def self.divided_by: (untyped left, untyped right) -> (Integer | Float | Numeric | BigDecimal)
1604
+
1605
+ # Return _left_ with all characters converted to lowercase.
1606
+ # Coerce _left_ to a string if it is not one already.
1607
+ def self.downcase: (untyped left) -> String
1608
+
1609
+ # Return _left_ with special HTML characters replaced with their HTML-safe escape sequences.
1610
+ # Coerce _left_ to a string if it is not one already.
1611
+ def self.escape: (untyped left) -> (String | nil)
1612
+
1613
+ # Return _left_ with special HTML characters replaced with their HTML-safe escape sequences.
1614
+ # Coerce _left_ to a string if it is not one already.
1615
+ #
1616
+ # It is safe to use `escape_once` on string values that already contain HTML-escape sequences.
1617
+ def self.escape_once: (untyped left) -> String
1618
+
1619
+
1620
+ def self.find: (untyped left, untyped key, ?untyped? value, context: Liquid2::RenderContext) -> untyped
1621
+
1622
+ def self.find_index: (untyped left, untyped key, ?untyped? value, context: Liquid2::RenderContext) -> Integer?
1623
+
1624
+ def self.has: (untyped left, untyped key, ?untyped? value, context: Liquid2::RenderContext) -> bool
1625
+
1626
+ # Return the first item in _left_, or `nil` if _left_ does not have a first item.
1627
+ def self.first: (untyped left) -> untyped
1628
+
1629
+ # Return _left_ rounded down to the next whole number.
1630
+ def self.floor: (untyped left) -> Integer
1631
+
1632
+ # Return the last item in _left_, or `nil` if _left_ does not have a last item.
1633
+ def self.last: (untyped left) -> untyped
1634
+
1635
+ # Return _left_ with leading whitespace removed.
1636
+ # Coerce _left_ to a string if it is not one already.
1637
+ def self.lstrip: (untyped left) -> String
1638
+
1639
+ # Return _left_ with trailing whitespace removed.
1640
+ # Coerce _left_ to a string if it is not one already.
1641
+ def self.rstrip: (untyped left) -> String
1642
+
1643
+ # Return _left_ with leading and trailing whitespace removed.
1644
+ # Coerce _left_ to a string if it is not one already.
1645
+ def self.strip: (untyped left) -> String
1646
+
1647
+ def self.map: (untyped left, untyped key, context: RenderContext) -> Array[untyped]
1648
+
1649
+ # Return _right_ subtracted from _left_.
1650
+ def self.minus: (untyped left, untyped right) -> (Integer | Float | Numeric | BigDecimal)
1651
+
1652
+ # Return the remainder of dividing _left_ by _right_.
1653
+ def self.modulo: (untyped left, untyped right) -> (Integer | Float | Numeric | BigDecimal)
1654
+
1655
+ # Return _left_ with LF or CRLF replaced with `<br />\n`.
1656
+ def self.newline_to_br: (untyped left) -> String
1657
+
1658
+ # Return _right_ added to _left_.
1659
+ def self.plus: (untyped left, untyped right) -> (Integer | Float | Numeric | BigDecimal)
1660
+
1661
+ # Return _right_ concatenated with _left_.
1662
+ # Coerce _left_ and _right_ to strings if they aren't strings already.
1663
+ def self.prepend: (untyped left, untyped right) -> String
1664
+
1665
+ def self.reject: (untyped left, untyped key, ?untyped? value, context: Liquid2::RenderContext) -> Array[untyped]
1666
+
1667
+ def self.where: (untyped left, untyped key, ?untyped? value, context: Liquid2::RenderContext) -> Array[untyped]
1668
+
1669
+ # Return _left_ with all occurrences of _pattern_ replaced with _replacement_.
1670
+ # All arguments are coerced to strings if they aren't strings already.
1671
+ def self.replace: (untyped left, untyped pattern, ?untyped replacement) -> String
1672
+
1673
+ # Return _left_ with the first occurrence of _pattern_ replaced with _replacement_.
1674
+ # All arguments are coerced to strings if they aren't strings already.
1675
+ def self.replace_first: (untyped left, untyped pattern, ?untyped replacement) -> String
1676
+
1677
+ # Return _left_ with the last occurrence of _pattern_ replaced with _replacement_.
1678
+ # All arguments are coerced to strings if they aren't strings already.
1679
+ def self.replace_last: (untyped left, untyped pattern, untyped replacement) -> String
1680
+
1681
+ # Return _left_ with all occurrences of _pattern_ removed.
1682
+ # All arguments are coerced to strings if they aren't strings already.
1683
+ def self.remove: (untyped left, untyped pattern) -> String
1684
+
1685
+ # Return _left_ with the first occurrence of _pattern_ removed.
1686
+ # All arguments are coerced to strings if they aren't strings already.
1687
+ def self.remove_first: (untyped left, untyped pattern) -> String
1688
+
1689
+ # Return _left_ with the last occurrence of _pattern_ removed.
1690
+ # All arguments are coerced to strings if they aren't strings already.
1691
+ def self.remove_last: (untyped left, untyped pattern) -> String
1692
+
1693
+ # Return _left_ with all items in reverse order.
1694
+ # Coerce _left_ to an array if it isn't an array already.
1695
+ def self.reverse: (untyped left) -> Array[untyped]
1696
+
1697
+ # Return _left_ rounded to _ndigits_ decimal digits.
1698
+ def self.round: (untyped left, ?::Integer ndigits) -> untyped
1699
+
1700
+ # Return the size of _left_, or zero if _left_ has no size.
1701
+ def self.size: (untyped left) -> Integer
1702
+
1703
+ # Return the subsequence of _left_ starting at _start_ up to _length_.
1704
+ def self.slice: (untyped left, untyped start, ?untyped length) -> untyped
1705
+
1706
+ # Return _left_ with all characters converted to uppercase.
1707
+ # Coerce _left_ to a string if it is not one already.
1708
+ def self.upcase: (untyped left) -> String
1709
+
1710
+ def self.sort: (untyped left, ?untyped? key, context: RenderContext) -> Array[untyped]
1711
+
1712
+ def self.sort_natural: (untyped left, ?untyped? key, context: RenderContext) -> Array[untyped]
1713
+
1714
+ def self.sort_numeric: (untyped left, ?untyped? key, context: RenderContext) -> Array[untyped]
1715
+
1716
+ def self.nil_safe_compare: (untyped a, untyped b) -> (0 | 1 | -1)
1717
+
1718
+ def self.nil_safe_casecmp: (untyped a, untyped b) -> (0 | 1 | -1)
1719
+
1720
+ def self.numeric_compare: (untyped left, untyped right) -> (0 | 1 | -1)
1721
+
1722
+ def self.ints: (untyped obj) -> Array[(Integer | Float | BigDecimal)]
1723
+
1724
+ # Split _left_ on every occurrence of _pattern_.
1725
+ def self.split: (untyped left, untyped pattern) -> Array[String]
1726
+
1727
+ # Deduplicate items in _left_.
1728
+ # Coerce _left_ to an array if it isn't an array already.
1729
+ def self.uniq: (untyped left, ?untyped? key, context: RenderContext) -> Array[untyped]
1730
+
1731
+ RE_HTML_BLOCKS: ::Regexp
1732
+
1733
+ RE_HTML_TAGS: ::Regexp
1734
+
1735
+ # Return _left_ with HTML tags removed.
1736
+ def self.strip_html: (untyped left) -> String?
1737
+
1738
+ # Return _left_ with CR and LF removed.
1739
+ def self.strip_newlines: (untyped left) -> String
1740
+
1741
+ # The _sum_ filter.
1742
+ def self.sum: (untyped left, ?untyped? key, context: Liquid2::RenderContext) -> Integer
1743
+
1744
+ # Return the result of multiplying _left_ by _right_.
1745
+ def self.times: (untyped left, untyped right) -> (Integer | Float | Numeric | BigDecimal)
1746
+
1747
+ def self.truncate: (untyped left, ?untyped max_length, ?untyped ellipsis) -> String?
1748
+
1749
+ def self.truncatewords: (untyped left, ?untyped max_words, ?untyped ellipsis) -> String?
1750
+
1751
+ def self.url_encode: (untyped left) -> String?
1752
+
1753
+ def self.url_decode: (untyped left) -> String?
1754
+
1755
+ def self.base64_encode: (untyped left) -> String
1756
+
1757
+ def self.base64_decode: (untyped left) -> String?
1758
+
1759
+ def self.base64_url_safe_encode: (untyped left) -> String
1760
+
1761
+ def self.base64_url_safe_decode: (untyped left) -> String?
1762
+ end
1763
+ end
1764
+
1765
+ module Liquid2
1766
+ # The standard _liquid_ tag.
1767
+ class LiquidTag < Tag
1768
+ @block: Block
1769
+
1770
+ @blank: bool
1771
+
1772
+ # @param parser [Parser]
1773
+ # @return [LiquidTag]
1774
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> LiquidTag
1775
+
1776
+ def initialize: ([Symbol, String?, Integer] token, Block block) -> void
1777
+
1778
+ def render: (RenderContext context, String buffer) -> void
1779
+ end
1780
+ end
1781
+
1782
+ module Liquid2
1783
+ # The standard _echo_ tag.
1784
+ class EchoTag < Tag
1785
+ @expression: Expression?
1786
+
1787
+ @blank: bool
1788
+
1789
+ # @param parser [Parser]
1790
+ # @return [EchoTag]
1791
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> EchoTag
1792
+
1793
+ def initialize: ([Symbol, String?, Integer] token, Expression? expression) -> void
1794
+
1795
+ def render: (RenderContext context, String buffer) -> void
1796
+ end
1797
+ end
1798
+
1799
+ module Liquid2
1800
+ # `{% # comment %}` style comments.
1801
+ class InlineComment < Tag
1802
+ @text: String
1803
+
1804
+ attr_reader text: String
1805
+
1806
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> InlineComment
1807
+
1808
+ # @param text [String]
1809
+ def initialize: ([Symbol, String?, Integer] token, String text) -> void
1810
+
1811
+ def render: (RenderContext _context, String _buffer) -> void
1812
+ end
1813
+ end
1814
+
1815
+ module Liquid2
1816
+ # The standard _raw_ tag.
1817
+ class RawTag < Tag
1818
+ @text: String
1819
+
1820
+ @blank: bool
1821
+
1822
+ # @param parser [Parser]
1823
+ # @return [RawTag]
1824
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> RawTag
1825
+
1826
+ # @param text [String]
1827
+ def initialize: ([Symbol, String?, Integer] token, String text) -> void
1828
+
1829
+ def render: (RenderContext _context, String buffer) -> void
1830
+ end
1831
+ end
1832
+
1833
+ module Liquid2
1834
+ # The standard _comment_ tag.
1835
+ class BlockComment < Tag
1836
+ @text: String
1837
+
1838
+ attr_reader text: String
1839
+
1840
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> BlockComment
1841
+
1842
+ # @param text [String]
1843
+ def initialize: ([Symbol, String?, Integer] token, String text) -> void
1844
+
1845
+ def render: (RenderContext _context, String _buffer) -> void
1846
+ end
1847
+ end
1848
+
1849
+ module Liquid2
1850
+ # The standard _capture_ tag.
1851
+ class CaptureTag < Tag
1852
+ @name: Identifier
1853
+
1854
+ @block: Block
1855
+
1856
+ END_BLOCK: Set[String]
1857
+
1858
+ # @param parser [Parser]
1859
+ # @return [CaptureTag]
1860
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> CaptureTag
1861
+
1862
+ # @param name [Identifier]
1863
+ # @param block [Block]
1864
+ def initialize: ([Symbol, String?, Integer] token, Identifier name, Block block) -> void
1865
+
1866
+ def render: (RenderContext context, String buffer) -> void
1867
+ end
1868
+ end
1869
+
1870
+ module Liquid2
1871
+ # The standard _case_ tag.
1872
+ class CaseTag < Tag
1873
+ @expression: untyped
1874
+
1875
+ @whens: Array[MultiEqualBlock]
1876
+
1877
+ @default: Block?
1878
+
1879
+ @blank: bool
1880
+
1881
+ END_BLOCK: Set[String]
1882
+
1883
+ WHEN_DELIM: Set[Symbol]
1884
+
1885
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> CaseTag
1886
+
1887
+ # @return [MultiEqualBlock]
1888
+ def self.parse_when: (Parser parser, untyped expr) -> MultiEqualBlock
1889
+
1890
+ def initialize: ([Symbol, String?, Integer] token, untyped expression, Array[MultiEqualBlock] whens, Block? default) -> void
1891
+
1892
+ def render: (RenderContext context, String buffer) -> void
1893
+ end
1894
+
1895
+ # A Liquid block guarded by any one of multiple expressions.
1896
+ class MultiEqualBlock < Node
1897
+ @left: untyped
1898
+
1899
+ @conditions: Array[untyped]
1900
+
1901
+ @block: Block
1902
+
1903
+ @blank: bool
1904
+
1905
+ # @param left [Expression]
1906
+ # @param conditions [Array<Expression>]
1907
+ # @param block [Block]
1908
+ def initialize: ([Symbol, String?, Integer] token, untyped left, Array[untyped] conditions, Block block) -> void
1909
+
1910
+ def render: (RenderContext context, String buffer) -> bool
1911
+ end
1912
+ end
1913
+
1914
+ module Liquid2
1915
+ # The standard _cycle_ tag.
1916
+ class CycleTag < Tag
1917
+ @name: untyped
1918
+
1919
+ @items: Array[untyped]
1920
+
1921
+ @named: bool
1922
+
1923
+ @blank: bool
1924
+
1925
+ # @param parser [Parser]
1926
+ # @return [CycleTag]
1927
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> CycleTag
1928
+
1929
+ # @param name [Expression?]
1930
+ # @param items [Array<Expression>]
1931
+ def initialize: ([Symbol, String?, Integer] token, untyped name, Array[untyped] items, bool named) -> void
1932
+
1933
+ def render: (RenderContext context, String buffer) -> void
1934
+ end
1935
+ end
1936
+
1937
+ module Liquid2
1938
+ # The standard _decrement_ tag.
1939
+ class DecrementTag < Tag
1940
+ @name: Identifier
1941
+
1942
+ # @param parser [Parser]
1943
+ # @return [DecrementTag]
1944
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> DecrementTag
1945
+
1946
+ # @param name [Identifier]
1947
+ def initialize: ([Symbol, String?, Integer] token, Identifier name) -> void
1948
+
1949
+ def render: (RenderContext context, String buffer) -> void
1950
+ end
1951
+ end
1952
+
1953
+
1954
+ module Liquid2
1955
+ # The standard _doc_ tag.
1956
+ class DocTag < Tag
1957
+ @text: String
1958
+
1959
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> DocTag
1960
+
1961
+ # @param text [String]
1962
+ def initialize: ([Symbol, String?, Integer] token, String text) -> void
1963
+
1964
+ def render: (RenderContext _context, String _buffer) -> void
1965
+ end
1966
+ end
1967
+
1968
+ module Liquid2
1969
+ # The standard _increment_ tag.
1970
+ class IncrementTag < Tag
1971
+ @name: Identifier
1972
+
1973
+ # @param parser [Parser]
1974
+ # @return [IncrementTag]
1975
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> IncrementTag
1976
+
1977
+ # @param name [Identifier]
1978
+ def initialize: ([Symbol, String?, Integer] token, Identifier name) -> void
1979
+
1980
+ def render: (RenderContext context, String buffer) -> void
1981
+ end
1982
+ end
1983
+
1984
+ module Liquid2
1985
+ # The standard _include_ tag.
1986
+ class IncludeTag < Tag
1987
+ @name: untyped
1988
+
1989
+ @repeat: bool
1990
+
1991
+ @var: untyped?
1992
+
1993
+ @as: Identifier?
1994
+
1995
+ @args: Array[KeywordArgument]
1996
+
1997
+ # @param parser [Parser]
1998
+ # @return [IncludeTag]
1999
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> IncludeTag
2000
+
2001
+ # @param name [Expression]
2002
+ # @param repeat [bool]
2003
+ # @param var [Expression?]
2004
+ # @param as [Identifier?]
2005
+ # @param args [Array<KeywordArgument> | nil]
2006
+ def initialize: ([Symbol, String?, Integer] token, untyped name, bool repeat, untyped var, Identifier? as, Array[KeywordArgument] args) -> void
2007
+
2008
+ def render: (RenderContext context, String buffer) -> void
2009
+ end
2010
+ end
2011
+
2012
+ module Liquid2
2013
+ DISABLED_TAGS: Set[String]
2014
+
2015
+ # The standard _render_ tag.
2016
+ class RenderTag < Tag
2017
+ @name: untyped
2018
+
2019
+ @repeat: bool
2020
+
2021
+ @var: untyped?
2022
+
2023
+ @as: String?
2024
+
2025
+ @args: Array[KeywordArgument]
2026
+
2027
+ # @param parser [Parser]
2028
+ # @return [RenderTag]
2029
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> RenderTag
2030
+
2031
+ # @param name [StringLiteral]
2032
+ # @param repeat [bool]
2033
+ # @param var [Expression?]
2034
+ # @param as [Identifier?]
2035
+ # @param args [Array<KeywordArgument> | nil]
2036
+ def initialize: ([Symbol, String?, Integer] token, untyped name, bool repeat, untyped var, Identifier? as, Array[KeywordArgument] args) -> void
2037
+
2038
+ def render: (RenderContext context, String buffer) -> void
2039
+ end
2040
+ end
2041
+
2042
+ module Liquid2
2043
+ # The standard _tablerow_ tag.
2044
+ class TableRowTag < Tag
2045
+ @expression: untyped
2046
+
2047
+ @block: Block
2048
+
2049
+ @blank: bool
2050
+
2051
+ END_BLOCK: Set[String]
2052
+
2053
+ def self.parse: ([Symbol, String?, Integer] token, Parser parser) -> TableRowTag
2054
+
2055
+ def initialize: ([Symbol, String?, Integer] token, untyped expression, Block block) -> void
2056
+
2057
+ def render: (RenderContext context, String buffer) -> void
2058
+
2059
+ def children: (RenderContext _static_context, ?include_partials: bool) -> ::Array[untyped]
2060
+
2061
+ def expressions: () -> ::Array[untyped]
2062
+
2063
+ def block_scope: () -> ::Array[Identifier]
2064
+ end
2065
+
2066
+ # `tablerow` loop helper variables.
2067
+ class TableRow
2068
+ @name: String
2069
+
2070
+ @length: Integer
2071
+
2072
+ @cols: Integer
2073
+
2074
+ @index: Integer
2075
+
2076
+ @row: Integer
2077
+
2078
+ @col: Integer
2079
+
2080
+ attr_reader name: String
2081
+
2082
+ attr_reader length: Integer
2083
+
2084
+ attr_reader col: Integer
2085
+
2086
+ attr_reader row: Integer
2087
+
2088
+ KEYS: Set[String]
2089
+
2090
+ def initialize: (String name, Integer length, Integer cols) -> void
2091
+
2092
+ def key?: (untyped key) -> bool
2093
+
2094
+ def []: (untyped key) -> (untyped | nil)
2095
+
2096
+ def fetch: (untyped key, ?::Symbol default) -> untyped
2097
+
2098
+ def next: () -> void
2099
+
2100
+ def index: () -> Integer
2101
+
2102
+ def index0: () -> Integer
2103
+
2104
+ def rindex: () -> Integer
2105
+
2106
+ def rindex0: () -> Integer
2107
+
2108
+ def first: () -> bool
2109
+
2110
+ def last: () -> bool
2111
+
2112
+ def col0: () -> Integer
2113
+
2114
+ def col_first: () -> bool
2115
+
2116
+ def col_last: () -> bool
2117
+ end
2118
+ end
2119
+
2120
+ module Liquid2
2121
+ # A lambda expression aka arrow function
2122
+ class Lambda < Expression
2123
+ @params: Array[Identifier]
2124
+
2125
+ @expr: untyped
2126
+
2127
+ attr_reader params: Array[Identifier]
2128
+
2129
+ attr_reader expr: untyped
2130
+
2131
+ # @param params [Array<Identifier>]
2132
+ # @param expr [Expression]
2133
+ def initialize: ([Symbol, String?, Integer] token, Array[Identifier] params, untyped expr) -> void
2134
+
2135
+ def evaluate: (RenderContext _context) -> self
2136
+
2137
+ # Apply this lambda function to elements from _enum_.
2138
+ # @param context [RenderContext]
2139
+ # @param enum [Enumerable<Object>]
2140
+ # @return [Enumerable<Object>]
2141
+ def map: (RenderContext context, Enumerable[untyped] enum) -> Enumerable[untyped]
2142
+ end
2143
+ end
2144
+
2145
+ module Liquid2
2146
+ # Quoted string with interpolated expressions.
2147
+ class TemplateString < Expression
2148
+ @segments: Array[untyped]
2149
+
2150
+ # @param segments [Array<Expression>]
2151
+ def initialize: ([Symbol, String?, Integer] token, Array[untyped] segments) -> void
2152
+
2153
+ def evaluate: (RenderContext context) -> String
2154
+ end
2155
+ end
2156
+
2157
+
2158
+ module Liquid2
2159
+ # Template static analysis.
2160
+ module StaticAnalysis
2161
+ # The location of a variable, tag or filter.
2162
+ class Span
2163
+ @template_name: String
2164
+
2165
+ @index: Integer
2166
+
2167
+ attr_reader template_name: String
2168
+
2169
+ attr_reader index: Integer
2170
+
2171
+ def initialize: (String template_name, Integer index) -> void
2172
+
2173
+ # @param source [String] Template source text.
2174
+ # @return [[Integer, Integer]] The line and column number of this span in _source_.
2175
+ def line_col: (String source) -> [Integer, Integer]
2176
+ end
2177
+
2178
+ class Variable
2179
+ @segments: Array[untyped]
2180
+
2181
+ @span: Span
2182
+
2183
+ attr_reader segments: Array[untyped]
2184
+
2185
+ attr_reader span: Span
2186
+
2187
+ RE_PROPERTY: ::Regexp
2188
+
2189
+ def initialize: (Array[untyped] segments, Span span) -> void
2190
+
2191
+ def to_s: () -> String
2192
+
2193
+ def ==: (untyped other) -> bool
2194
+
2195
+ alias eql? ==
2196
+
2197
+ def hash: () -> untyped
2198
+
2199
+ def segments_to_s: (Array[untyped] segments) -> String
2200
+ end
2201
+
2202
+ class StaticScope
2203
+ @stack: Array[Set[String]]
2204
+
2205
+ def initialize: (Set[String] globals) -> void
2206
+
2207
+ def include?: (String key) -> untyped
2208
+
2209
+ def push: (Set[String] scope) -> self
2210
+
2211
+ def pop: () -> Set[String]?
2212
+
2213
+ def add: (String name) -> void
2214
+ end
2215
+
2216
+ class VariableMap
2217
+ @data: Hash[String, Array[Variable]]
2218
+
2219
+ attr_reader data: Hash[String, Array[Variable]]
2220
+
2221
+ def initialize: () -> void
2222
+
2223
+ def []: (Variable var) -> Array[Variable]
2224
+
2225
+ def add: (Variable var) -> void
2226
+ end
2227
+
2228
+ class Result
2229
+ @variables: Hash[String, Array[Variable]]
2230
+
2231
+ @globals: Hash[String, Array[Variable]]
2232
+
2233
+ @locals: Hash[String, Array[Variable]]
2234
+
2235
+ @filters: Hash[String, Array[Span]]
2236
+
2237
+ @tags: Hash[String, Array[Span]]
2238
+
2239
+ attr_reader variables: Hash[String, Array[Variable]]
2240
+
2241
+ attr_reader globals: Hash[String, Array[Variable]]
2242
+
2243
+ attr_reader locals: Hash[String, Array[Variable]]
2244
+
2245
+ attr_reader filters: Hash[String, Array[Span]]
2246
+
2247
+ attr_reader tags: Hash[String, Array[Span]]
2248
+
2249
+ def initialize: (Hash[String, Array[Variable]] variables, Hash[String, Array[Variable]] globals, Hash[String, Array[Variable]] locals, Hash[String, Array[Span]] filters, Hash[String, Array[Span]] tags) -> void
2250
+ end
2251
+
2252
+ def self.analyze: (Liquid2::Template template, include_partials: bool) -> Result
2253
+
2254
+ def self.extract_filters: (untyped expression, String template_name) -> Array[[String, Span]]
2255
+
2256
+ def self.analyze_variables: (Expression expression, String template_name, StaticScope scope, VariableMap globals, VariableMap variables) -> void
2257
+
2258
+ def self.segments: (Liquid2::Path path, String template_name) -> Array[untyped]
2259
+ end
2260
+ end
2261
+
2262
+ module Liquid2
2263
+ class FileSystemLoader < TemplateLoader
2264
+ @search_path: Array[Pathname]
2265
+
2266
+ @default_extension: String?
2267
+
2268
+ def initialize: ((String | Array[String]) search_path, ?default_extension: String?) -> void
2269
+
2270
+ def get_source: (Environment _env, String name, ?context: RenderContext?, **untyped _kwargs) -> TemplateSource
2271
+
2272
+ def resolve_path: (String template_name) -> Pathname
2273
+ end
2274
+
2275
+ class CachingFileSystemLoader < FileSystemLoader
2276
+ include CachingLoaderMixin
2277
+
2278
+ def initialize: ((String | Array[String]) search_path, ?default_extension: String?, ?auto_reload: bool, ?namespace_key: ::String, ?capacity: ::Integer, ?thread_safe: bool) -> void
2279
+ end
2280
+ end
2281
+
2282
+ module Liquid2
2283
+ # A least recently used cache relying on Ruby hash insertion order.
2284
+ class LRUCache
2285
+ @data: Hash[untyped, untyped]
2286
+
2287
+ @max_size: Integer
2288
+
2289
+ attr_reader max_size: Integer
2290
+
2291
+ def initialize: (?::Integer max_size) -> void
2292
+
2293
+ # Return the cached value or nil if _key_ does not exist.
2294
+ def []: (untyped key) -> (nil | untyped)
2295
+
2296
+ def []=: (untyped key, untyped value) -> untyped
2297
+
2298
+ def length: () -> Integer
2299
+
2300
+ def keys: () -> Array[untyped]
2301
+ end
2302
+
2303
+ class ThreadSafeLRUCache < LRUCache
2304
+ include MonitorMixin
2305
+
2306
+ alias unsafe_get []
2307
+
2308
+ alias unsafe_set []=
2309
+
2310
+ alias unsafe_length length
2311
+
2312
+ alias unsafe_keys keys
2313
+
2314
+ def initialize: (?::Integer max_size) -> void
2315
+
2316
+ def []: (untyped key) -> untyped
2317
+
2318
+ def []=: (untyped key, untyped value) -> untyped
2319
+
2320
+ def length: () -> Integer
2321
+
2322
+ def keys: () -> Array[untyped]
2323
+ end
2324
+ end
2325
+
2326
+ module Liquid2
2327
+ module CachingLoaderMixin
2328
+ @auto_reload: bool
2329
+
2330
+ @namespace_key: String?
2331
+
2332
+ @cache: Liquid2::LRUCache
2333
+
2334
+ def initialize_cache: (?auto_reload: bool, ?namespace_key: ::String, ?capacity: ::Integer, ?thread_safe: bool) -> untyped
2335
+
2336
+ def load: (Environment env, String name, ?globals: untyped?, ?context: RenderContext?, **untyped kwargs) -> Template
2337
+
2338
+ def cache_key: (String name, ?context: RenderContext?, **untyped kwargs) -> String
2339
+ end
2340
+ end
2341
+
2342
+ module Liquid2
2343
+ # Liquid filters and helper methods.
2344
+ module Filters
2345
+ # Return _left_ serialized in JSON format.
2346
+ def self.json: (untyped left, ?pretty: bool) -> String
2347
+ end
2348
+ end