luoma 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +4 -2
- data/README.md +3 -3
- data/docs/filter_reference.md +182 -0
- data/docs/index.md +4 -0
- data/lib/luoma/environment.rb +1 -0
- data/lib/luoma/filters/array.rb +9 -0
- data/lib/luoma/version.rb +1 -1
- data/sig/luoma/filters/array.rbs +4 -0
- data/zensical.toml +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f24da19a06edd7781345b3b0e4d9aa73c616404472c24e50e068d9acb0a8e463
|
|
4
|
+
data.tar.gz: 97b49239b9ac0de992568860034dd7f8a5735739b3ee42f345508377a3c38eea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09c958eadecea8638b9fe6ce31907e83640f44342b78978696564bf3128e625f7604d09db53d2f62a1831ca238811eee9baf98e505d5be968cd7a3467479f5bf'
|
|
7
|
+
data.tar.gz: 19ce9bc9c86d34a65a1044803ec1627a916d92ad37bb9246166a2b4841f28dcfb53ebaf11e60eee9eff812dfda3854894a941e57ac0341c377f8bb3cf605c8ba
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<h1 align="center">Luoma - Ruby</h1>
|
|
2
2
|
|
|
3
|
-
<p align="center">A modern template engine
|
|
3
|
+
<p align="center">A modern template engine with a well-defined, composable, implementation agnostic expression language.</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<a href="https://github.com/jg-rp/luoma-ruby/blob/main/LICENSE.txt">
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<img alt="Gem Version" src="https://img.shields.io/gem/v/luoma?style=flat-square">
|
|
15
15
|
</a>
|
|
16
16
|
<a href="https://github.com/jg-rp/luoma-ruby">
|
|
17
|
-
<img alt="Static Badge" src="https://img.shields.io/badge/Ruby-3.
|
|
17
|
+
<img alt="Static Badge" src="https://img.shields.io/badge/Ruby-3.3%20%7C%203.4%20%7C%204.0-CC342D?style=flat-square">
|
|
18
18
|
</a>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
@@ -57,7 +57,7 @@ puts template.render("you" => "Luoma") # Hello, Luoma!
|
|
|
57
57
|
|
|
58
58
|
## Links
|
|
59
59
|
|
|
60
|
-
- Documentation: https://jg-rp.github.io/luoma/
|
|
60
|
+
- Documentation: https://jg-rp.github.io/luoma-ruby/
|
|
61
61
|
- Change log: https://github.com/jg-rp/luoma-ruby/blob/main/CHANGELOG.md
|
|
62
62
|
- RubyGems: https://rubygems.org/gems/luoma
|
|
63
63
|
- Source code: https://github.com/jg-rp/luoma-ruby
|
data/docs/filter_reference.md
CHANGED
|
@@ -37,6 +37,156 @@ Given a value that can't be cast to an integer or float, the special value `Noth
|
|
|
37
37
|
0
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
## all
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
<array> | all
|
|
44
|
+
<array> | all: <string> [, <value>]
|
|
45
|
+
<array> | all: <lambda>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Return `true` if all items in the input array are truthy, or `false` otherwise.
|
|
49
|
+
|
|
50
|
+
```liquid2
|
|
51
|
+
{{ [true, true, true] | all }}
|
|
52
|
+
{{ [true, false, true] | all }}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```title="Output"
|
|
56
|
+
true
|
|
57
|
+
false
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
If a string argument is given, array items should be objects and the string is used as a property name to test for truthiness.
|
|
61
|
+
|
|
62
|
+
```liquid2
|
|
63
|
+
{% assign
|
|
64
|
+
items = [
|
|
65
|
+
{"title": "foo", "active": true},
|
|
66
|
+
{"title": "bar", "active": false},
|
|
67
|
+
{"title": "baz", "active": true},
|
|
68
|
+
]
|
|
69
|
+
%}
|
|
70
|
+
|
|
71
|
+
{{ items | all: "active" }}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
```title="Output"
|
|
75
|
+
false
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
If the optional second argument is given, the value at the given property will be compared to the argument value instead of testing for truthiness.
|
|
79
|
+
|
|
80
|
+
```liquid2
|
|
81
|
+
{% assign
|
|
82
|
+
items = [
|
|
83
|
+
{"title": "foo", "state": 2},
|
|
84
|
+
{"title": "bar", "state": 2},
|
|
85
|
+
{"title": "baz", "state": 2},
|
|
86
|
+
]
|
|
87
|
+
%}
|
|
88
|
+
|
|
89
|
+
{{ items | all: "state", 2 }}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```title="Output"
|
|
93
|
+
true
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Given a lambda expression as the first argument, the expression will be evaluated for each item in the input array and the result tested for truthiness.
|
|
97
|
+
|
|
98
|
+
```liquid2
|
|
99
|
+
{% assign
|
|
100
|
+
items = [
|
|
101
|
+
{"title": "foo", "state": 2},
|
|
102
|
+
{"title": "bar", "state": 3},
|
|
103
|
+
{"title": "baz", "state": 1},
|
|
104
|
+
]
|
|
105
|
+
%}
|
|
106
|
+
|
|
107
|
+
{{ items | all: (x) -> x.state < 5 }}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```title="Output"
|
|
111
|
+
true
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## any
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
<array> | any
|
|
118
|
+
<array> | any: <string> [, <value>]
|
|
119
|
+
<array> | any: <lambda>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Return `true` if any of the items in the input array are truthy, or `false` if they are all falsy.
|
|
123
|
+
|
|
124
|
+
```liquid2
|
|
125
|
+
{{ [true, true, true] | any }}
|
|
126
|
+
{{ [true, false, true] | any }}
|
|
127
|
+
{{ [false, false, false] | any }}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```title="Output"
|
|
131
|
+
true
|
|
132
|
+
true
|
|
133
|
+
false
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
If a string argument is given, array items should be objects and the string is used as a property name to test for truthiness.
|
|
137
|
+
|
|
138
|
+
```liquid2
|
|
139
|
+
{% assign
|
|
140
|
+
items = [
|
|
141
|
+
{"title": "foo", "active": true},
|
|
142
|
+
{"title": "bar", "active": false},
|
|
143
|
+
{"title": "baz", "active": true},
|
|
144
|
+
]
|
|
145
|
+
%}
|
|
146
|
+
|
|
147
|
+
{{ items | any: "active" }}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```title="Output"
|
|
151
|
+
true
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
If the optional second argument is given, the value at the given property will be compared to the argument value instead of testing for truthiness.
|
|
155
|
+
|
|
156
|
+
```liquid2
|
|
157
|
+
{% assign
|
|
158
|
+
items = [
|
|
159
|
+
{"title": "foo", "state": 2},
|
|
160
|
+
{"title": "bar", "state": 2},
|
|
161
|
+
{"title": "baz", "state": 2},
|
|
162
|
+
]
|
|
163
|
+
%}
|
|
164
|
+
|
|
165
|
+
{{ items | any: "state", 2 }}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
```title="Output"
|
|
169
|
+
true
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Given a lambda expression as the first argument, the expression will be evaluated for each item in the input array and the result tested for truthiness.
|
|
173
|
+
|
|
174
|
+
```liquid2
|
|
175
|
+
{% assign
|
|
176
|
+
items = [
|
|
177
|
+
{"title": "foo", "state": 2},
|
|
178
|
+
{"title": "bar", "state": 3},
|
|
179
|
+
{"title": "baz", "state": 1},
|
|
180
|
+
]
|
|
181
|
+
%}
|
|
182
|
+
|
|
183
|
+
{{ items | any: (x) -> x.state < 2 }}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
```title="Output"
|
|
187
|
+
true
|
|
188
|
+
```
|
|
189
|
+
|
|
40
190
|
## append
|
|
41
191
|
|
|
42
192
|
```
|
|
@@ -677,6 +827,14 @@ Ground
|
|
|
677
827
|
|
|
678
828
|
If the input sequence is undefined, empty or not a sequence, `nil` is returned.
|
|
679
829
|
|
|
830
|
+
## flatten
|
|
831
|
+
|
|
832
|
+
TODO
|
|
833
|
+
|
|
834
|
+
## flat_map
|
|
835
|
+
|
|
836
|
+
TODO
|
|
837
|
+
|
|
680
838
|
## floor
|
|
681
839
|
|
|
682
840
|
```
|
|
@@ -779,6 +937,10 @@ If an argument string is not given, it defaults to a single space.
|
|
|
779
937
|
John Paul George Ringo
|
|
780
938
|
```
|
|
781
939
|
|
|
940
|
+
## json
|
|
941
|
+
|
|
942
|
+
TODO
|
|
943
|
+
|
|
782
944
|
## last
|
|
783
945
|
|
|
784
946
|
```
|
|
@@ -852,6 +1014,14 @@ For example, if `pages` is an array of objects with a `category` property:
|
|
|
852
1014
|
- technology
|
|
853
1015
|
```
|
|
854
1016
|
|
|
1017
|
+
## max
|
|
1018
|
+
|
|
1019
|
+
TODO:
|
|
1020
|
+
|
|
1021
|
+
## min
|
|
1022
|
+
|
|
1023
|
+
TODO:
|
|
1024
|
+
|
|
855
1025
|
## minus
|
|
856
1026
|
|
|
857
1027
|
```
|
|
@@ -1366,6 +1536,10 @@ The optional argument is a sort key. If given, it should be the name of a proper
|
|
|
1366
1536
|
<h4>A Shoe</h4>
|
|
1367
1537
|
```
|
|
1368
1538
|
|
|
1539
|
+
## sort_numeric
|
|
1540
|
+
|
|
1541
|
+
TODO
|
|
1542
|
+
|
|
1369
1543
|
## split
|
|
1370
1544
|
|
|
1371
1545
|
```
|
|
@@ -1487,6 +1661,10 @@ Return the sum of all numeric elements in an array.
|
|
|
1487
1661
|
|
|
1488
1662
|
If the optional string argument is given, it is assumed that array items are hash/dict/mapping-like, and the argument should be the name of a property/key. The values at `array[property]` will be summed.
|
|
1489
1663
|
|
|
1664
|
+
## take
|
|
1665
|
+
|
|
1666
|
+
TODO
|
|
1667
|
+
|
|
1490
1668
|
## times
|
|
1491
1669
|
|
|
1492
1670
|
```
|
|
@@ -1700,3 +1878,7 @@ Available product:
|
|
|
1700
1878
|
- Television
|
|
1701
1879
|
- Garlic press
|
|
1702
1880
|
```
|
|
1881
|
+
|
|
1882
|
+
## zip
|
|
1883
|
+
|
|
1884
|
+
TODO:
|
data/docs/index.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Luoma - Ruby
|
|
2
2
|
|
|
3
|
+
!!! warning
|
|
4
|
+
|
|
5
|
+
This documentation is a work in progress.
|
|
6
|
+
|
|
3
7
|
Luoma is a modern template engine with a well-defined, composable, implementation agnostic expression language.
|
|
4
8
|
|
|
5
9
|
Luoma markup will be familiar to anyone who's used [Liquid](https://github.com/Shopify/liquid), [Jinja](https://jinja.palletsprojects.com/en/stable/) or [Django's template language](https://docs.djangoproject.com/en/6.0/topics/templates/#the-django-template-language), but with a strictly immutable data model, first-class blocks and expressions, and functional primitives for when data transformation is necessary.
|
data/lib/luoma/environment.rb
CHANGED
|
@@ -205,6 +205,7 @@ module Luoma
|
|
|
205
205
|
register_filter("strip_newlines", Luoma::Filters.method(:strip_newlines))
|
|
206
206
|
register_filter("strip", Luoma::Filters.method(:strip))
|
|
207
207
|
register_filter("sum", Luoma::Filters.method(:sum))
|
|
208
|
+
register_filter("take", Luoma::Filters.method(:take))
|
|
208
209
|
register_filter("times", Luoma::Filters.method(:times))
|
|
209
210
|
register_filter("truncate", Luoma::Filters.method(:truncate))
|
|
210
211
|
register_filter("truncatewords", Luoma::Filters.method(:truncatewords))
|
data/lib/luoma/filters/array.rb
CHANGED
|
@@ -368,5 +368,14 @@ module Luoma
|
|
|
368
368
|
max_.call(left) { |item, _index| context.fetch(item, key, default: nil) }
|
|
369
369
|
end
|
|
370
370
|
end
|
|
371
|
+
|
|
372
|
+
# Return at most _count_ items from `_left` as a new array.
|
|
373
|
+
# Coerce _left_ to an array if it's not an array already.
|
|
374
|
+
# Coerce _count_ to an integer, or zero if it is not numeric.
|
|
375
|
+
def self.take(context, left, count)
|
|
376
|
+
count_ = context.to_i(count, default: 0)
|
|
377
|
+
count_ = 0 if count_.negative?
|
|
378
|
+
context.to_enumerable(left).take(count_)
|
|
379
|
+
end
|
|
371
380
|
end
|
|
372
381
|
end
|
data/lib/luoma/version.rb
CHANGED
data/sig/luoma/filters/array.rbs
CHANGED
|
@@ -70,5 +70,9 @@ module Luoma
|
|
|
70
70
|
# Return the maximum numeric value found in _left_.
|
|
71
71
|
# Coerce _left_ to an array if it's not an array already.
|
|
72
72
|
def self.max: (FilterContext context, untyped left, ?untyped key) -> untyped
|
|
73
|
+
|
|
74
|
+
# Return at most _count_ items from `_left` as a new array.
|
|
75
|
+
# Coerce _left_ to an array if it's not an array already.
|
|
76
|
+
def self.take: (FilterContext context, untyped left, untyped count) -> Array[untyped]
|
|
73
77
|
end
|
|
74
78
|
end
|
data/zensical.toml
CHANGED
|
@@ -202,7 +202,7 @@ features = [
|
|
|
202
202
|
# In order to provide a better user experience on slow connections when
|
|
203
203
|
# using instant navigation, a progress indicator can be enabled.
|
|
204
204
|
# https://zensical.org/docs/setup/navigation/#progress-indicator
|
|
205
|
-
|
|
205
|
+
"navigation.instant.progress",
|
|
206
206
|
|
|
207
207
|
# When navigation paths are activated, a breadcrumb navigation is rendered
|
|
208
208
|
# above the title of each page
|
data.tar.gz.sig
CHANGED
|
Binary file
|
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.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Prior
|
|
@@ -204,11 +204,11 @@ files:
|
|
|
204
204
|
- sig/luoma/template.rbs
|
|
205
205
|
- sig/luoma/token.rbs
|
|
206
206
|
- zensical.toml
|
|
207
|
-
homepage: https://jg-rp.github.io/luoma/
|
|
207
|
+
homepage: https://jg-rp.github.io/luoma-ruby/
|
|
208
208
|
licenses:
|
|
209
209
|
- MIT
|
|
210
210
|
metadata:
|
|
211
|
-
homepage_uri: https://jg-rp.github.io/luoma/
|
|
211
|
+
homepage_uri: https://jg-rp.github.io/luoma-ruby/
|
|
212
212
|
source_code_uri: https://github.com/jg-rp/luoma-ruby
|
|
213
213
|
changelog_uri: https://github.com/jg-rp/luoma-ruby/blob/main/CHANGELOG.md
|
|
214
214
|
rubygems_mfa_required: 'true'
|
metadata.gz.sig
CHANGED
|
Binary file
|