luoma 0.2.0 → 0.3.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 (55) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +2 -2
  5. data/lib/luoma/context.rb +2 -1
  6. data/lib/luoma/drop.rb +2 -3
  7. data/lib/luoma/drops/range.rb +1 -1
  8. data/lib/luoma/drops/undefined.rb +1 -1
  9. data/lib/luoma/environment.rb +13 -14
  10. data/lib/luoma/escape.rb +53 -0
  11. data/lib/luoma/expression.rb +8 -8
  12. data/lib/luoma/filter.rb +3 -3
  13. data/lib/luoma/filters/escape_js.rb +12 -0
  14. data/lib/luoma/filters/slice.rb +1 -1
  15. data/lib/luoma/filters/sort.rb +0 -25
  16. data/lib/luoma/filters/string.rb +2 -2
  17. data/lib/luoma/loaders/file_system_loader.rb +10 -9
  18. data/lib/luoma/parser_unified.rb +2 -1
  19. data/lib/luoma/tags/assign.rb +4 -0
  20. data/lib/luoma/tags/case.rb +1 -1
  21. data/lib/luoma/template.rb +0 -2
  22. data/lib/luoma/version.rb +1 -1
  23. data/lib/luoma.rb +2 -0
  24. data/sig/luoma/drop.rbs +2 -2
  25. data/sig/luoma/environment.rbs +8 -8
  26. data/sig/luoma/escape.rbs +7 -0
  27. data/sig/luoma/filters/escape_js.rbs +6 -0
  28. data/sig/luoma/filters/sort.rbs +0 -4
  29. data/sig/luoma/loaders/file_system_loader.rbs +4 -0
  30. data.tar.gz.sig +1 -2
  31. metadata +4 -26
  32. metadata.gz.sig +0 -0
  33. data/docs/configuration.md +0 -180
  34. data/docs/custom_filters.md +0 -3
  35. data/docs/custom_tags.md +0 -3
  36. data/docs/expressions.md +0 -3
  37. data/docs/extension_types.md +0 -41
  38. data/docs/filter_reference.md +0 -1884
  39. data/docs/index.md +0 -77
  40. data/docs/luoma_for_template_authors.md +0 -3
  41. data/docs/markdown.md +0 -111
  42. data/docs/predicate_reference.md +0 -3
  43. data/docs/static_analysis.md +0 -3
  44. data/docs/tag_reference.md +0 -352
  45. data/docs/template_loaders.md +0 -177
  46. data/docs/undefined_variables.md +0 -3
  47. data/docs-requirements.txt +0 -11
  48. data/docs_/cycle.md +0 -17
  49. data/docs_/font_rendering_example.md +0 -157
  50. data/docs_/header_block_example.md +0 -51
  51. data/docs_/increment_and_decrement.md +0 -49
  52. data/docs_/logo_style_example.md +0 -40
  53. data/docs_/migration.md +0 -11
  54. data/docs_/notes.md +0 -19
  55. data/zensical.toml +0 -363
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luoma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Prior
@@ -64,28 +64,6 @@ files:
64
64
  - Rakefile
65
65
  - Steepfile
66
66
  - certs/jgrp.pem
67
- - docs-requirements.txt
68
- - docs/configuration.md
69
- - docs/custom_filters.md
70
- - docs/custom_tags.md
71
- - docs/expressions.md
72
- - docs/extension_types.md
73
- - docs/filter_reference.md
74
- - docs/index.md
75
- - docs/luoma_for_template_authors.md
76
- - docs/markdown.md
77
- - docs/predicate_reference.md
78
- - docs/static_analysis.md
79
- - docs/tag_reference.md
80
- - docs/template_loaders.md
81
- - docs/undefined_variables.md
82
- - docs_/cycle.md
83
- - docs_/font_rendering_example.md
84
- - docs_/header_block_example.md
85
- - docs_/increment_and_decrement.md
86
- - docs_/logo_style_example.md
87
- - docs_/migration.md
88
- - docs_/notes.md
89
67
  - lib/luoma.rb
90
68
  - lib/luoma/cache.rb
91
69
  - lib/luoma/chain_hash.rb
@@ -104,6 +82,7 @@ files:
104
82
  - lib/luoma/filters/array.rb
