liquidum 1.4.3 → 1.4.4
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
- data/.shipkit.yml +1 -1
- data/README.md +3 -1
- data/config/locales/en.yml +4 -0
- data/config/locales/nl.yml +4 -0
- data/lib/liquidum/filters.rb +30 -4
- data/lib/liquidum/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 184a362b7a5a6c5344164fe79127d14f872765546e8c26e80d8d44fd70df4dd5
|
|
4
|
+
data.tar.gz: 5d3cf537732e80265b97ecf0de056d335cae2130e824edf0402dbc747bc4aea6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 05cbe8851ecaee7d729460f73c3ac082369967f393a766eb4caa30f3bca3d76c93f3946cd28e58bd5ce48ed0686a0c0f2c5727403e362626cf4f444e31dbf30f
|
|
7
|
+
data.tar.gz: 4f0eab6bd9f6dd0248a8727b09eea109c9cd5fa148d5d242ea317bdec3112517cda46d3df09e1d4d488ce88af3b55f48540d505c3c67954529866957722970e2
|
data/.shipkit.yml
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
---
|
|
2
|
-
previous_version: 1.4.
|
|
2
|
+
previous_version: 1.4.3
|
data/README.md
CHANGED
|
@@ -97,7 +97,9 @@ GET /liquidum/filters
|
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
An argument's kind is `property`, `value` (of the property before it),
|
|
100
|
-
`format` (a date's
|
|
100
|
+
`format` (a date's, strftime's, with the app's `date.formats` and
|
|
101
|
+
`time.formats` as its `values`), `key` (a translation's), `locale` (with the
|
|
102
|
+
app's locales as its `values`, as `localize: 'nl'` has it) or `any`. An app describes its own
|
|
101
103
|
filters with `Liquidum::Filters.describe :money, arguments: [[:currency]]`, and
|
|
102
104
|
labels them as `liquidum.filters.<name>`.
|
|
103
105
|
|
data/config/locales/en.yml
CHANGED
|
@@ -27,6 +27,10 @@ en:
|
|
|
27
27
|
context:
|
|
28
28
|
not_a_json_object: 'must be a JSON object, like {"name": "value"}'
|
|
29
29
|
liquidum:
|
|
30
|
+
# The app's date.formats and time.formats, for a date filter's format (Liquidum::Filters)
|
|
31
|
+
formats:
|
|
32
|
+
date: "Date, %{name}"
|
|
33
|
+
time: "Time, %{name}"
|
|
30
34
|
tags:
|
|
31
35
|
assign: "Sets a variable"
|
|
32
36
|
attach: "Attaches a file"
|
data/config/locales/nl.yml
CHANGED
|
@@ -27,6 +27,10 @@ nl:
|
|
|
27
27
|
context:
|
|
28
28
|
not_a_json_object: 'moet een JSON-object zijn, zoals {"naam": "waarde"}'
|
|
29
29
|
liquidum:
|
|
30
|
+
# The app's date.formats and time.formats, for a date filter's format (Liquidum::Filters)
|
|
31
|
+
formats:
|
|
32
|
+
date: "Datum, %{name}"
|
|
33
|
+
time: "Tijd, %{name}"
|
|
30
34
|
tags:
|
|
31
35
|
assign: "Zet een variabele"
|
|
32
36
|
attach: "Voegt een bestand toe"
|
data/lib/liquidum/filters.rb
CHANGED
|
@@ -14,8 +14,10 @@ module Liquidum
|
|
|
14
14
|
#
|
|
15
15
|
# An argument's kind says what goes there: a property of the collection's
|
|
16
16
|
# items ("property"), a value a property can have ("value", the property
|
|
17
|
-
# being the argument before), a date format ("format"
|
|
18
|
-
#
|
|
17
|
+
# being the argument before), a date format ("format", strftime's, with the
|
|
18
|
+
# app's date.formats and time.formats as its `values`), a
|
|
19
|
+
# translation's key ("key"), a locale ("locale", with the app's locales as
|
|
20
|
+
# its `values`), or anything ("any"). `keeps` is "collection" (the same items),
|
|
19
21
|
# "item" (one of them) or nil. Labels are liquidum.filters.<name>, in the
|
|
20
22
|
# current locale; a host describes its own filters the same way:
|
|
21
23
|
#
|
|
@@ -38,12 +40,36 @@ module Liquidum
|
|
|
38
40
|
{
|
|
39
41
|
name: name,
|
|
40
42
|
label: I18n.t(name, scope: "liquidum.filters", default: name.humanize),
|
|
41
|
-
arguments: description[:arguments].map { |argument, kind|
|
|
43
|
+
arguments: description[:arguments].map { |argument, kind| argument(argument, kind || :any) },
|
|
42
44
|
keeps: description[:keeps]&.to_s
|
|
43
45
|
}.compact
|
|
44
46
|
end
|
|
45
47
|
end
|
|
46
48
|
|
|
49
|
+
def argument(name, kind)
|
|
50
|
+
values = case kind
|
|
51
|
+
when :locale then I18n.available_locales.map { |locale| {value: locale.to_s, label: locale.to_s} }
|
|
52
|
+
when :format then formats
|
|
53
|
+
end
|
|
54
|
+
{name: name.to_s, kind: kind.to_s, values: values}.compact
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# The app's own date and time formats (date.formats, time.formats in the
|
|
58
|
+
# current locale), strftime's patterns as date and localize take them,
|
|
59
|
+
# each once, labelled with its name
|
|
60
|
+
def formats
|
|
61
|
+
%w[date time].flat_map do |type|
|
|
62
|
+
patterns = I18n.t("#{type}.formats", default: {})
|
|
63
|
+
next [] unless patterns.is_a?(Hash)
|
|
64
|
+
|
|
65
|
+
patterns.filter_map do |format, pattern|
|
|
66
|
+
next unless pattern.is_a?(String)
|
|
67
|
+
|
|
68
|
+
{value: pattern, label: I18n.t(type, scope: "liquidum.formats", name: format, default: "#{type} #{format}")}
|
|
69
|
+
end
|
|
70
|
+
end.uniq { |format| format[:value] }
|
|
71
|
+
end
|
|
72
|
+
|
|
47
73
|
property = [:property, :property]
|
|
48
74
|
value = [:value, :value]
|
|
49
75
|
{
|
|
@@ -71,7 +97,7 @@ module Liquidum
|
|
|
71
97
|
"minus" => [[[:number]]], "times" => [[[:number]]], "divided_by" => [[[:number]]], "modulo" => [[[:number]]],
|
|
72
98
|
"at_least" => [[[:number]]], "at_most" => [[[:number]]],
|
|
73
99
|
# Dates
|
|
74
|
-
"date" => [[[:format, :format]]], "localize" => [[[:locale], [:format, :format]]], "strptime" => [[[:format, :format]]],
|
|
100
|
+
"date" => [[[:format, :format]]], "localize" => [[[:locale, :locale], [:format, :format]]], "strptime" => [[[:format, :format]]],
|
|
75
101
|
"timezone" => [[[:zone]]], "to" => [[[:type]]]
|
|
76
102
|
}.each { |name, (arguments, keeps)| describe(name, arguments: arguments, keeps: keeps) }
|
|
77
103
|
end
|
data/lib/liquidum/version.rb
CHANGED