luoma 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 (152) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +2 -0
  3. data/.rdoc_options +16 -0
  4. data/CHANGELOG.md +5 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +68 -0
  7. data/Rakefile +69 -0
  8. data/Steepfile +41 -0
  9. data/certs/jgrp.pem +27 -0
  10. data/docs/configuration.md +180 -0
  11. data/docs/custom_filters.md +3 -0
  12. data/docs/custom_tags.md +3 -0
  13. data/docs/expressions.md +3 -0
  14. data/docs/extension_types.md +41 -0
  15. data/docs/filter_reference.md +1702 -0
  16. data/docs/index.md +73 -0
  17. data/docs/luoma_for_template_authors.md +3 -0
  18. data/docs/markdown.md +111 -0
  19. data/docs/predicate_reference.md +3 -0
  20. data/docs/static_analysis.md +3 -0
  21. data/docs/tag_reference.md +352 -0
  22. data/docs/template_loaders.md +177 -0
  23. data/docs/undefined_variables.md +3 -0
  24. data/docs-requirements.txt +11 -0
  25. data/docs_/cycle.md +17 -0
  26. data/docs_/font_rendering_example.md +157 -0
  27. data/docs_/header_block_example.md +51 -0
  28. data/docs_/increment_and_decrement.md +49 -0
  29. data/docs_/logo_style_example.md +40 -0
  30. data/docs_/migration.md +11 -0
  31. data/docs_/notes.md +19 -0
  32. data/lib/luoma/cache.rb +80 -0
  33. data/lib/luoma/chain_hash.rb +54 -0
  34. data/lib/luoma/context.rb +227 -0
  35. data/lib/luoma/drop.rb +84 -0
  36. data/lib/luoma/drops/block.rb +33 -0
  37. data/lib/luoma/drops/expression.rb +29 -0
  38. data/lib/luoma/drops/html_safe.rb +36 -0
  39. data/lib/luoma/drops/range.rb +69 -0
  40. data/lib/luoma/drops/undefined.rb +119 -0
  41. data/lib/luoma/environment.rb +479 -0
  42. data/lib/luoma/errors.rb +79 -0
  43. data/lib/luoma/escape.rb +35 -0
  44. data/lib/luoma/expression.rb +1271 -0
  45. data/lib/luoma/filter.rb +97 -0
  46. data/lib/luoma/filters/array.rb +372 -0
  47. data/lib/luoma/filters/date.rb +19 -0
  48. data/lib/luoma/filters/default.rb +16 -0
  49. data/lib/luoma/filters/json.rb +14 -0
  50. data/lib/luoma/filters/math.rb +84 -0
  51. data/lib/luoma/filters/size.rb +13 -0
  52. data/lib/luoma/filters/slice.rb +52 -0
  53. data/lib/luoma/filters/sort.rb +113 -0
  54. data/lib/luoma/filters/string.rb +186 -0
  55. data/lib/luoma/fnv.rb +15 -0
  56. data/lib/luoma/lexer.rb +106 -0
  57. data/lib/luoma/lexer_legacy.rb +396 -0
  58. data/lib/luoma/lexer_unified.rb +279 -0
  59. data/lib/luoma/loader.rb +50 -0
  60. data/lib/luoma/loaders/choice_loader.rb +20 -0
  61. data/lib/luoma/loaders/file_system_loader.rb +75 -0
  62. data/lib/luoma/loaders/mixins.rb +52 -0
  63. data/lib/luoma/markup.rb +109 -0
  64. data/lib/luoma/parser.rb +252 -0
  65. data/lib/luoma/parser_unified.rb +979 -0
  66. data/lib/luoma/predicates/blank.rb +19 -0
  67. data/lib/luoma/predicates/defined.rb +10 -0
  68. data/lib/luoma/predicates/empty.rb +15 -0
  69. data/lib/luoma/predicates/type.rb +35 -0
  70. data/lib/luoma/static_analysis.rb +427 -0
  71. data/lib/luoma/tags/assign.rb +63 -0
  72. data/lib/luoma/tags/break.rb +23 -0
  73. data/lib/luoma/tags/capture.rb +43 -0
  74. data/lib/luoma/tags/case.rb +137 -0
  75. data/lib/luoma/tags/comment.rb +17 -0
  76. data/lib/luoma/tags/continue.rb +23 -0
  77. data/lib/luoma/tags/define.rb +42 -0
  78. data/lib/luoma/tags/else.rb +30 -0
  79. data/lib/luoma/tags/for.rb +108 -0
  80. data/lib/luoma/tags/if.rb +109 -0
  81. data/lib/luoma/tags/import.rb +91 -0
  82. data/lib/luoma/tags/include.rb +77 -0
  83. data/lib/luoma/tags/output.rb +20 -0
  84. data/lib/luoma/tags/raw.rb +26 -0
  85. data/lib/luoma/tags/render.rb +92 -0
  86. data/lib/luoma/tags/with.rb +55 -0
  87. data/lib/luoma/template.rb +178 -0
  88. data/lib/luoma/token.rb +84 -0
  89. data/lib/luoma/version.rb +5 -0
  90. data/lib/luoma.rb +75 -0
  91. data/sig/luoma/cache.rbs +44 -0
  92. data/sig/luoma/chain_hash.rbs +26 -0
  93. data/sig/luoma/context.rbs +115 -0
  94. data/sig/luoma/drop.rbs +44 -0
  95. data/sig/luoma/drops/block.rbs +10 -0
  96. data/sig/luoma/drops/expression.rbs +10 -0
  97. data/sig/luoma/drops/html_safe.rbs +14 -0
  98. data/sig/luoma/drops/range.rbs +15 -0
  99. data/sig/luoma/drops/undefined.rbs +27 -0
  100. data/sig/luoma/environment.rbs +212 -0
  101. data/sig/luoma/errors.rbs +67 -0
  102. data/sig/luoma/escape.rbs +15 -0
  103. data/sig/luoma/expression.rbs +514 -0
  104. data/sig/luoma/filter.rbs +66 -0
  105. data/sig/luoma/filters/array.rbs +74 -0
  106. data/sig/luoma/filters/date.rbs +9 -0
  107. data/sig/luoma/filters/default.rbs +8 -0
  108. data/sig/luoma/filters/json.rbs +7 -0
  109. data/sig/luoma/filters/math.rbs +37 -0
  110. data/sig/luoma/filters/size.rbs +6 -0
  111. data/sig/luoma/filters/slice.rbs +10 -0
  112. data/sig/luoma/filters/sort.rbs +17 -0
  113. data/sig/luoma/filters/string.rbs +103 -0
  114. data/sig/luoma/fnv.rbs +3 -0
  115. data/sig/luoma/lexer.rbs +42 -0
  116. data/sig/luoma/lexer_legacy.rbs +81 -0
  117. data/sig/luoma/lexer_unified.rbs +49 -0
  118. data/sig/luoma/loader.rbs +40 -0
  119. data/sig/luoma/loaders/choice_loader.rbs +9 -0
  120. data/sig/luoma/loaders/file_system_loader.rbs +19 -0
  121. data/sig/luoma/loaders/mixins.rbs +16 -0
  122. data/sig/luoma/markup.rbs +68 -0
  123. data/sig/luoma/parser.rbs +105 -0
  124. data/sig/luoma/parser_unified.rbs +150 -0
  125. data/sig/luoma/predicates/blank.rbs +6 -0
  126. data/sig/luoma/predicates/defined.rbs +6 -0
  127. data/sig/luoma/predicates/empty.rbs +6 -0
  128. data/sig/luoma/predicates/type.rbs +21 -0
  129. data/sig/luoma/static_analysis.rbs +141 -0
  130. data/sig/luoma/tags/assign.rbs +12 -0
  131. data/sig/luoma/tags/break.rbs +11 -0
  132. data/sig/luoma/tags/capture.rbs +14 -0
  133. data/sig/luoma/tags/case.rbs +36 -0
  134. data/sig/luoma/tags/comment.rbs +11 -0
  135. data/sig/luoma/tags/continue.rbs +11 -0
  136. data/sig/luoma/tags/define.rbs +16 -0
  137. data/sig/luoma/tags/else.rbs +17 -0
  138. data/sig/luoma/tags/for.rbs +26 -0
  139. data/sig/luoma/tags/if.rbs +45 -0
  140. data/sig/luoma/tags/import.rbs +13 -0
  141. data/sig/luoma/tags/include.rbs +13 -0
  142. data/sig/luoma/tags/output.rbs +13 -0
  143. data/sig/luoma/tags/raw.rbs +11 -0
  144. data/sig/luoma/tags/render.rbs +13 -0
  145. data/sig/luoma/tags/with.rbs +15 -0
  146. data/sig/luoma/template.rbs +117 -0
  147. data/sig/luoma/token.rbs +81 -0
  148. data/sig/luoma.rbs +11 -0
  149. data/zensical.toml +363 -0
  150. data.tar.gz.sig +0 -0
  151. metadata +233 -0
  152. metadata.gz.sig +0 -0
