liquidum 1.4.1 → 1.4.2

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/.shipkit.yml +1 -1
  3. data/CHANGELOG.md +9 -0
  4. data/Gemfile +8 -0
  5. data/README.md +37 -1
  6. data/app/controllers/liquidum/filters_controller.rb +13 -0
  7. data/app/controllers/liquidum/sandbox_controller.rb +23 -23
  8. data/app/helpers/liquidum/application_helper.rb +1 -1
  9. data/app/models/liquidum/sandbox.rb +19 -1
  10. data/app/views/liquidum/conversions/index.html.slim +5 -5
  11. data/app/views/liquidum/sandbox/edit.html.slim +2 -2
  12. data/app/views/liquidum/sandbox/index.html.slim +2 -2
  13. data/config/locales/en.yml +119 -0
  14. data/config/locales/nl.yml +119 -0
  15. data/config/routes.rb +3 -3
  16. data/db/migrate/20261108090000_change_liquidum_sandboxes_to_text.rb +11 -0
  17. data/lib/liquidum/drop.rb +22 -4
  18. data/lib/liquidum/filters.rb +78 -0
  19. data/lib/liquidum/liquid/filters/array_wrap_filter.rb +1 -1
  20. data/lib/liquidum/liquid/filters/encode_filter.rb +1 -1
  21. data/lib/liquidum/liquid/filters/format_filter.rb +1 -1
  22. data/lib/liquidum/liquid/filters/localize_filter.rb +1 -1
  23. data/lib/liquidum/liquid/filters/max_filter.rb +1 -1
  24. data/lib/liquidum/liquid/filters/min_filter.rb +1 -1
  25. data/lib/liquidum/liquid/filters/strptime_filter.rb +1 -1
  26. data/lib/liquidum/liquid/filters/sum_filter.rb +1 -1
  27. data/lib/liquidum/liquid/filters/timezone_filter.rb +1 -1
  28. data/lib/liquidum/liquid/filters/to_filter.rb +1 -1
  29. data/lib/liquidum/liquid/filters/translate_filter.rb +1 -1
  30. data/lib/liquidum/liquid/filters/unescape_html_filter.rb +1 -1
  31. data/lib/liquidum/liquid/filters/where_exp_filter.rb +1 -1
  32. data/lib/liquidum/liquid/tags/helper_tag.rb +1 -1
  33. data/lib/liquidum/liquid/tags/render_tag.rb +1 -1
  34. data/lib/liquidum/variable.rb +9 -3
  35. data/lib/liquidum/version.rb +1 -1
  36. data/lib/liquidum.rb +1 -0
  37. data/liquidum.gemspec +1 -1
  38. metadata +12 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e037e5f4610a86efae723943b8acb2bebbb0fdd54d5e2df6ee4dcdab75a01f2
4
- data.tar.gz: '068162d42a3eb9863a33a618c860f3031a499bcea95618228af9c3a915716b20'
3
+ metadata.gz: 52abab7d7d88646c34d1fecac8b789517328896337feb0c84fc00fa24401c2f0
4
+ data.tar.gz: 94beabeaf8e34a7d933f19bd23b76dfeafbb36bee75a9bf43714b0a566b9d12b
5
5
  SHA512:
6
- metadata.gz: f26a0722a7631f12ab2aa8b0c796b2020bcf4ba047e87ef9c9f160b623b34585937be7121e894d48cb61d6b37339602cc44db919ec587eddf8870c6d71acdac4
7
- data.tar.gz: fdedeec7a1efa53abe574a11b6c702ea6cc0e572f8361f6e7f647f4b9edc70655bf82e485e31f915701362c118dfe7885df4109dc1ab70d8acd32c4f64882f6a
6
+ metadata.gz: 5f3d23e7d75ecc20aa3efae769b50a578ff873e91f2824deda3b8173a28dbfe7b78638a7431055df61998f981950419f6d6db1f63736fe413527daf3843b187d
7
+ data.tar.gz: e6f5a3d082ae67aea986de3328c1ee61cd92718f33bd6f50f4f9ba20efff251d25ffdc42c7d2f60f3b609b05faa542dc96e6357bcc3c6b10dde5e1db8b093052
data/.shipkit.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  ---
2
- previous_version: 1.4.0
2
+ previous_version: 1.4.1
data/CHANGELOG.md CHANGED
@@ -6,6 +6,15 @@
6
6
  start with a dot, from the Liquid context. Those keys had no scope before.
7
7
  - The `t` filter translates with the app's own translations when
8
8
  `config.i18n_store` isn't set, instead of failing.
9
+ - The sandbox works again: a `liquidum_sandboxes` migration makes the
10
+ template and context `text` (copy it in with
11
+ `bin/rails liquidum:install:migrations`), Render no longer saves, a context
12
+ that isn't a JSON object is an error on the form, and its pages and the
13
+ conversions page are translated (English and Dutch).
14
+ - Routes only for the actions that exist: no `show` or `destroy` for the
15
+ sandbox, only `index` and `create` for conversions, and no `render_only`
16
+ route.
17
+ - The sandbox no longer needs the responders gem.
9
18
 
10
19
  - Allow Liquid 5.4 and later (up to 6).
11
20
  - Drops describe their variables for editors: `Drop.variables`, the
data/Gemfile CHANGED
@@ -9,3 +9,11 @@ gemspec
9
9
  source "https://rubygems.pkg.github.com/entdec" do
10
10
  gem "shipkit"
11
11
  end
12
+
13
+ # The sandbox and conversion pages use Satis, as host apps do (and Satis's
14
+ # tailwindcss-rails an asset pipeline)
15
+ gem "satis"
16
+ gem "propshaft"
17
+ # The sandboxes table is a Mensa table
18
+ git_source(:entdec) { |repo_name| "git@github.com:entdec/#{repo_name}.git" }
19
+ gem "mensa", entdec: "mensa"
data/README.md CHANGED
@@ -57,7 +57,12 @@ OrderDrop.variables # => [#<data Liquidum::Variable name="customer", label="Cust
57
57
  ```
58
58
 
59
59
  `describe` takes `label:`, `type:`, `hint:` (a string, or a proc to translate
60
- it), and `drop:` and `collection:` for a method that returns other drops. A
60
+ it), `drop:` and `collection:` for a method that returns other drops, and
61
+ `values:`, the values a variable can have, by their labels
62
+ (`values: -> { {"account" => "Club", "sponsor" => "Sponsor"} }`), for an editor
63
+ to complete `{% if line.party == "` or `| where: "party", "` with. A model's
64
+ enum has its values already, labelled as
65
+ `activerecord.attributes.<model>.<enum, plural>.<value>`. A
61
66
  drop is for the model with its name (`OrderDrop` is for `Order`); override
62
67
  `self.model` when that's not so.
63
68
 
@@ -81,6 +86,20 @@ GET /liquidum/variables?roots=…&path=order.customer
81
86
  ```
82
87
 
83
88
  In a collection the path goes into its elements (`order.order_lines.product`).
89
+
90
+ And for what can follow a `|`, the filters Liquid has (its own, Liquidum's and
91
+ the app's), each with its arguments and, for one on a collection, what it
92
+ leaves: the same items (`where`, `sort`) or one of them (`first`):
93
+
94
+ ```
95
+ GET /liquidum/filters
96
+ {"filters": [{"name": "where", "label": "Those whose property has the value", "arguments": [{"name": "property", "kind": "property"}, {"name": "value", "kind": "value"}], "keeps": "collection"}, …]}
97
+ ```
98
+
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
101
+ filters with `Liquidum::Filters.describe :money, arguments: [[:currency]]`, and
102
+ labels them as `liquidum.filters.<name>`.
84
103
  The endpoint only describes variables and never reads a record. Its
85
104
  controllers inherit from `::ApplicationController`; to choose another one:
86
105
 
@@ -110,6 +129,23 @@ Or install it yourself as:
110
129
  $ gem install liquidum
111
130
  ```
112
131
 
132
+ Mount the engine for the variables endpoint, the sandbox and the conversions,
133
+ and copy in its migrations for the sandbox:
134
+
135
+ ```ruby
136
+ mount Liquidum::Engine, at: "/liquidum", as: "liquidum"
137
+ ```
138
+
139
+ ```bash
140
+ $ bin/rails liquidum:install:migrations
141
+ $ bin/rails db:migrate
142
+ ```
143
+
144
+ The sandbox (`/liquidum/sandbox`) renders a template with a JSON context, and
145
+ saves the ones worth coming back to. Its pages use Satis. Its controllers
146
+ inherit from `config.parent_controller`, so set that to decide who may use
147
+ them.
148
+
113
149
  ## Contributing
114
150
 
115
151
  Contribution directions go here.
@@ -0,0 +1,13 @@
1
+ require_dependency "liquidum/application_controller"
2
+
3
+ module Liquidum
4
+ # The filters a template can use, for an editor's completion after a |
5
+ # (Liquidum::Filters), labelled in the request's locale:
6
+ #
7
+ # GET /liquidum/filters → {filters: [{name, label, arguments: [{name, kind}], keeps}]}
8
+ class FiltersController < ApplicationController
9
+ def index
10
+ render json: {filters: Filters.all}
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,6 @@
1
- require_dependency "liquidum/application_controller"
2
-
3
1
  module Liquidum
2
+ # Try out Liquid: a template rendered with a JSON context, saved to come
3
+ # back to
4
4
  class SandboxController < ApplicationController
5
5
  before_action :set_objects, except: %i[index]
6
6
 
@@ -12,40 +12,40 @@ module Liquidum
12
12
  end
13
13
 
14
14
  def create
15
- return render_only if params[:render_only] == "commit"
16
-
17
- @sandbox.update(sandbox_attributes)
18
-
19
- respond_with @sandbox,
20
- collection_location: -> { edit_sandbox_path(@sandbox) },
21
- action: :edit
15
+ save
22
16
  end
23
17
 
24
18
  def edit
25
- if @sandbox.valid?
26
- @sandbox.result = Liquidum.render(@sandbox.template, assigns: JSON.parse(@sandbox.context))
27
- end
19
+ render_result
28
20
  end
29
21
 
30
22
  def update
31
- return render_only if params[:render_only] == "commit"
32
-
33
- @sandbox.update(sandbox_attributes)
34
-
35
- respond_with @sandbox,
36
- collection_location: -> { edit_sandbox_path(@sandbox) },
37
- action: :edit
23
+ save
38
24
  end
39
25
 
40
26
  private
41
27
 
42
- def render_only
28
+ # "Render" shows the result without saving, "Save" saves and comes back
29
+ def save
43
30
  @sandbox.assign_attributes(sandbox_attributes)
31
+ return render_edit if params.key?(:render_only)
44
32
 
45
- if @sandbox.valid?
46
- @sandbox.result = Liquidum.render(@sandbox.template, assigns: JSON.parse(@sandbox.context))
33
+ if @sandbox.save
34
+ redirect_to edit_sandbox_path(@sandbox), notice: t("liquidum.sandbox.saved")
35
+ else
36
+ render :edit, status: :unprocessable_entity
47
37
  end
48
- render :edit, status: 302
38
+ end
39
+
40
+ def render_edit
41
+ render_result
42
+ render :edit, status: @sandbox.errors.any? ? :unprocessable_entity : :ok
43
+ end
44
+
45
+ def render_result
46
+ return unless @sandbox.valid?
47
+
48
+ @sandbox.result = Liquidum.render(@sandbox.template, assigns: @sandbox.assigns)
49
49
  end
50
50
 
51
51
  def set_objects
@@ -1,7 +1,7 @@
1
1
  module Liquidum
2
2
  module ApplicationHelper
3
3
  def liquidum_sandboxes_menu
4
- Satis::Menus::Builder.build(:admin_tickets) do |m|
4
+ Satis::Menus::Builder.build(:liquidum_sandboxes) do |m|
5
5
  m.item :create, icon: 'fal fa-plus', link: new_sandbox_path
6
6
  end
7
7
  end
@@ -1,8 +1,26 @@
1
1
  module Liquidum
2
2
  class Sandbox < ApplicationRecord
3
- attribute :result, default: ''
3
+ attribute :result, default: ""
4
4
 
5
5
  validates :context, presence: true
6
6
  validates :template, presence: true
7
+ validate :context_is_a_json_object
8
+
9
+ # The context as the template's variables
10
+ def assigns
11
+ JSON.parse(context.to_s)
12
+ rescue JSON::ParserError
13
+ {}
14
+ end
15
+
16
+ private
17
+
18
+ def context_is_a_json_object
19
+ return if context.blank?
20
+
21
+ errors.add(:context, :not_a_json_object) unless JSON.parse(context).is_a?(Hash)
22
+ rescue JSON::ParserError => e
23
+ errors.add(:context, :invalid_json, message: e.message)
24
+ end
7
25
  end
8
26
  end
@@ -1,12 +1,12 @@
1
1
  = sts.form_for(@conversion, url: conversions_path, data: { turbo: false }) do |f|
2
- = sts.card(title: 'Conversions') do |card|
2
+ = sts.card(:liquidum_conversions, title: t('.title')) do |card|
3
3
  - card.with_action
4
- = f.submit "JSON -> YAML", name: "json_to_yaml"
5
- = f.submit "YAML -> JSON", name: "yaml_to_json"
6
- = f.submit "SLIM -> HTML", name: "slim_to_html"
4
+ = f.submit t('.json_to_yaml'), name: "json_to_yaml"
5
+ = f.submit t('.yaml_to_json'), name: "yaml_to_json"
6
+ = f.submit t('.slim_to_html'), name: "slim_to_html"
7
7
  - card.with_tab :main, padding: true
8
8
  .grid.grid-cols-12.gap-4
9
9
  .col-span-12
10
10
  = f.editor :source, mode: "application/json"
11
11
  .col-span-12
12
- = f.editor :result, mode: "text/plain", read_only: true
12
+ = f.editor :result, mode: "text/plain", read_only: true
@@ -1,7 +1,7 @@
1
1
  = sts.form_for(@sandbox, url: @sandbox.persisted? ? sandbox_path(@sandbox) : sandbox_index_path) do |f|
2
- = sts.card(title: 'Liquid Sandbox') do |card|
2
+ = sts.card(:liquidum_sandbox, title: t('.title'), icon: 'fad fa-toolbox') do |card|
3
3
  - card.with_action
4
- = f.submit "Save", value: 'save'
4
+ = f.submit t('.save'), name: "save"
5
5
  - card.with_action
6
6
  = f.submit t('.render'), name: "render_only"
7
7
  - card.with_tab :main, padding: true
@@ -1,2 +1,2 @@
1
- = sts.card title: t('.sandboxes'), icon: 'fad fa-toolbox', content_padding: false, menu: liquidum_sandboxes_menu do |card|
2
- = sts.table 'liquidum/sandboxes', parameters: { search_placeholder: "Search By Context, Template and Description" }
1
+ = sts.card :liquidum_sandboxes, title: t('.sandboxes'), icon: 'fad fa-toolbox', content_padding: false, menu: liquidum_sandboxes_menu do |card|
2
+ = sts.table 'liquidum/sandboxes', parameters: { search_placeholder: t('.search') }
@@ -0,0 +1,119 @@
1
+ en:
2
+ menu:
3
+ liquidum_sandboxes:
4
+ create: New sandbox
5
+ activemodel:
6
+ attributes:
7
+ liquidum/conversions_controller/conversion:
8
+ source: Source
9
+ result: Result
10
+ activerecord:
11
+ models:
12
+ liquidum/sandbox:
13
+ one: Sandbox
14
+ other: Sandboxes
15
+ attributes:
16
+ liquidum/sandbox:
17
+ context: Context (JSON)
18
+ created_at: Created
19
+ description: Description
20
+ result: Result
21
+ template: Template
22
+ updated_at: Updated
23
+ errors:
24
+ models:
25
+ liquidum/sandbox:
26
+ attributes:
27
+ context:
28
+ not_a_json_object: 'must be a JSON object, like {"name": "value"}'
29
+ liquidum:
30
+ filters:
31
+ abs: "Absolute value"
32
+ append: "Text added after it"
33
+ array_wrap: "As a list"
34
+ at_least: "At least a number"
35
+ at_most: "At most a number"
36
+ base64_decode: "Decoded from Base64"
37
+ base64_encode: "Encoded as Base64"
38
+ base64_url_safe_decode: "Decoded from URL-safe Base64"
39
+ base64_url_safe_encode: "Encoded as URL-safe Base64"
40
+ capitalize: "First letter a capital"
41
+ ceil: "Rounded up"
42
+ compact: "Without empty items"
43
+ concat: "Joined with another list"
44
+ date: "Date in a format"
45
+ default: "Another value when empty"
46
+ divided_by: "Divided by a number"
47
+ downcase: "In lower case"
48
+ encode: "In another encoding"
49
+ escape: "HTML escaped"
50
+ escape_once: "HTML escaped, once"
51
+ find: "The first whose property has the value"
52
+ find_index: "Where the first whose property has the value is"
53
+ first: "The first item"
54
+ floor: "Rounded down"
55
+ format: "In a format"
56
+ h: "HTML escaped"
57
+ has: "Whether one's property has the value"
58
+ join: "Items joined into text"
59
+ last: "The last item"
60
+ localize: "Date in a language and format"
61
+ lstrip: "Without spaces at the start"
62
+ map: "Each item's property"
63
+ max: "The largest"
64
+ min: "The smallest"
65
+ minus: "Minus a number"
66
+ modulo: "Remainder after dividing"
67
+ newline_to_br: "Line breaks as <br>"
68
+ plus: "Plus a number"
69
+ prepend: "Text added before it"
70
+ reject: "Those whose property hasn't the value"
71
+ remove: "Without a text"
72
+ remove_first: "Without a text's first time"
73
+ remove_last: "Without a text's last time"
74
+ replace: "A text replaced"
75
+ replace_first: "A text replaced the first time"
76
+ replace_last: "A text replaced the last time"
77
+ reverse: "In reverse order"
78
+ round: "Rounded"
79
+ rstrip: "Without spaces at the end"
80
+ size: "Number of items or characters"
81
+ slice: "A part of it"
82
+ sort: "Sorted"
83
+ sort_natural: "Sorted, ignoring case"
84
+ split: "Text split into a list"
85
+ squish: "Spaces collapsed"
86
+ strip: "Without spaces around it"
87
+ strip_html: "Without HTML"
88
+ strip_newlines: "Without line breaks"
89
+ strptime: "Date read from text"
90
+ sum: "Sum of the items"
91
+ t: "Translated"
92
+ times: "Times a number"
93
+ timezone: "In a time zone"
94
+ to: "As JSON, YAML or a date"
95
+ translate: "Translated"
96
+ truncate: "Cut to a length"
97
+ truncatewords: "Cut to a number of words"
98
+ unescape_html: "HTML unescaped"
99
+ uniq: "Without duplicates"
100
+ upcase: "In capitals"
101
+ url_decode: "Decoded from a URL"
102
+ url_encode: "Encoded for a URL"
103
+ where: "Those whose property has the value"
104
+ where_exp: "Those for which a condition holds"
105
+ sandbox:
106
+ saved: The sandbox has been saved
107
+ index:
108
+ sandboxes: Liquid sandboxes
109
+ search: Search by description or template
110
+ edit:
111
+ title: Liquid sandbox
112
+ save: Save
113
+ render: Render
114
+ conversions:
115
+ index:
116
+ title: Conversions
117
+ json_to_yaml: JSON → YAML
118
+ yaml_to_json: YAML → JSON
119
+ slim_to_html: Slim → HTML
@@ -0,0 +1,119 @@
1
+ nl:
2
+ menu:
3
+ liquidum_sandboxes:
4
+ create: Nieuwe zandbak
5
+ activemodel:
6
+ attributes:
7
+ liquidum/conversions_controller/conversion:
8
+ source: Bron
9
+ result: Resultaat
10
+ activerecord:
11
+ models:
12
+ liquidum/sandbox:
13
+ one: Zandbak
14
+ other: Zandbakken
15
+ attributes:
16
+ liquidum/sandbox:
17
+ context: Context (JSON)
18
+ created_at: Aangemaakt
19
+ description: Omschrijving
20
+ result: Resultaat
21
+ template: Sjabloon
22
+ updated_at: Gewijzigd
23
+ errors:
24
+ models:
25
+ liquidum/sandbox:
26
+ attributes:
27
+ context:
28
+ not_a_json_object: 'moet een JSON-object zijn, zoals {"naam": "waarde"}'
29
+ liquidum:
30
+ filters:
31
+ abs: "Absolute waarde"
32
+ append: "Tekst erachter"
33
+ array_wrap: "Als lijst"
34
+ at_least: "Minstens een getal"
35
+ at_most: "Hoogstens een getal"
36
+ base64_decode: "Gedecodeerd uit Base64"
37
+ base64_encode: "Gecodeerd als Base64"
38
+ base64_url_safe_decode: "Gedecodeerd uit URL-veilig Base64"
39
+ base64_url_safe_encode: "Gecodeerd als URL-veilig Base64"
40
+ capitalize: "Eerste letter een hoofdletter"
41
+ ceil: "Naar boven afgerond"
42
+ compact: "Zonder lege items"
43
+ concat: "Samengevoegd met een andere lijst"
44
+ date: "Datum in een formaat"
45
+ default: "Andere waarde als het leeg is"
46
+ divided_by: "Gedeeld door een getal"
47
+ downcase: "In kleine letters"
48
+ encode: "In een andere codering"
49
+ escape: "HTML-veilig gemaakt"
50
+ escape_once: "Eenmaal HTML-veilig gemaakt"
51
+ find: "De eerste waarvan de eigenschap de waarde heeft"
52
+ find_index: "Plaats van de eerste waarvan de eigenschap de waarde heeft"
53
+ first: "Het eerste item"
54
+ floor: "Naar beneden afgerond"
55
+ format: "In een formaat"
56
+ h: "HTML-veilig gemaakt"
57
+ has: "Of er een is waarvan de eigenschap de waarde heeft"
58
+ join: "Items samengevoegd tot tekst"
59
+ last: "Het laatste item"
60
+ localize: "Datum in een taal en formaat"
61
+ lstrip: "Zonder spaties aan het begin"
62
+ map: "De eigenschap van elk item"
63
+ max: "De grootste"
64
+ min: "De kleinste"
65
+ minus: "Min een getal"
66
+ modulo: "Rest na delen"
67
+ newline_to_br: "Regeleinden als <br>"
68
+ plus: "Plus een getal"
69
+ prepend: "Tekst ervoor"
70
+ reject: "Die waarvan de eigenschap de waarde niet heeft"
71
+ remove: "Zonder een tekst"
72
+ remove_first: "Zonder de eerste keer van een tekst"
73
+ remove_last: "Zonder de laatste keer van een tekst"
74
+ replace: "Een tekst vervangen"
75
+ replace_first: "Een tekst de eerste keer vervangen"
76
+ replace_last: "Een tekst de laatste keer vervangen"
77
+ reverse: "In omgekeerde volgorde"
78
+ round: "Afgerond"
79
+ rstrip: "Zonder spaties aan het eind"
80
+ size: "Aantal items of tekens"
81
+ slice: "Een deel ervan"
82
+ sort: "Gesorteerd"
83
+ sort_natural: "Gesorteerd, hoofdletters genegeerd"
84
+ split: "Tekst gesplitst tot een lijst"
85
+ squish: "Spaties samengevoegd"
86
+ strip: "Zonder spaties eromheen"
87
+ strip_html: "Zonder HTML"
88
+ strip_newlines: "Zonder regeleinden"
89
+ strptime: "Datum gelezen uit tekst"
90
+ sum: "Som van de items"
91
+ t: "Vertaald"
92
+ times: "Maal een getal"
93
+ timezone: "In een tijdzone"
94
+ to: "Als JSON, YAML of datum"
95
+ translate: "Vertaald"
96
+ truncate: "Ingekort tot een lengte"
97
+ truncatewords: "Ingekort tot een aantal woorden"
98
+ unescape_html: "HTML-tekens hersteld"
99
+ uniq: "Zonder dubbele"
100
+ upcase: "In hoofdletters"
101
+ url_decode: "Gedecodeerd uit een URL"
102
+ url_encode: "Gecodeerd voor een URL"
103
+ where: "Die waarvan de eigenschap de waarde heeft"
104
+ where_exp: "Die waarvoor een voorwaarde geldt"
105
+ sandbox:
106
+ saved: De zandbak is opgeslagen
107
+ index:
108
+ sandboxes: Liquid-zandbakken
109
+ search: Zoek op omschrijving of sjabloon
110
+ edit:
111
+ title: Liquid-zandbak
112
+ save: Opslaan
113
+ render: Renderen
114
+ conversions:
115
+ index:
116
+ title: Conversies
117
+ json_to_yaml: JSON → YAML
118
+ yaml_to_json: YAML → JSON
119
+ slim_to_html: Slim → HTML
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  Liquidum::Engine.routes.draw do
2
2
  resources :variables, only: :index
3
- resources :conversions
4
- resources :sandbox
5
- post 'render_only', to: 'sandbox#render_only'
3
+ resources :filters, only: :index
4
+ resources :conversions, only: %i[index create]
5
+ resources :sandbox, except: %i[show destroy]
6
6
  end
@@ -0,0 +1,11 @@
1
+ class ChangeLiquidumSandboxesToText < ActiveRecord::Migration[7.0]
2
+ def up
3
+ change_column :liquidum_sandboxes, :context, :text
4
+ change_column :liquidum_sandboxes, :template, :text
5
+ end
6
+
7
+ def down
8
+ change_column :liquidum_sandboxes, :context, :string
9
+ change_column :liquidum_sandboxes, :template, :string
10
+ end
11
+ end
data/lib/liquidum/drop.rb CHANGED
@@ -74,10 +74,13 @@ module Liquidum
74
74
  # describe :portal_url, label: -> { I18n.t("orders.portal_url") }
75
75
  # describe :owner, drop: "UserDrop"
76
76
  # describe :tags, drop: "TagDrop", collection: true
77
+ # describe :party, values: -> { {"account" => I18n.t("…"), "sponsor" => I18n.t("…")} }
77
78
  #
78
- # A label or hint can be a proc, to translate it in the current locale.
79
- def describe(name, label: nil, type: nil, hint: nil, drop: nil, collection: nil)
80
- descriptions[name.to_s] = {label: label, type: type, hint: hint, drop: drop, collection: collection}.compact
79
+ # A label, hint or values can be a proc, to translate them in the current
80
+ # locale. Values are the values the variable can have, by their labels
81
+ # (or a list of them); an enum of the model has its own already.
82
+ def describe(name, label: nil, type: nil, hint: nil, drop: nil, collection: nil, values: nil)
83
+ descriptions[name.to_s] = {label: label, type: type, hint: hint, drop: drop, collection: collection, values: values}.compact
81
84
  end
82
85
 
83
86
  def descriptions
@@ -122,10 +125,25 @@ module Liquidum
122
125
  type: (description[:type] || (drop ? :object : attribute_type(name)))&.to_s,
123
126
  hint: resolve(description[:hint]),
124
127
  drop: drop,
125
- collection: description.fetch(:collection) { relation&.collection? || false }
128
+ collection: description.fetch(:collection) { relation&.collection? || false },
129
+ values: values_for(name, description[:values])
126
130
  )
127
131
  end
128
132
 
133
+ # [{value, label}]: as described, else the model's enum's values, each
134
+ # labelled as activerecord.attributes.<model>.<enum, plural>.<value>
135
+ def values_for(name, described)
136
+ values = resolve(described)
137
+ if values.nil? && model.respond_to?(:defined_enums) && model.defined_enums.key?(name)
138
+ scope = "activerecord.attributes.#{model.model_name.i18n_key}.#{name.pluralize}"
139
+ values = model.defined_enums[name].keys.to_h { |value| [value, I18n.t(value, scope: scope, default: value.humanize)] }
140
+ end
141
+ case values
142
+ when Hash then values.map { |value, label| {value: value.to_s, label: label.to_s} }
143
+ when Array then values.map { |value| {value: value.to_s, label: value.to_s.humanize} }
144
+ end
145
+ end
146
+
129
147
  def label_for(name)
130
148
  model.respond_to?(:human_attribute_name) ? model.human_attribute_name(name) : name.humanize
131
149
  end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Liquidum
4
+ # The filters a template can use, for an editor's completion after a |:
5
+ # those Liquid has registered (its own, Liquidum's and the host's), each
6
+ # with what it's for and its arguments, and what a filter on a collection
7
+ # leaves (`keeps`), so an editor knows `lines | where: "party", "sponsor"`
8
+ # is still a collection of lines.
9
+ #
10
+ # Liquidum::Filters.all
11
+ # # => [{name: "where", label: "Those whose property has the value",
12
+ # # arguments: [{name: "property", kind: "property"}, {name: "value", kind: "value"}],
13
+ # # keeps: "collection"}, …]
14
+ #
15
+ # An argument's kind says what goes there: a property of the collection's
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),
19
+ # "item" (one of them) or nil. Labels are liquidum.filters.<name>, in the
20
+ # current locale; a host describes its own filters the same way:
21
+ #
22
+ # Liquidum::Filters.describe :money, arguments: [], keeps: nil
23
+ #
24
+ # and labels them in its locale files.
25
+ module Filters
26
+ DESCRIPTIONS = {}
27
+
28
+ module_function
29
+
30
+ def describe(name, arguments: [], keeps: nil)
31
+ DESCRIPTIONS[name.to_s] = {arguments: arguments.map { |argument| Array(argument) }, keeps: keeps}
32
+ end
33
+
34
+ def all
35
+ names = Liquid::Environment.default.strainer_template.filter_method_names.map(&:to_s).sort
36
+ names.map do |name|
37
+ description = DESCRIPTIONS.fetch(name, {arguments: [], keeps: nil})
38
+ {
39
+ name: name,
40
+ 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} },
42
+ keeps: description[:keeps]&.to_s
43
+ }.compact
44
+ end
45
+ end
46
+
47
+ property = [:property, :property]
48
+ value = [:value, :value]
49
+ {
50
+ # On collections
51
+ "compact" => [[], :collection], "concat" => [[[:items]], :collection], "first" => [[], :item], "last" => [[], :item],
52
+ "join" => [[[:separator]]], "map" => [[property]], "reverse" => [[], :collection], "size" => [[]],
53
+ "sort" => [[property], :collection], "sort_natural" => [[property], :collection], "uniq" => [[], :collection],
54
+ "where" => [[property, value], :collection], "reject" => [[property, value], :collection],
55
+ "where_exp" => [[[:item], [:condition]], :collection], "find" => [[property, value], :item],
56
+ "find_index" => [[property, value]], "has" => [[property, value]], "sum" => [[]], "min" => [[]], "max" => [[]],
57
+ "array_wrap" => [[], :collection],
58
+ # Text
59
+ "append" => [[[:text]]], "prepend" => [[[:text]]], "capitalize" => [[]], "downcase" => [[]], "upcase" => [[]],
60
+ "default" => [[[:value]]], "escape" => [[]], "escape_once" => [[]], "h" => [[]], "strip" => [[]], "lstrip" => [[]],
61
+ "rstrip" => [[]], "squish" => [[]], "strip_html" => [[]], "strip_newlines" => [[]], "newline_to_br" => [[]],
62
+ "remove" => [[[:text]]], "remove_first" => [[[:text]]], "remove_last" => [[[:text]]],
63
+ "replace" => [[[:text], [:replacement]]], "replace_first" => [[[:text], [:replacement]]], "replace_last" => [[[:text], [:replacement]]],
64
+ "slice" => [[[:start], [:length]]], "split" => [[[:separator]]], "truncate" => [[[:length], [:ellipsis]]],
65
+ "truncatewords" => [[[:words], [:ellipsis]]], "url_encode" => [[]], "url_decode" => [[]], "base64_encode" => [[]],
66
+ "base64_decode" => [[]], "base64_url_safe_encode" => [[]], "base64_url_safe_decode" => [[]],
67
+ "unescape_html" => [[]], "encode" => [[[:encoding]]], "format" => [[[:format]]],
68
+ "t" => [[[:key, :key]]], "translate" => [[[:key, :key]]],
69
+ # Numbers
70
+ "abs" => [[]], "ceil" => [[]], "floor" => [[]], "round" => [[[:decimals]]], "plus" => [[[:number]]],
71
+ "minus" => [[[:number]]], "times" => [[[:number]]], "divided_by" => [[[:number]]], "modulo" => [[[:number]]],
72
+ "at_least" => [[[:number]]], "at_most" => [[[:number]]],
73
+ # Dates
74
+ "date" => [[[:format, :format]]], "localize" => [[[:locale], [:format, :format]]], "strptime" => [[[:format, :format]]],
75
+ "timezone" => [[[:zone]]], "to" => [[[:type]]]
76
+ }.each { |name, (arguments, keeps)| describe(name, arguments: arguments, keeps: keeps) }
77
+ end
78
+ end
@@ -11,4 +11,4 @@ module ArrayWrapFilter
11
11
  end
12
12
  end
13
13
 
14
- Liquid::Template.register_filter(ArrayWrapFilter)
14
+ Liquid::Environment.default.register_filter(ArrayWrapFilter)
@@ -11,4 +11,4 @@ module EncodeFilter
11
11
  end
12
12
  end
13
13
 
14
- Liquid::Template.register_filter(EncodeFilter)
14
+ Liquid::Environment.default.register_filter(EncodeFilter)
@@ -11,4 +11,4 @@ module FormatFilter
11
11
  end
12
12
  end
13
13
 
14
- Liquid::Template.register_filter(FormatFilter)
14
+ Liquid::Environment.default.register_filter(FormatFilter)
@@ -12,4 +12,4 @@ module LocalizeFilter
12
12
  end
13
13
  end
14
14
 
15
- Liquid::Template.register_filter(LocalizeFilter)
15
+ Liquid::Environment.default.register_filter(LocalizeFilter)
@@ -13,4 +13,4 @@ module MaxFilter
13
13
  input.max
14
14
  end
15
15
  end
16
- Liquid::Template.register_filter(MaxFilter)
16
+ Liquid::Environment.default.register_filter(MaxFilter)
@@ -13,4 +13,4 @@ module MinFilter
13
13
  input.min
14
14
  end
15
15
  end
16
- Liquid::Template.register_filter(MinFilter)
16
+ Liquid::Environment.default.register_filter(MinFilter)
@@ -11,4 +11,4 @@ module StrptimeFilter
11
11
  end
12
12
  end
13
13
 
14
- Liquid::Template.register_filter(StrptimeFilter)
14
+ Liquid::Environment.default.register_filter(StrptimeFilter)
@@ -13,4 +13,4 @@ module SumFilter
13
13
  input.sum
14
14
  end
15
15
  end
16
- Liquid::Template.register_filter(SumFilter)
16
+ Liquid::Environment.default.register_filter(SumFilter)
@@ -15,4 +15,4 @@ module TimezoneFilter
15
15
  end
16
16
  end
17
17
 
18
- Liquid::Template.register_filter(TimezoneFilter)
18
+ Liquid::Environment.default.register_filter(TimezoneFilter)
@@ -43,4 +43,4 @@ module ToFilter
43
43
  end
44
44
  end
45
45
 
46
- Liquid::Template.register_filter(ToFilter)
46
+ Liquid::Environment.default.register_filter(ToFilter)
@@ -47,4 +47,4 @@ module TranslateFilter
47
47
  alias_method :t, :translate
48
48
  end
49
49
 
50
- Liquid::Template.register_filter(TranslateFilter)
50
+ Liquid::Environment.default.register_filter(TranslateFilter)
@@ -12,4 +12,4 @@ module UnescapeHTMLFilter
12
12
  end
13
13
  end
14
14
 
15
- Liquid::Template.register_filter(UnescapeHTMLFilter)
15
+ Liquid::Environment.default.register_filter(UnescapeHTMLFilter)
@@ -67,4 +67,4 @@ module WhereExpFilter
67
67
 
68
68
  end
69
69
 
70
- Liquid::Template.register_filter(WhereExpFilter)
70
+ Liquid::Environment.default.register_filter(WhereExpFilter)
@@ -27,4 +27,4 @@ class HelperTag < LiquidumTag
27
27
  end
28
28
  end
29
29
 
30
- Liquid::Template.register_tag('helper', HelperTag)
30
+ Liquid::Environment.default.register_tag('helper', HelperTag)
@@ -16,4 +16,4 @@ class RenderTag < LiquidumTag
16
16
  end
17
17
  end
18
18
 
19
- Liquid::Template.register_tag('render', RenderTag)
19
+ Liquid::Environment.default.register_tag('render', RenderTag)
@@ -3,10 +3,16 @@
3
3
  module Liquidum
4
4
  # A variable a template can use, as the editor's variable picker shows it.
5
5
  # A variable with a drop has variables of its own; a collection is a list
6
- # of them, to loop over.
7
- Variable = Data.define(:name, :label, :type, :hint, :drop, :collection) do
6
+ # of them, to loop over. A variable with values has those only, each
7
+ # [{value, label}], for the editor to complete a comparison with it or a
8
+ # where filter on it ({% if line.party == "sponsor" %}).
9
+ Variable = Data.define(:name, :label, :type, :hint, :drop, :collection, :values) do
10
+ def initialize(values: nil, **attributes)
11
+ super
12
+ end
13
+
8
14
  def as_json(*)
9
- {name: name, label: label, type: type, hint: hint, collection: collection, children: !drop.nil?}.compact
15
+ {name: name, label: label, type: type, hint: hint, collection: collection, children: !drop.nil?, values: values}.compact
10
16
  end
11
17
  end
12
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Liquidum
4
- VERSION = "1.4.1"
4
+ VERSION = "1.4.2"
5
5
  end
data/lib/liquidum.rb CHANGED
@@ -11,6 +11,7 @@ require "liquidum/configuration"
11
11
  require "liquidum/drop"
12
12
  require "liquidum/variable"
13
13
  require "liquidum/variables"
14
+ require "liquidum/filters"
14
15
 
15
16
  require "liquidum/liquid/liquid_helpers"
16
17
  require "liquidum/liquid/liquid_template_extensions"
data/liquidum.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_runtime_dependency("i18n", ["~> 1.8"])
29
29
  spec.add_runtime_dependency("kramdown", ["~> 2.1"])
30
30
  spec.add_runtime_dependency("kramdown-parser-gfm", ["~> 1.0"])
31
- spec.add_runtime_dependency("liquid", ["< 6"])
31
+ spec.add_runtime_dependency("liquid", [">= 5.5", "< 6"])
32
32
  spec.add_runtime_dependency("parslet", [">= 0"])
33
33
  spec.add_runtime_dependency("pg", [">= 0"])
34
34
  spec.add_runtime_dependency("rails", [">= 5.2"])
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.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt
@@ -83,6 +83,9 @@ dependencies:
83
83
  name: liquid
84
84
  requirement: !ruby/object:Gem::Requirement
85
85
  requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '5.5'
86
89
  - - "<"
87
90
  - !ruby/object:Gem::Version
88
91
  version: '6'
@@ -90,6 +93,9 @@ dependencies:
90
93
  prerelease: false
91
94
  version_requirements: !ruby/object:Gem::Requirement
92
95
  requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '5.5'
93
99
  - - "<"
94
100
  - !ruby/object:Gem::Version
95
101
  version: '6'
@@ -286,6 +292,7 @@ files:
286
292
  - TODO.md
287
293
  - app/controllers/liquidum/application_controller.rb
288
294
  - app/controllers/liquidum/conversions_controller.rb
295
+ - app/controllers/liquidum/filters_controller.rb
289
296
  - app/controllers/liquidum/sandbox_controller.rb
290
297
  - app/controllers/liquidum/variables_controller.rb
291
298
  - app/helpers/liquidum/application_helper.rb
@@ -300,12 +307,16 @@ files:
300
307
  - bin/de
301
308
  - bin/rails
302
309
  - bin/rubocop
310
+ - config/locales/en.yml
311
+ - config/locales/nl.yml
303
312
  - config/routes.rb
304
313
  - db/migrate/20230202121357_create_liquidum_sandboxes.rb
314
+ - db/migrate/20261108090000_change_liquidum_sandboxes_to_text.rb
305
315
  - lib/liquidum.rb
306
316
  - lib/liquidum/configuration.rb
307
317
  - lib/liquidum/drop.rb
308
318
  - lib/liquidum/engine.rb
319
+ - lib/liquidum/filters.rb
309
320
  - lib/liquidum/liquid/drops/active_storage_attached_many_drop.rb
310
321
  - lib/liquidum/liquid/drops/active_storage_attached_one_drop.rb
311
322
  - lib/liquidum/liquid/drops/active_storage_attachment_drop.rb