Skip to content

Commit 95b1afb

Browse files
committed
Initial commit
0 parents  commit 95b1afb

File tree

8 files changed

+180
-0
lines changed

8 files changed

+180
-0
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.php]
13+
indent_size = 4
14+
15+
[*.md,*.txt]
16+
trim_trailing_whitespace = false
17+
insert_final_newline = false
18+
19+
[composer.json]
20+
indent_size = 4

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# OS files
2+
.DS_Store
3+
4+
# npm modules
5+
/node_modules
6+
7+
# Composer files
8+
/vendor

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) <Year> <Your Name>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Kirby Playground
2+
3+
## Usage
4+
5+
1. Create your tests as snippets in `/site/snippets/playground/`
6+
2. Access your tests at `/playground/[component-name]`
7+
8+
For example, if you have a snippet named `buttons.php`, it will be available at `/playground/buttons`.
9+
10+
## Features
11+
12+
- Custom route handling for `/playground/(:any?)`
13+
- Site method `playgroundLinks()` that scans the playground snippets directory and creates a navigation list
14+
- Components are rendered through virtual pages, without requiring actual page files
15+
- Loads CSS files from `assets/css/playground/[component-name].css` and a global `playground.css`
16+
- Built-in fallback to a component list when accessing non-existent components
17+
18+
## Configuration
19+
20+
You can enable authentication to restrict access to logged-in Panel users:
21+
22+
```php
23+
// site/config/config.php
24+
return [
25+
'medienbaecker.playground.auth' => true
26+
];
27+
```
28+
29+
## Directory Structure
30+
31+
```
32+
site/
33+
├── snippets/
34+
│ └── playground/
35+
│ └── your-component.php
36+
└── assets/
37+
└── css/
38+
└── playground/
39+
├── playground.css
40+
└── your-component.css
41+
```

composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "medienbaecker/playground",
3+
"description": "Kirby Playground",
4+
"license": "MIT",
5+
"type": "kirby-plugin",
6+
"version": "1.0.0",
7+
"authors": [
8+
{
9+
"name": "Thomas Günther",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"getkirby/composer-installer": "^1.1"
15+
}
16+
}

index.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
use Kirby\Cms\App as Kirby;
4+
use Kirby\Cms\Page;
5+
use Kirby\Filesystem\Dir;
6+
7+
Kirby::plugin('medienbaecker/playground', [
8+
'options' => [
9+
'auth' => false
10+
],
11+
12+
'siteMethods' => [
13+
'playgroundLinks' => function () {
14+
$files = Dir::files(kirby()->root('snippets') . '/playground');
15+
$links = array_map(function ($file) {
16+
$name = pathinfo($file, PATHINFO_FILENAME);
17+
$title = ucwords(str_replace('-', ' ', $name));
18+
return "<li><a href='" . url("playground/{$name}") . "'>{$title}</a></li>";
19+
}, $files);
20+
21+
return '<ul class="playground-nav">' . implode('', $links) . '</ul>';
22+
}
23+
],
24+
25+
'templates' => [
26+
'playground' => __DIR__ . '/templates/playground.php'
27+
],
28+
29+
'snippets' => [
30+
'playground/not-found' => __DIR__ . '/snippets/not-found.php'
31+
],
32+
33+
'routes' => [
34+
[
35+
'pattern' => 'playground/(:any?)',
36+
'action' => function ($component = null) {
37+
if (kirby()->option('medienbaecker.playground.auth') && !kirby()->user()) {
38+
$this->next();
39+
}
40+
41+
$page = new Page([
42+
'slug' => $component ?? 'playground',
43+
'template' => 'playground',
44+
'content' => [
45+
'title' => $component ? "Playground: {$component}" : 'Playground',
46+
'component' => $component
47+
]
48+
]);
49+
50+
return site()->visit($page);
51+
}
52+
]
53+
]
54+
]);

snippets/not-found.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="wrap playground-list">
2+
<div class="inner rich-text">
3+
<?= site()->playgroundLinks() ?>
4+
</div>
5+
</div>

templates/playground.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php snippet('head') ?>
2+
3+
<?= css([
4+
'assets/css/playground/playground.css',
5+
"assets/css/playground/{$page->component()}.css"
6+
]) ?>
7+
8+
<?php
9+
snippet([
10+
"playground/{$page->component()}",
11+
'playground/not-found'
12+
])
13+
?>
14+
15+
<?php snippet('bottom') ?>

0 commit comments

Comments
 (0)