105
83
  - lib/luoma/filters/date.rb
106
84
  - lib/luoma/filters/default.rb
85
+ - lib/luoma/filters/escape_js.rb
107
86
  - lib/luoma/filters/json.rb
108
87
  - lib/luoma/filters/math.rb
109
88
  - lib/luoma/filters/size.rb
@@ -163,6 +142,7 @@ files:
163
142
  - sig/luoma/filters/array.rbs
164
143
  - sig/luoma/filters/date.rbs
165
144
  - sig/luoma/filters/default.rbs
145
+ - sig/luoma/filters/escape_js.rbs
166
146
  - sig/luoma/filters/json.rbs
167
147
  - sig/luoma/filters/math.rbs
168
148
  - sig/luoma/filters/size.rbs
@@ -203,7 +183,6 @@ files:
203
183
  - sig/luoma/tags/with.rbs
204
184
  - sig/luoma/template.rbs
205
185
  - sig/luoma/token.rbs
206
- - zensical.toml
207
186
  homepage: https://jg-rp.github.io/luoma-ruby/
208
187
  licenses:
209
188
  - MIT
@@ -228,6 +207,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
207
  requirements: []
229
208
  rubygems_version: 4.0.6
230
209
  specification_version: 4
231
- summary: A modern template engine with a well-defined, composable agnostic expression
232
- language.
210
+ summary: A modern template engine with a well-defined, composable expression language.
233
211
  test_files: []
