Skip to content

Commit 5e7954f

Browse files
committed
✨ commands are automatically lazy resolved
see changes in readme for more information Signed-off-by: bnomei <[email protected]>
1 parent 01d8a7c commit 5e7954f

File tree

6 files changed

+14
-53
lines changed

6 files changed

+14
-53
lines changed

README.md

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -247,52 +247,6 @@ If you want you can also call any of [the core shipping with the CLI](https://gi
247247

248248
Keep in mind that the Janitor panel button and webhooks will append the `--quiet` option on all commands automatically to silence outputs to the non-existing CLI. But if you use `janitor()->command()` you will have to append `--quiet` to your command yourself.
249249

250-
### Smartly delaying resolution of a command argument
251-
252-
In some cases you do not want to resolve the query language of a commands argument(s) **every time** when the button is shown in the panel but delay that until the api call is received by Janitor. Janitor will then resolve it **once** and forward the updated argument(s) to your command. This is useful for process-intensive calls or when the string of the data would be very long, like when the data is HTML.
253-
254-
To achieve this you need to change the query language bounds for that argument from `{{ query }}` to `{( query )}`.
255-
256-
```yml
257-
test_sendmail:
258-
type: janitor
259-
command: 'sendmail --to {{ user.email }} --data {( page.htmlOfEmail )}'
260-
label: send mail
261-
```
262-
263-
> Note: This only works inside the Janitor fields `command`-property.
264-
265-
### Dynamic values in commands aka "Wrong value even after saving"
266-
267-
In the example above the `user.email` will resolve to the email of the user when the button is first rendered in the panel. But let's assume you want to pick a **value from the same page**. The example below will echo back the selected email as a message. But because of the complexity involved janitor commands (and other props) are NOT dynamic - they do NOT change if you change a value in the panel but only on reload of the page. So if you change the value and hit the button you will not get the new value but the old one!
268-
269-
```yaml
270-
selectEmail:
271-
type: select
272-
options:
273-
- [email protected] # <--- SET VALUE
274-
275-
276-
janitor_savedData:
277-
label: 'Saved Data'
278-
type: janitor
279-
# will use [email protected] until you reload the page manually
280-
command: 'janitor:pipe --data {{ page.selectEmail }} --to message'
281-
```
282-
283-
There are two ways to fix this.
284-
285-
1. One is to enforce a page reload with the `autosave: true` property.
286-
2. The other and recommended solution is to use the lazy resolved queries with the `{( )}` instead of `{{ }}` inside the command. This will resolve the query language of the data **every time** the button is clicked.
287-
288-
```yaml
289-
janitor_savedData:
290-
label: 'Saved Data'
291-
type: janitor
292-
command: 'janitor:pipe --data {( page.selectEmail )} --to message'
293-
# autosave: true
294-
```
295-
296250
### Running commands in your code
297251

298252
You can run any command in you own code as well like in a model, template, controller or hook. Since commands do not return data directly you need to retrieve data stored for Janitor using a helper `janitor()->data($commandName)`.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/kirby3-janitor",
33
"type": "kirby-plugin",
4-
"version": "3.9.2",
4+
"version": "3.10.0",
55
"license": "MIT",
66
"homepage": "https://github.com/bnomei/kirby3-janitor",
77
"description": "Kirby 3 Plugin for running commands like cleaning the cache from within the Panel, PHP code or a cronjob",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
return Janitor::isTrue($clipboard);
5151
},
5252
'command' => function ($command = null) {
53+
// make lazy by default
54+
$command = str_replace(['{{', '}}'], ['{(', ')}'], $command);
55+
56+
// allow non-lazy
57+
$command = str_replace(['{<', '>}'], ['{{', '}}'], $command);
58+
5359
// resolve queries
5460
$command = Janitor::query($command, $this->model());
5561

tests/site/blueprints/pages/default.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ fields:
158158
type: janitor
159159
command: 'janitor:pipe --data {( model.text.kirbytext )} --to message'
160160
# pipe will show lazy/smart resolved data on button (aka the message)
161+
help: THIS IS NEW AUTOMATIC DEFAULT IN v3.10
161162

162163
janitor_color:
163164
label: Janitor buttons can now be colorful
@@ -186,5 +187,5 @@ fields:
186187
janitor_savedData:
187188
label: 'Saved Data'
188189
type: janitor
189-
command: 'janitor:pipe --data {( page.sele )} --to message'
190+
command: 'janitor:pipe --data {{ page.sele }} --to message'
190191
# autosave: true

vendor/composer/installed.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php return array(
22
'root' => array(
33
'name' => 'bnomei/kirby3-janitor',
4-
'pretty_version' => '3.9.2',
5-
'version' => '3.9.2.0',
4+
'pretty_version' => '3.10.0',
5+
'version' => '3.10.0.0',
66
'reference' => NULL,
77
'type' => 'kirby-plugin',
88
'install_path' => __DIR__ . '/../../',
@@ -11,8 +11,8 @@
1111
),
1212
'versions' => array(
1313
'bnomei/kirby3-janitor' => array(
14-
'pretty_version' => '3.9.2',
15-
'version' => '3.9.2.0',
14+
'pretty_version' => '3.10.0',
15+
'version' => '3.10.0.0',
1616
'reference' => NULL,
1717
'type' => 'kirby-plugin',
1818
'install_path' => __DIR__ . '/../../',

0 commit comments

Comments
 (0)