Skip to content

Commit

Permalink
feat!: use prefix $ instead of @ for props
Browse files Browse the repository at this point in the history
Many js-frameworks (alpine, petite-vue) use `@` for events. The `$`
won't clash with it and indicate that the prop will be available as a
php variable in the snippet/layout.
  • Loading branch information
arnoson committed Nov 24, 2023
1 parent 6c2c049 commit cef8534
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/cli/site/snippets/menu.kirby
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ul>
<?php foreach($pages as $page): ?>
<li>
<snippet:link @href="<?= $page->url() ?>">
<snippet:link $href="<?= $page->url() ?>">
<?= $page->title() ?>
</snippet:link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion examples/cli/site/templates/default.kirby
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<h1><?= $site->title() ?></h1>
<?php if (true): ?>
<snippet:menu
@pages="<? $site->children() ?>"
$pages="<? $site->children() ?>"
></snippet:menu>
<?php endif; ?>
</body>
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/src/snippets/menu.kirby
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ul>
<?php foreach($pages as $page): ?>
<li>
<snippet:link @href="<?= $page->url() ?>">
<snippet:link $href="<?= $page->url() ?>">
<?= $page->title() ?>
</snippet:link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/src/templates/default.kirby
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<h1><?= $site->title() ?></h1>
<?php if (true): ?>
<snippet:menu
@pages="<? $site->children() ?>"
$pages="<? $site->children() ?>"
></snippet:menu>
<?php endif; ?>
</body>
Expand Down
3 changes: 1 addition & 2 deletions packages/kirby-plugin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ function __snippetData(array $attributes) {
$attr = [];

foreach($attributes as $key => $value) {
if (strpos($key, '@') === 0) {
// Remove the leading '@'
if (str_starts_with($key, '$')) {
$name = substr($key, 1);
$data[$name] = $value;
} else {
Expand Down
6 changes: 3 additions & 3 deletions packages/kirby-plugin/tests/snippetDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

it('handles snippet props and groups attributes', function() {
$input = [
'@myProp' => 123,
'@myOtherProp' => 'test',
'$myProp' => 123,
'$myOtherProp' => 'test',
'class' => 'red',
'aria-label' => 'text'
];
Expand All @@ -23,7 +23,7 @@
});

it('provides an empty attr array', function() {
$input = ['@prop' => true];
$input = ['$prop' => true];
$output = ['prop' => true, 'attr' => []];

expect(__snippetData($input))->toEqual($output);
Expand Down
2 changes: 1 addition & 1 deletion packages/npm-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ watchFiles('**/*.kirby', options)
transformFiles('**/*.kirby', options)

// or compile a string
const result = transform(`<snippet:test @prop="<? true ?>" />`)
const result = transform(`<snippet:test $prop="<? true ?>" />`)
```

0 comments on commit cef8534

Please sign in to comment.