metadata.gz.sig CHANGED
Binary file
@@ -1,180 +0,0 @@
1
- ---
2
- title: Setup
3
- ---
4
-
5
- # Luoma environments
6
-
7
- Template parsing and rendering behavior is configured using an instance of `Luoma::Environment`. Once configured, parse templates with `Environment#parse(source)` or `Environment#get_template(name)`, both of which return an instance of `Luoma::Template`.
8
-
9
- An `Environment` is where you'd register custom filters or tags, or define variables that should be available to all templates, for example.
10
-
11
- !!! tip
12
-
13
- In addition to the environment options shown here, `Luoma::Environment` is designed to be extended. You can, for example, override `Luoma::Environment#eq?` to redefine expression equality, or override `Luoma::Environment#serialize` to change the way objects are rendered. See [environment.rb](https://github.com/jg-rp/luoma-ruby/blob/main/lib/luoma/expression.rb) for a complete method reference and default implementations.
14
-
15
- ## The default environment
16
-
17
- The default Luoma environment and new instances of `Luoma::Environment` constructed without any arguments are equivalent to passing the following arguments to `Environment.new`.
18
-
19
- ```ruby
20
- env = Luoma::Environment.new(
21
- auto_trim: nil,
22
- globals: nil,
23
- lexer: Luoma::UnifiedLexer,
24
- loader: Luoma::HashLoader.new({}),
25
- max_assign_score_cumulative: nil,
26
- max_assign_score: nil,
27
- max_context_depth: 30,
28
- max_render_score_cumulative: nil,
29
- max_render_score: nil,
30
- max_render_size: nil,
31
- parser: Luoma::UnifiedParser,
32
- strict: false,
33
- suppress_blank_control_flow_blocks: true,
34
- undefined: Luoma::UndefinedDrop
35
- )
36
- ```
37
-
38
- Top-level convenience methods `Luoma.parse` and `Luoma.render` always use the default environment.
39
-
40
- ## Managing tags, filters and predicates
41
-
42
- New instances of `Luoma::Environment` and the [default Luoma environment](#the-default-environment) have all standard tags, filters and predicates enabled by default. `Environment.tags`, `Environment.filters` and `Environment.predicates` are hashes mapping strings to `_Tag`, filter callables and predicate callables, respectively. You can add, remove, replace or alias tags, filters and predicates in an environment by updating these mappings after environment initialization.
43
-
44
- This example removes th `{% include %}` tag and renames `downcase` to `lower` and `upcase` to `upper`.
45
-
46
- ```ruby
47
-
48
- require "luoma"
49
-
50
- env = Luoma::Environment.new
51
- env.tags.delete("include")
52
- env.filters["lower"] = env.tags.delete("downcase")
53
- env.filters["upper"] = env.tags.delete("upcase")
54
- ```
55
-
56
- Alternatively, you can extend `Luoma::Environment` and override `setup_tags_filters_and_predicates`.
57
-
58
- ```ruby
59
- require "luoma"
60
-
61
- class MyLuomaEnv < Luoma::Environment
62
- #: () -> void
63
- def setup_tags_filters_and_predicates
64
- super
65
- @tags.delete("include")
66
- end
67
- end
68
-
69
- env = MyLuomaEnv.new
70
- # ...
71
- ```
72
-
73
- ## Auto trim
74
-
75
- The `auto_trim` option sets the default whitespace trimming mode. Setting `auto_trim: "-"` or `auto_trim: "~"` is equivalent to adding `-` or `~` before every closing markup delimiter.
76
-
77
- ```ruby
78
- require "luoma"
79
-
80
- source = <<~SOURCE.chomp
81
- <ul>
82
- {% for x in (1..4) %}
83
- <li>{{ x }}</li>
84
- {% endfor %}
85
- </ul>
86
- ---
87
- SOURCE
88
-
89
- puts Luoma::Environment.new.render(source)
90
- puts Luoma::Environment.new(auto_trim: "~").render(source)
91
- ```
92
-
93
- ```html title="output"
94
- <ul>
95
- <li>1</li>
96
-
97
- <li>2</li>
98
-
99
- <li>3</li>
100
-
101
- <li>4</li>
102
- </ul>
103
- ---
104
- <ul>
105
- <li>1</li>
106
- <li>2</li>
107
- <li>3</li>
108
- <li>4</li>
109
- </ul>
110
- ---
111
- ```
112
-
113
- ## Global variables
114
-
115
- Global template variables are those added by application developers, as opposed to local variables created by template authors with tags such as `{% assign %}` and `{% capture %}`. Globals can come from the following places, in order of highest to lowest priority.
116
-
117
- 1. The _data_ argument to `Luoma.render`, `Luoma::Environment#render` or `Luoma::Template#render`.
118
- 2. "overlay" or "matter" data provided by a template loader and bound to a `Luoma::Template` instance. This could be front matter parsed from the beginning of a template source file, or data from a database, for example.
119
- 3. The `globals` argument to `Luoma.parse` or `Luoma::Environment#parse`. These variables are pinned to the resulting template.
120
- 4. The `globals` argument when constructing a new `Luoma::Environment`. These variables are pinned to the environment and will be merged into other global data for every template rendered from the environment.
121
-
122
- You can change the global variable source priority by extending and overriding `Luoma::Environment#makeGlobals` and/or `Luoma::Template#makeGlobals`.
123
-
124
- ## Resource limits
125
-
126
- For deployments where template authors are untrusted, you can set limits on some resources to avoid malicious templates from consuming too much memory or too many CPU cycles. If any limit is exceeded, a `Luoma::ResourceLimitError` is raised.
127
-
128
- !!! note
129
-
130
- The following "scores" are non-specific measures of usage modelled on Shopify/liquid resource limits.
131
-
132
- These numbers are for illustration purposes. You'll need to do a bit of trial and error to find the limits that work best for you.
133
-
134
- ```ruby
135
- require "luoma"
136
-
137
- env = Luoma::Environment.new(
138
- # Maximum of 2000 "bytes" assigned with the assign/capture tags per template
139
- # or partial template.
140
- max_assign_score: 2000,
141
-
142
- # Maximum of 10,000 "bytes" assigned with the assign/capture tags for the
143
- # root template and all partial templates combined.
144
- max_assign_score_cumulative: 10000,
145
-
146
- # Maximum nesting of 30 `for` loops and/or `render` tags, for example.
147
- max_context_depth: 30,
148
-
149
- # Maximum of 1000 nodes (text and markup in the template syntax tree) rendered
150
- # per template.
151
- max_render_score: 1000,
152
-
153
- # Maximum of 5000 nodes (text and markup in the template syntax tree) rendered
154
- # for the root template and any rendered partial templates combined.
155
- max_render_score_cumulative: 5000,
156
-
157
- # Maximum of 15,000 bytes written to the output buffer.
158
- max_render_size: 15000,
159
- )
160
- ```
161
-
162
- ## Strict mode
163
-
164
- When `strict: false` (the default) unknown filters, unknown predicates and filter argument errors are silently ignored at render time. When `strict: true`, `Luoma::FilterNotFoundError`, `Luoma::PredicateNotFoundError` or `Luoma::FilterArgumentError` is raised, all of which inherit from `Luoma::LuomaError`.
165
-
166
- ```ruby
167
- require "luoma"
168
-
169
- source = "Hello, {{ you | title }}"
170
-
171
- puts Luoma::Environment.new.render(source)
172
- puts Luoma::Environment.new(strict: true).render(source)
173
-
174
- # Hello,
175
- # /home/james/projects/luoma-ruby/lib/luoma/expression.rb:195:in 'Luoma::FilteredExpression#evaluate_filter': Luoma::FilterNotFoundError: unknown filter "title"
176
- # -> "Hello, {{ you | title }}":1:17
177
- # |
178
- # 1 | Hello, {{ you | title }}
179
- # | ^^^^^ unknown filter "title"
180
- ```
@@ -1,3 +0,0 @@
1
- # Custom filters
2
-
3
- TODO
data/docs/custom_tags.md DELETED
@@ -1,3 +0,0 @@
1
- # Custom tags
2
-
3
- TODO:
data/docs/expressions.md DELETED
@@ -1,3 +0,0 @@
1
- # Expressions
2
-
3
- TODO
@@ -1,41 +0,0 @@
1
- # Extension types
2
-
3
- A drop is a developer-defined type that plays nicely with Luoma tags, filters, predicates and operators. Drops are often used to implement lazy data retrieval or context sensitive logic.
4
-
5
- The base drop, `Luoma::Drop`, is falsy, is an empty iterable/enumerable, is equal to nothing (including itself) and renders as an empty string.
6
-
7
- TODO: document the complete Drop API.
8
-
9
- ## Built-in drops
10
-
11
- ### `BlockDrop`
12
-
13
- A `Luoma::BlockDrop` encapsulates a block of Luoma markup. When an instance of `BlockDrop` is rendered, its internal markup is rendered to the output stream using variables from the current context, in the scope where it is "called".
14
-
15
- Similarly, if a `BlockDrop` is coerced to a string - passed to a filter or tag that expects a string value - its internal markup is rendered into a new string using variables from the current scope.
16
-
17
- Instances of `BlockDrop` are produced by the built-in `{% define %}` tag. When rendered, `{% define some_name %}...{% enddefine %}` binds a `BlockDrop` to the given name without writing to the output stream. This means blocks can be passed around and rendered multiple times in different contexts without loading a separate template.
18
-
19
- By default, Luoma has special rules for rendering **arrays** of `BlockDrop`. Given an array of `BlockDrop` instances and no other types, Luoma will render each block to the output stream separated by a single newline character. If an array contains `BlockDrop` instances mixed with strings, those blocks and strings are rendered in order without a separating newline. Otherwise the array is considered data and is output in JSON.
20
-
21
- ### `ExpressionDrop`
22
-
23
- A `Luoma::ExpressionDrop` encapsulates a single Luoma expression for later evaluation. When rendered or coerced to a string, `ExpressionDrop` produces a textual representation of its expression.
24
-
25
- Lambda literals (`(a, b) -> expression`) evaluate to an instance of `ExpressionDrop`, without capturing anything about the scope in which it is defined. Internally, Luoma's filter application operator (`|`) recognizes instances of `ExpressionDrop` as user-defined filters, and some built-in filters accept instances of `ExpressionDrop` as arguments.
26
-
27
- ### `RangeDrop`
28
-
29
- Range literals (`(1..5)`) evaluate to instances of `Luoma::RangeDrop`. When iterated, `RangeDrop` yields integers from its range of integer values.
30
-
31
- When rendered or coerced to a string, `RangeDrop` produces a JSON-like array of integers.
32
-
33
- ### `UndefinedDrop`
34
-
35
- Undefined variables resolve to an instance of of `Luoma::UndefinedDrop`, or one of its subclasses. Undefined variable behavior is configured by passing a `Luoma::UndefinedDrop` singleton to `Luoma::Environment.new`.
36
-
37
- See [Undefined variables](./undefined_variables.md) for a breakdown of the built-in `Undefined` types.
38
-
39
- ## Custom drops
40
-
41
- TODO: