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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96d0ead154fefe58f08b4f87c9981cf141ae8b149a740bb02b30550fca32137c
4
- data.tar.gz: 2bfceaf7029f7a3d9675424197b90e8f54ce14820a0eecda3ef58a3d72c3826a
3
+ metadata.gz: 184a362b7a5a6c5344164fe79127d14f872765546e8c26e80d8d44fd70df4dd5
4
+ data.tar.gz: 5d3cf537732e80265b97ecf0de056d335cae2130e824edf0402dbc747bc4aea6
5
5
  SHA512:
6
- metadata.gz: 199d3b0735522241c505b79e095b257bf5013f417d4daa947ae94490d35dcf4adf5d6c852c1329225c29d8e4dbe29e58a2b5fdd0e4449451cd4397cd307cc521
7
- data.tar.gz: bdd601cb35ccee0d7cba791ddc2b7201399074cbb53e45564f7469442ea158c0f8f9f9cdc1cbc9fc37430a8baa2c643bb70a0c0c624083f4263aa2b6e86f635a
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
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), `key` (a translation's) or `any`. An app describes its own
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
 
@@ -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"
@@ -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"
@@ -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"), a translation's key
18
- # ("key"), or anything ("any"). `keeps` is "collection" (the same items),
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| {name: argument.to_s, kind: (kind || :any).to_s} },
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Liquidum
4
- VERSION = "1.4.3"
4
+ VERSION = "1.4.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquidum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt