tess_edit 0.5.13 → 0.5.14
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/README.md +2 -2
- data/app/javascript/tess_edit/core/liquid.js +11 -6
- data/app/javascript/tess_edit/core/variables.js +8 -1
- data/app/javascript/tess_edit/ui/variable_menu.js +22 -4
- data/config/locales/en.yml +1 -0
- data/config/locales/nl.yml +1 -0
- data/lib/tess_edit/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: 97bb49e864a1f6b6a2160a031885aa9243b3777539ebc2ee8539514790607a5e
|
|
4
|
+
data.tar.gz: db45bf62fb64f47d1ad1232fa0b92c524946d2f286112749a09495965a49381a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: daedafe40b1d4e09904ac960a3a62305fc6155606ba487483137a70ff0ee37e53d9085f0ce04f28f587951d28e0a43c9e61edd4ec70a64513f8fa093bfb86171
|
|
7
|
+
data.tar.gz: 3575c9541577ec1915579308e6a46e85ae6d5935130dc6bc53b9c6a0651cb022ae0016c8929ab7778b7f34e5b572d4e75f150c8e700aa6a45a10beb394460a2e
|
data/README.md
CHANGED
|
@@ -253,7 +253,7 @@ The endpoint answers `GET` with the variables at `path` (the roots without one),
|
|
|
253
253
|
|
|
254
254
|
`children` says a variable has variables of its own, at the path with its name added; a `collection` is a list of them, and its path goes into its elements (`order.order_lines.product`). The editor offers a collection's `first`, `last` and `size`, and inside a Loop block (`{% for line in order.order_lines %}`) its variable, `line`, asking for `order.order_lines.…` for it. An unknown path answers 404. [Liquidum](https://github.com/entdec/liquidum)'s `/liquidum/variables` answers this way from your drops; the dummy app's `VariablesController` is a fixed example (`/?variables=1`).
|
|
255
255
|
|
|
256
|
-
An Assign block before a block (in its container, or in one around it), and `{% assign %}` or an open `{% for %}` earlier in the same text, are variables there too. An Assign's variable is what its expression comes to: `{% assign lines = order.order_lines | where: "kind", "product" %}` is still order lines, through filters that keep a collection (`where`, `sort`, `reverse`, …), and `| first` makes it one of them, so `{% for line in lines %}` completes `line.` as a line.
|
|
256
|
+
An Assign block before a block (in its container, or in one around it), and `{% assign %}`, an ended `{% capture %}` (a text) or an open `{% for %}` earlier in the same text, are variables there too. An Assign's variable is what its expression comes to: `{% assign lines = order.order_lines | where: "kind", "product" %}` is still order lines, through filters that keep a collection (`where`, `sort`, `reverse`, …), and `| first` makes it one of them, so `{% for line in lines %}` completes `line.` as a line.
|
|
257
257
|
|
|
258
258
|
A variable with `values` (`"values": [{"value": "shipping", "label": "Shipping"}]`) can only be those: after `line.kind == `, `!=`, `<>` or `contains`, and after `{% when ` in a `{% case line.kind %}`, the editor suggests them, quoted, with `blank` and `empty`. Inside a Loop, or an open `{% for %}`, `forloop` is a variable too, with its `index`, `first`, `last` and the rest.
|
|
259
259
|
|
|
@@ -265,7 +265,7 @@ With `data-tess-edit-filters-url-value` the editor also completes filters: after
|
|
|
265
265
|
{"filters": [{"name": "where", "label": "Those whose property has the value", "arguments": [{"name": "property", "kind": "property"}, {"name": "value", "kind": "value"}], "keeps": "collection"}]}
|
|
266
266
|
```
|
|
267
267
|
|
|
268
|
-
An argument's `kind` is `property`, `value` (one the property before it can have), `format` (a date's: the editor suggests strftime formats, each with today in it) or anything else, where the editor suggests variables. `keeps` says what a filter on a collection leaves: the same items (`"collection"`) or one of them (`"item"`); without the endpoint Liquid's own are known. Liquidum's `/liquidum/filters` answers this way, with your app's filters as well; the dummy app's `VariablesController#filters` is an example.
|
|
268
|
+
An argument's `kind` is `property`, `value` (one the property before it can have), `format` (a date's: the editor suggests strftime formats, the host's `values` first, as Liquidum gives your app's `date.formats` and `time.formats`, then common ones, each with today in it, in the language a `locale` argument before it names) or anything else, where the editor suggests variables; an argument with `values` (`[{"value": "nl", "label": "nl"}]`, as Liquidum gives `localize`'s locales) gets those, quoted. `keeps` says what a filter on a collection leaves: the same items (`"collection"`) or one of them (`"item"`); without the endpoint Liquid's own are known. Liquidum's `/liquidum/filters` answers this way, with your app's filters as well; the dummy app's `VariablesController#filters` is an example.
|
|
269
269
|
|
|
270
270
|
With `data-tess-edit-tags-url-value` the editor completes tags after `{%`: first what goes in the block it's in (`elsif`, `else`, `when`, `endif`), then the tags, each with its label. Choosing a block writes its end tag too, with the caret where its arguments go: `{% if | %}{% endif %}`. The endpoint answers `GET` with:
|
|
271
271
|
|
|
@@ -210,19 +210,24 @@ export function liquidScope(doc, id) {
|
|
|
210
210
|
return scope
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
// The assigns ({% assign x = … %})
|
|
214
|
-
//
|
|
213
|
+
// The assigns ({% assign x = … %}), captures ({% capture x %}…{% endcapture %},
|
|
214
|
+
// once ended) and loops ({% for x in … %}, while open) earlier in a text,
|
|
215
|
+
// before the caret, nearest first, as liquidScope gives them
|
|
216
|
+
// [{ variable, captured: true }] a capture's: a text
|
|
215
217
|
export function textScope(before) {
|
|
216
|
-
const
|
|
218
|
+
const found = []
|
|
217
219
|
for (const match of before.matchAll(/\{%-?\s*(assign|for)\s+(\w+)\s*(=|in)\s*([\s\S]*?)\s*-?%\}/g)) {
|
|
218
|
-
if (match[1] === "assign" && match[3] === "=")
|
|
220
|
+
if (match[1] === "assign" && match[3] === "=") found.push([match.index, { variable: match[2], expression: match[4] }])
|
|
219
221
|
if (match[1] === "for" && match[3] === "in") {
|
|
220
222
|
// Only while the loop is open
|
|
221
223
|
const after = before.slice(match.index + match[0].length)
|
|
222
|
-
if (!/\{%-?\s*endfor\b/.test(after))
|
|
224
|
+
if (!/\{%-?\s*endfor\b/.test(after)) found.push([match.index, { variable: match[2], collection: match[4].split(/\s/)[0] }])
|
|
223
225
|
}
|
|
224
226
|
}
|
|
225
|
-
|
|
227
|
+
for (const match of before.matchAll(/\{%-?\s*capture\s+(["']?)(\w+)\1\s*-?%\}[\s\S]*?\{%-?\s*endcapture\s*-?%\}/g)) {
|
|
228
|
+
found.push([match.index, { variable: match[2], captured: true }])
|
|
229
|
+
}
|
|
230
|
+
return found.sort((a, b) => b[0] - a[0]).map(([, entry]) => entry)
|
|
226
231
|
}
|
|
227
232
|
|
|
228
233
|
// What replaces a quoted argument or value, in the quote it was started
|
|
@@ -148,7 +148,8 @@ export class Variables {
|
|
|
148
148
|
if (own.some((variable) => variable.name === entry.variable)) continue
|
|
149
149
|
// What it stands for, of the scope around it
|
|
150
150
|
const target = entry.path && (await this.variable(entry.path.split("."), scope.slice(index + 1)))
|
|
151
|
-
|
|
151
|
+
if (entry.captured) own.push(capturedVariable(entry))
|
|
152
|
+
else own.push(entry.path ? { ...(target || { children: false }), name: entry.variable, label: t("Assigned %{path}", { path: entry.path }), assign: true } : loopVariable(entry))
|
|
152
153
|
}
|
|
153
154
|
if (scope.some((entry) => entry.collection)) own.push(FORLOOP)
|
|
154
155
|
return [...own, ...(await this.at(""))]
|
|
@@ -175,6 +176,7 @@ export class Variables {
|
|
|
175
176
|
const own = scope.find((entry) => entry.variable === last)
|
|
176
177
|
if (last === "forloop" && !own && scope.some((entry) => entry.collection)) return FORLOOP
|
|
177
178
|
if (own?.path) return { ...(await this.variable(own.path.split("."), scope.slice(scope.indexOf(own) + 1))), name: last }
|
|
179
|
+
if (own?.captured) return capturedVariable(own)
|
|
178
180
|
if (own) return loopVariable(own)
|
|
179
181
|
} else if (ELEMENT.has(last)) {
|
|
180
182
|
const collection = await this.variable(parent, scope)
|
|
@@ -187,6 +189,11 @@ export class Variables {
|
|
|
187
189
|
|
|
188
190
|
const FORLOOP = { name: "forloop", label: "This loop", type: "object", children: true, forloop: true }
|
|
189
191
|
|
|
192
|
+
// A {% capture %}'s variable: the text between it and its endcapture
|
|
193
|
+
function capturedVariable({ variable }) {
|
|
194
|
+
return { name: variable, label: t("Captured text"), type: "string", children: false, captured: true }
|
|
195
|
+
}
|
|
196
|
+
|
|
190
197
|
function loopVariable({ variable, collection }) {
|
|
191
198
|
return { name: variable, label: t("Each of %{collection}", { collection }), type: "object", children: true, loop: true }
|
|
192
199
|
}
|
|
@@ -96,12 +96,23 @@ export class VariableMenu {
|
|
|
96
96
|
}
|
|
97
97
|
if (context.kind === "argument") {
|
|
98
98
|
const filter = (await variables.filters()).get(context.filter)
|
|
99
|
-
const
|
|
99
|
+
const argument = filter?.arguments?.[context.index]
|
|
100
|
+
const kind = argument?.kind
|
|
100
101
|
const more = filter?.arguments?.length > context.index + 1
|
|
101
102
|
if (kind === "format") {
|
|
102
|
-
|
|
103
|
+
// In the locale an argument before it names: localize: 'nl', '%B'
|
|
104
|
+
const locale = filter.arguments.slice(0, context.index).map((before, index) => before.kind === "locale" && context.args[index]).find((value) => /^[a-z]{2}(?:-[A-Za-z]{2})?$/.test(value || ""))
|
|
105
|
+
const example = (format) => strftime(new Date(), format, locale || undefined)
|
|
106
|
+
// The host's own formats first (date.formats, time.formats), then the common ones
|
|
107
|
+
const own = (argument.values || []).map((format) => ({ value: format.value, label: `${format.label} · ${example(format.value)}` }))
|
|
108
|
+
const common = DATE_FORMATS.filter((format) => !own.some((mine) => mine.value === format)).map((format) => ({ value: format, label: example(format) }))
|
|
109
|
+
const formats = [...own, ...common]
|
|
103
110
|
return this.quotedOptions({ ...context, quote: context.quote || "'" }, formats, more)
|
|
104
111
|
}
|
|
112
|
+
// Those the host gives, such as its locales
|
|
113
|
+
if (argument?.values && !(context.partial && !context.quote && context.partial.includes("."))) {
|
|
114
|
+
return this.quotedOptions({ ...context, quote: context.quote || "'" }, argument.values, more)
|
|
115
|
+
}
|
|
105
116
|
if (kind === "property" || kind === "value") {
|
|
106
117
|
const elements = await this.elements(context.input, scope)
|
|
107
118
|
if (!elements) return null
|
|
@@ -430,7 +441,11 @@ const INSIDE = {
|
|
|
430
441
|
}
|
|
431
442
|
|
|
432
443
|
// A date's formats, as Ruby's strftime writes them
|
|
433
|
-
const DATE_FORMATS = [
|
|
444
|
+
const DATE_FORMATS = [
|
|
445
|
+
"%-d %B %Y", "%-d %b %Y", "%A %-d %B %Y", "%-d %B", "%-d %b", "%B %Y", "%A",
|
|
446
|
+
"%d-%m-%Y", "%-d-%-m-%Y", "%Y-%m-%d", "%-m/%-d/%Y",
|
|
447
|
+
"%-d %B %Y %H:%M", "%d-%m-%Y %H:%M", "%H:%M"
|
|
448
|
+
]
|
|
434
449
|
|
|
435
450
|
// A date in a strftime format, in the page's language, for a format's example
|
|
436
451
|
export function strftime(date, format, locale = document.documentElement?.lang || "en") {
|
|
@@ -440,7 +455,10 @@ export function strftime(date, format, locale = document.documentElement?.lang |
|
|
|
440
455
|
d: pad(date.getDate()), "-d": String(date.getDate()), e: String(date.getDate()).padStart(2, " "),
|
|
441
456
|
m: pad(date.getMonth() + 1), "-m": String(date.getMonth() + 1), Y: String(date.getFullYear()), y: pad(date.getFullYear() % 100),
|
|
442
457
|
B: part({ month: "long" }), b: part({ month: "short" }).replace(/\.$/, ""), A: part({ weekday: "long" }), a: part({ weekday: "short" }),
|
|
443
|
-
H: pad(date.getHours()),
|
|
458
|
+
H: pad(date.getHours()), "-H": String(date.getHours()), M: pad(date.getMinutes()), S: pad(date.getSeconds()),
|
|
459
|
+
I: pad(date.getHours() % 12 || 12), "-I": String(date.getHours() % 12 || 12), p: date.getHours() < 12 ? "AM" : "PM",
|
|
460
|
+
R: `${pad(date.getHours())}:${pad(date.getMinutes())}`,
|
|
461
|
+
Z: new Intl.DateTimeFormat(locale, { timeZoneName: "short" }).formatToParts(date).find((part) => part.type === "timeZoneName")?.value || ""
|
|
444
462
|
}
|
|
445
463
|
return format.replace(/%(-?[a-zA-Z])/g, (match, code) => codes[code] ?? match)
|
|
446
464
|
}
|
data/config/locales/en.yml
CHANGED
data/config/locales/nl.yml
CHANGED
data/lib/tess_edit/version.rb
CHANGED