liquidum 1.4.2 → 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 +14 -1
- data/app/controllers/liquidum/tags_controller.rb +13 -0
- data/config/locales/en.yml +25 -0
- data/config/locales/nl.yml +25 -0
- data/config/routes.rb +1 -0
- data/lib/liquidum/filters.rb +30 -4
- data/lib/liquidum/tags.rb +51 -0
- data/lib/liquidum/version.rb +1 -1
- data/lib/liquidum.rb +1 -0
- metadata +3 -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,9 +97,22 @@ 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>`.
|
|
105
|
+
|
|
106
|
+
And for what can follow `{%`, the tags, each with how it's written and whether
|
|
107
|
+
it's a block, which an editor writes with its closing tag:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
GET /liquidum/tags
|
|
111
|
+
{"tags": [{"name": "if", "label": "Only when a condition holds", "syntax": "if condition", "block": true}, …]}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
An app describes its own with `Liquidum::Tags.describe :signature_field, syntax: "signature_field kind signer"`,
|
|
115
|
+
labelled as `liquidum.tags.<name>`.
|
|
103
116
|
The endpoint only describes variables and never reads a record. Its
|
|
104
117
|
controllers inherit from `::ApplicationController`; to choose another one:
|
|
105
118
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require_dependency "liquidum/application_controller"
|
|
2
|
+
|
|
3
|
+
module Liquidum
|
|
4
|
+
# The tags a template can use, for an editor's completion after {%
|
|
5
|
+
# (Liquidum::Tags), labelled in the request's locale:
|
|
6
|
+
#
|
|
7
|
+
# GET /liquidum/tags → {tags: [{name, label, syntax, block}]}
|
|
8
|
+
class TagsController < ApplicationController
|
|
9
|
+
def index
|
|
10
|
+
render json: {tags: Tags.all}
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/config/locales/en.yml
CHANGED
|
@@ -27,6 +27,31 @@ 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}"
|
|
34
|
+
tags:
|
|
35
|
+
assign: "Sets a variable"
|
|
36
|
+
attach: "Attaches a file"
|
|
37
|
+
break: "Stops the loop"
|
|
38
|
+
capture: "Sets a variable to its text"
|
|
39
|
+
case: "One of several, by a variable's value"
|
|
40
|
+
comment: "Not shown"
|
|
41
|
+
continue: "Goes on with the loop's next item"
|
|
42
|
+
cycle: "Each time the next of its values"
|
|
43
|
+
decrement: "Counts down"
|
|
44
|
+
echo: "Shows a value"
|
|
45
|
+
for: "For each item"
|
|
46
|
+
helper: "A helper's output"
|
|
47
|
+
if: "Only when a condition holds"
|
|
48
|
+
ifchanged: "Only when it changed"
|
|
49
|
+
include: "Another template, sharing variables"
|
|
50
|
+
increment: "Counts up"
|
|
51
|
+
raw: "Liquid shown as it is"
|
|
52
|
+
render: "Another template"
|
|
53
|
+
tablerow: "A table row for each item"
|
|
54
|
+
unless: "Only when a condition doesn't hold"
|
|
30
55
|
filters:
|
|
31
56
|
abs: "Absolute value"
|
|
32
57
|
append: "Text added after it"
|
data/config/locales/nl.yml
CHANGED
|
@@ -27,6 +27,31 @@ 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}"
|
|
34
|
+
tags:
|
|
35
|
+
assign: "Zet een variabele"
|
|
36
|
+
attach: "Voegt een bestand toe"
|
|
37
|
+
break: "Stopt de lus"
|
|
38
|
+
capture: "Zet een variabele op de tekst erin"
|
|
39
|
+
case: "Een van meerdere, naar de waarde van een variabele"
|
|
40
|
+
comment: "Niet getoond"
|
|
41
|
+
continue: "Gaat door met het volgende item"
|
|
42
|
+
cycle: "Telkens de volgende van de waarden"
|
|
43
|
+
decrement: "Telt af"
|
|
44
|
+
echo: "Toont een waarde"
|
|
45
|
+
for: "Voor elk item"
|
|
46
|
+
helper: "De uitvoer van een helper"
|
|
47
|
+
if: "Alleen als een voorwaarde geldt"
|
|
48
|
+
ifchanged: "Alleen als het veranderde"
|
|
49
|
+
include: "Een ander sjabloon, met dezelfde variabelen"
|
|
50
|
+
increment: "Telt op"
|
|
51
|
+
raw: "Liquid getoond zoals het is"
|
|
52
|
+
render: "Een ander sjabloon"
|
|
53
|
+
tablerow: "Een tabelrij voor elk item"
|
|
54
|
+
unless: "Alleen als een voorwaarde niet geldt"
|
|
30
55
|
filters:
|
|
31
56
|
abs: "Absolute waarde"
|
|
32
57
|
append: "Tekst erachter"
|
data/config/routes.rb
CHANGED
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
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Liquidum
|
|
4
|
+
# The tags a template can use, for an editor's completion after {%: those
|
|
5
|
+
# Liquid has registered (its own, Liquidum's and the host's), each with how
|
|
6
|
+
# it's written and whether it's a block, which the editor writes with its
|
|
7
|
+
# closing tag ({% if … %}{% endif %}).
|
|
8
|
+
#
|
|
9
|
+
# Liquidum::Tags.all
|
|
10
|
+
# # => [{name: "if", label: "Only when a condition holds", syntax: "if condition", block: true}, …]
|
|
11
|
+
#
|
|
12
|
+
# The tags inside a block (elsif, else, when) are Liquid's syntax, which the
|
|
13
|
+
# editor knows. Labels are liquidum.tags.<name>, in the current locale; a
|
|
14
|
+
# host describes its own tags the same way:
|
|
15
|
+
#
|
|
16
|
+
# Liquidum::Tags.describe :signature_field, syntax: "signature_field kind signer"
|
|
17
|
+
module Tags
|
|
18
|
+
SYNTAX = {}
|
|
19
|
+
# Not for writing by hand: an inline comment, documentation
|
|
20
|
+
HIDDEN = %w[# doc].freeze
|
|
21
|
+
|
|
22
|
+
module_function
|
|
23
|
+
|
|
24
|
+
def describe(name, syntax:)
|
|
25
|
+
SYNTAX[name.to_s] = syntax
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def all
|
|
29
|
+
Liquid::Environment.default.tags.to_h.filter_map do |name, tag|
|
|
30
|
+
next if HIDDEN.include?(name)
|
|
31
|
+
|
|
32
|
+
tag = tag.safe_constantize if tag.is_a?(String)
|
|
33
|
+
{
|
|
34
|
+
name: name,
|
|
35
|
+
label: I18n.t(name, scope: "liquidum.tags", default: name.humanize),
|
|
36
|
+
syntax: SYNTAX.fetch(name, name),
|
|
37
|
+
block: !!(tag && tag < Liquid::Block)
|
|
38
|
+
}
|
|
39
|
+
end.sort_by { |tag| tag[:name] }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
{
|
|
43
|
+
"assign" => "assign variable = value", "capture" => "capture variable", "case" => "case variable",
|
|
44
|
+
"cycle" => "cycle value, value", "decrement" => "decrement variable", "echo" => "echo value",
|
|
45
|
+
"for" => "for item in collection", "if" => "if condition", "ifchanged" => "ifchanged",
|
|
46
|
+
"include" => "include 'name'", "increment" => "increment variable", "render" => "render 'name'",
|
|
47
|
+
"tablerow" => "tablerow item in collection", "unless" => "unless condition", "attach" => "attach value",
|
|
48
|
+
"helper" => "helper name"
|
|
49
|
+
}.each { |name, syntax| describe(name, syntax: syntax) }
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/liquidum/version.rb
CHANGED
data/lib/liquidum.rb
CHANGED
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.
|
|
4
|
+
version: 1.4.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom de Grunt
|
|
@@ -294,6 +294,7 @@ files:
|
|
|
294
294
|
- app/controllers/liquidum/conversions_controller.rb
|
|
295
295
|
- app/controllers/liquidum/filters_controller.rb
|
|
296
296
|
- app/controllers/liquidum/sandbox_controller.rb
|
|
297
|
+
- app/controllers/liquidum/tags_controller.rb
|
|
297
298
|
- app/controllers/liquidum/variables_controller.rb
|
|
298
299
|
- app/helpers/liquidum/application_helper.rb
|
|
299
300
|
- app/jobs/liquidum/application_job.rb
|
|
@@ -341,6 +342,7 @@ files:
|
|
|
341
342
|
- lib/liquidum/liquid/parser.rb
|
|
342
343
|
- lib/liquidum/liquid/tags/helper_tag.rb
|
|
343
344
|
- lib/liquidum/liquid/tags/render_tag.rb
|
|
345
|
+
- lib/liquidum/tags.rb
|
|
344
346
|
- lib/liquidum/variable.rb
|
|
345
347
|
- lib/liquidum/variables.rb
|
|
346
348
|
- lib/liquidum/version.rb
|