@@ -0,0 +1,44 @@
1
+ module Luoma
2
+ class Drop
3
+ include Enumerable[untyped]
4
+
5
+ # (untyped, RenderContext) -> bool
6
+ def key?: (untyped obj, Luoma::RenderContext context) -> bool
7
+
8
+ # (String, RenderContext) -> untyped
9
+ def fetch: (untyped name, Luoma::RenderContext context, ?default: untyped?) -> untyped
10
+
11
+ def each: () ?{ (?) -> untyped } -> untyped
12
+
13
+ def to_a: () -> Array[untyped]
14
+
15
+ # (untyped, RenderContext) -> bool
16
+ def eq?: (untyped obj, Luoma::RenderContext context) -> bool
17
+
18
+ # (untyped, RenderContext) -> bool
19
+ def lt?: (untyped obj, Luoma::RenderContext context) -> bool
20
+
21
+ # (untyped, RenderContext) -> bool
22
+ def gt?: (untyped obj, Luoma::RenderContext context) -> bool
23
+
24
+ # (untyped, RenderContext) -> bool
25
+ def contains?: (untyped obj, Luoma::RenderContext context) -> bool
26
+
27
+ # Return the length of this object.
28
+ # Along with `#slice`, `#length` is part of the iterator protocol.
29
+ # (RenderContext) -> Integer
30
+ def length: (Luoma::RenderContext context) -> Integer
31
+
32
+ # (Integer, Integer, Integer) -> Enumerable[untyped]
33
+ def slice: (Integer start, Integer stop, Integer step) -> untyped
34
+
35
+ # (:data | :numeric | :string | :boolean, RenderContext) -> untyped
36
+ def to_primitive: (:data | :numeric | :string | :boolean hint, Luoma::RenderContext context) -> untyped
37
+
38
+ # () -> String
39
+ def to_s: () -> String
40
+
41
+ # (RenderContext) -> String?
42
+ def render: (RenderContext context) -> String?
43
+ end
44
+ end
@@ -0,0 +1,10 @@
1
+ module Luoma
2
+ class BlockDrop < Drop
3
+ @block: t_block
4
+
5
+ # (t_block) -> void
6
+ def initialize: (t_block block) -> void
7
+
8
+ def render: (RenderContext context) -> string
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Luoma
2
+ class ExpressionDrop < Drop
3
+ @expr: LambdaExpr
4
+
5
+ attr_reader expr: LambdaExpr
6
+
7
+ # (LambdaExpr) -> void
8
+ def initialize: (LambdaExpr expr) -> void
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module Luoma
2
+ class HTMLSafe < Drop
3
+ @s: String
4
+
5
+ # (String | HTMLSafe) -> HTMLSafe
6
+ def self.escape: (String | HTMLSafe value) -> HTMLSafe
7
+
8
+ # (String | HTMLSafe) -> HTMLSafe
9
+ def self.from: (String | HTMLSafe value) -> HTMLSafe
10
+
11
+ # (String) -> void
12
+ def initialize: (String s) -> void
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module Luoma
2
+ class RangeDrop < Drop
3
+ @start: Integer
4
+
5
+ @stop: Integer
6
+
7
+ @range: Range[Integer]
8
+
9
+ attr_reader start: Integer
10
+
11
+ attr_reader stop: Integer
12
+
13
+ def initialize: (Integer start, Integer stop) -> void
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ module Luoma
2
+ attr_reader path: String
3
+
4
+ # The default and base "undefined" type.
5
+ class UndefinedDrop < Drop
6
+ @path: String
7
+
8
+ @token: t_token
9
+
10
+ @source: String
11
+
12
+ @template_name: String
13
+
14
+ # (String, t_token, String, String) -> void
15
+ def initialize: (String path, t_token token, String source, String template_name) -> void
16
+
17
+ # (untyped, RenderContext) -> bool
18
+ def eq?: (untyped obj, RenderContext context) -> bool
19
+ end
20
+
21
+ class StrictUndefinedDrop < UndefinedDrop
22
+ def error: () -> untyped
23
+ end
24
+
25
+ class FalsyStrictUndefinedDrop < StrictUndefinedDrop
26
+ end
27
+ end
@@ -0,0 +1,212 @@
1
+ module Luoma
2
+ type t_namespace = Hash[String, untyped]
3
+
4
+ interface _Namespace
5
+ def key?: (String) -> bool
6
+ def fetch: (String, ?::Symbol default) -> untyped
7
+ def []: (String) -> untyped
8
+ def nil?: () -> bool
9
+ end
10
+
11
+ interface _Lexer
12
+ def tokenize: (Environment, String) -> Array[t_token]
13
+ end
14
+
15
+ interface _Parser
16
+ def parse: (Environment, String, String, Array[t_token]) -> t_block
17
+ end
18
+
19
+ class Environment
20
+ @auto_trim: '-' | '~' | nil
21
+
22
+ @globals: t_namespace?
23
+
24
+ @lexer: _Lexer
25
+
26
+ @loader: TemplateLoader
27
+
28
+ @parser: _Parser
29
+
30
+ @strict: bool
31
+
32
+ @suppress_blank_control_flow_blocks: bool
33
+
34
+ @undefined: singleton(UndefinedDrop)
35
+
36
+ @tags: Hash[String, _Tag]
37
+
38
+ @filters: Hash[String, untyped]
39
+
40
+ @predicates: Hash[String, ^(untyped) -> bool]
41
+
42
+ @max_assign_score_cumulative: Integer?
43
+
44
+ @max_assign_score: Integer?
45
+
46
+ @max_context_depth: Integer
47
+
48
+ @max_render_score_cumulative: Integer?
49
+
50
+ @max_render_score: Integer?
51
+
52
+ @max_render_size: Integer?
53
+
54
+ @persistent_registers: Set[Symbol]
55
+
56
+ attr_accessor auto_trim: '-' | '~' | nil
57
+
58
+ attr_accessor globals: t_namespace?
59
+
60
+ attr_accessor lexer: _Lexer
61
+
62
+ attr_accessor loader: TemplateLoader
63
+
64
+ attr_accessor parser: _Parser
65
+
66
+ attr_reader filters: Hash[String, untyped]
67
+
68
+ attr_reader predicates: Hash[String, ^(untyped) -> bool]
69
+
70
+ attr_accessor strict: bool
71
+
72
+ attr_reader tags: Hash[String, _Tag]
73
+
74
+ attr_accessor undefined: singleton(UndefinedDrop)
75
+
76
+ attr_accessor max_assign_score_cumulative: Integer?
77
+
78
+ attr_accessor max_assign_score: Integer?
79
+
80
+ attr_accessor max_context_depth: Integer
81
+
82
+ attr_accessor max_render_score_cumulative: Integer?
83
+
84
+ attr_accessor max_render_score: Integer?
85
+
86
+ attr_accessor max_render_size: Integer?
87
+
88
+ attr_reader persistent_registers: Set[Symbol]
89
+
90
+ RE_INTEGER: Regexp
91
+
92
+ RE_DECIMAL: Regexp
93
+
94
+ def initialize: (
95
+ ?auto_trim: ('-' | '~' | nil),
96
+ ?globals: t_namespace?,
97
+ ?lexer: _Lexer,
98
+ ?loader: TemplateLoader?,
99
+ ?parser: _Parser,
100
+ ?strict: bool,
101
+ ?suppress_blank_control_flow_blocks: bool,
102
+ ?undefined: singleton(UndefinedDrop),
103
+ ?max_assign_score_cumulative: Integer?,
104
+ ?max_assign_score: Integer?,
105
+ ?max_context_depth: Integer,
106
+ ?max_render_score_cumulative: Integer?,
107
+ ?max_render_score: Integer?,
108
+ ?max_render_size: Integer?
109
+ ) -> void
110
+
111
+ # (String,
112
+ # ?globals: t_namespace?,
113
+ # ?name: String?,
114
+ # ?overlay: t_namespace?,
115
+ # ?up_to_date: Proc::_Callable?) -> Template
116
+ def parse: (String source, ?globals: t_namespace?, ?name: String?, ?overlay: t_namespace?, ?up_to_date: untyped?) -> Template
117
+
118
+ # (String, ?t_namespace?) -> String
119
+ def render: (String source, ?t_namespace? data) -> String
120
+
121
+ # (String, ?globals: t_namespace?, ?context: RenderContext?, **untyped) -> Template
122
+ def get_template: (String name, ?globals: t_namespace?, ?context: RenderContext?, **untyped kwargs) -> Template
123
+
124
+ # Add or replace a filter. The same callable can be registered multiple
125
+ # times with different names.
126
+ #
127
+ # When evaluated as a filter, _callable_ will be called with an instance of
128
+ # `FilterContext` as the first argument, and the result of the expression
129
+ # to the left of the pipe operator as the second argument.
130
+ #
131
+ # Remaining positional and keyword arguments are passed through from the
132
+ # filter invocation.
133
+ #
134
+ #: (String, untyped) -> void
135
+ def register_filter: (String name, untyped callable) -> void
136
+
137
+ # Remove a filter from the filter register.
138
+ #: (String) -> untyped
139
+ def delete_filter: (String name) -> void
140
+
141
+ # Add or replace a tag.
142
+ #: (String, _Tag) -> void
143
+ def register_tag: (String name, _Tag tag) -> void
144
+
145
+ # Remove a tag from the tag register.
146
+ #: (String) -> (_Tag | nil)
147
+ def delete_tag: (String name) -> _Tag?
148
+
149
+ # Add or replace a predicate function.
150
+ #: (String, ^(untyped) -> bool) -> void
151
+ def register_predicate: (String name, untyped callable) -> void
152
+
153
+ # Remove a predicate from the predicate register.
154
+ #: (String) -> (^(untyped) -> bool | nil)
155
+ def delete_predicate: (String name) -> untyped
156
+
157
+ # () -> void
158
+ def setup_tags_filters_and_predicates: () -> void
159
+
160
+ # (untyped, untyped, RenderContext, t_token) -> bool
161
+ def contains?: (untyped left, untyped right, RenderContext context, t_token token) -> bool
162
+
163
+ # (untyped, untyped, RenderContext, t_token) -> bool
164
+ def eq?: (untyped left, untyped right, RenderContext context, t_token token) -> bool
165
+
166
+ # (untyped, untyped, RenderContext, t_token) -> bool?
167
+ def lt?: (untyped left, untyped right, RenderContext context, t_token token) -> bool?
168
+
169
+ # (untyped, untyped, RenderContext, t_token) -> (-1 | 1 | 0 | nil)
170
+ def cmp: (untyped left, untyped right, RenderContext context, t_token token) -> (-1 | 1 | 0 | nil)
171
+
172
+ # (untyped) -> bool
173
+ def nothing?: (untyped obj) -> bool
174
+
175
+ # (untyped, RenderContext) -> bool
176
+ def truthy?: (untyped obj, RenderContext context) -> bool
177
+
178
+ # (untyped, RenderContext) -> String
179
+ def serialize: (untyped obj, RenderContext context) -> String
180
+
181
+ # (untyped, RenderContext) -> Array[untyped]
182
+ def to_a: (untyped obj, RenderContext context) -> Array[untyped]
183
+
184
+ # (untyped, RenderContext) -> Hash[untyped, untyped]
185
+ def to_h: (untyped obj, RenderContext context) -> Hash[untyped, untyped]
186
+
187
+ # [X] (untyped, RenderContext, ?default: X) -> (Integer | X)
188
+ def to_i: [X] (untyped obj, RenderContext context, ?default: X) -> (Integer | X)
189
+
190
+ # [X] (untyped, RenderContext, ?default: X) -> (Numeric | X)
191
+ def to_numeric: [X] (untyped obj, RenderContext context, ?default: X) -> (Numeric | X)
192
+
193
+ # (untyped, RenderContext) -> Enumerable
194
+ def to_enumerable: (untyped obj, RenderContext context) -> Enumerable[untyped]
195
+
196
+ # (untyped, RenderContext) -> String
197
+ def to_string: (untyped obj, RenderContext context) -> String
198
+
199
+ # Cast _obj_ to a date and time. Return `nil` if casting fails.
200
+ # NOTE: This was copied from Shopify/liquid.
201
+ def to_date: (untyped obj, RenderContext context) -> untyped
202
+
203
+ # (String, String?, String?) -> String
204
+ def trim: (String value, String? left, String? right) -> String
205
+
206
+ # (t_namespace?) -> t_namespace?
207
+ def make_globals: (t_namespace? namespace) -> t_namespace?
208
+
209
+ # (untyped, RenderContext) -> untyped
210
+ def to_data: (untyped obj, RenderContext context) -> untyped
211
+ end
212
+ end
@@ -0,0 +1,67 @@
1
+ module Luoma
2
+ # The base class for all template errors.
3
+ class LuomaError < StandardError
4
+ end
5
+
6
+ class DetailedLuomaError < LuomaError
7
+ @token: t_token
8
+
9
+ @template_name: String
10
+
11
+ @source: String
12
+
13
+ attr_accessor token: t_token
14
+
15
+ attr_accessor template_name: String
16
+
17
+ attr_accessor source: String
18
+
19
+ def initialize: (String message, t_token token, String source, String template_name) -> void
20
+
21
+ def detailed_message: (?highlight: bool, **untyped kwargs) -> String
22
+
23
+ def error_context: (String source, Integer index) -> [Integer, Integer, String]
24
+ end
25
+
26
+ class DisabledTagError < DetailedLuomaError
27
+ end
28
+
29
+ class FilterArgumentError < DetailedLuomaError
30
+ end
31
+
32
+ class FilterNotFoundError < DetailedLuomaError
33
+ end
34
+
35
+ class PredicateNotFoundError < DetailedLuomaError
36
+ end
37
+
38
+ class RequiredBlockError < TemplateInheritanceError
39
+ end
40
+
41
+ class ResourceLimitError < LuomaError
42
+ end
43
+
44
+ class ContextDepthError < ResourceLimitError
45
+ end
46
+
47
+ class TemplateInheritanceError < DetailedLuomaError
48
+ end
49
+
50
+ class TemplateNotFoundError < LuomaError
51
+ end
52
+
53
+ class NoSuchTemplateError < DetailedLuomaError
54
+ end
55
+
56
+ class TemplateSyntaxError < DetailedLuomaError
57
+ end
58
+
59
+ class TemplateTypeError < DetailedLuomaError
60
+ end
61
+
62
+ class UndefinedVariableError < DetailedLuomaError
63
+ end
64
+
65
+ class IncomparableValuesError < LuomaError
66
+ end
67
+ end
@@ -0,0 +1,15 @@
1
+ module Luoma
2
+ RE_ESCAPE: ::Regexp
3
+
4
+ ESCAPE_MAP: Hash[String, String]
5
+
6
+ RE_UNESCAPE: ::Regexp
7
+
8
+ UNESCAPE_MAP: Hash[String, String]
9
+
10
+ # (String) -> String
11
+ def self.escape: (String s) -> String
12
+
13
+ # (String) -> String
14
+ def self.unescape: (String s) -> String
15
+ end