Skip to content

Commit

Permalink
Housekeeping, better README
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmichael committed Apr 29, 2023
1 parent 015cfae commit 913cc07
Show file tree
Hide file tree
Showing 4 changed files with 1,525 additions and 1,413 deletions.
File renamed without changes.
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@

**Better attribute API for snippets and templates**

This plugin brings [Vue.js](https://vuejs.org)/[Laravel-Blade](https://laravel.com/docs/9.x/blade#components)-like attribute composition to the templates of your [Kirby](https://getkirby.com) yproject. This is an exploration in search of better HTML attribute handling for nested snippets and components.

**⚠️ Work-in-progress, use at your own risk ⚠️**

This plugin brings [Vue.js](https://vuejs.org)/[Laravel-Blade](https://laravel.com/docs/9.x/blade#components)-like attribute composition to the templates of your [Kirby project](https://getkirby.com). This is an exploration in search of better HTML attribute handling for nested snippets and components.

## Requirements

- Kirby 3.8
- Kirby 3.8+
- PHP 8.1 (because of [Enumeration](https://www.php.net/manual/en/language.types.enumerations.php) support)

## Installation

During this early development stage, installation only works via composer:
The recommended is installation via composer.

```
composer require fabianmichael/kirby-template-attributes
```

Alternatively, if you want to contribute to the development of this plugin, you can install it via submodule or clone this repository and use it as a local composer dependency.
Alternatively, you can also [download the plugin](https://github.com/fabianmichael/kirby-template-attributes/archive/main.zip) and install it manually by copying it to the `site/plugins/` folder of your website.

## Usage

Expand All @@ -37,14 +34,18 @@ Use the `attributes()` helper for generating a string of attributes:
You can also use named arguments if you prefer a leaner syntax. Be aware, that this only works as long as you don’t have dashes in your attribute names:

```php
<svg <?= attributes(
<img <?= attributes(
class: 'icon',
width: 16,
height: 16,
viewBox: '0 0 16 16',
) ?>>[…]</svg>
src: $image->url(),
alt: 'The funniest donkey ever!',
) ?>>
```

⚠️ If you need XML-compatible attributes, always call `$attributes->toXml()` instead of just echoing the `Attributes` object,
because otherwise all attributes will be converted to lower-case.

In many cases, you need to set different classes. The `classes()` helper is a nice shortcut for improved readability:

```php
Expand Down Expand Up @@ -88,16 +89,13 @@ The `classes()` helper is pretty flexible and also accepts multiple paramaters,
]) ?>
```

## Custom merge strategies

- Custom merge strategies for arbitrary attributes


## Before/After

You can set `$before` and `$after`, just like for Kirby’s `Html::attr()` helper by using the corresponding methods:

```
->before()
->after()
attributes(class: 'foo')->before(' ');
attributes(class: 'foo')->after(' ');
```

## Examples
Expand Down Expand Up @@ -164,3 +162,8 @@ This is already cool and makes working with attributes for snippets much easier,
]) ?>
</nav>
```


## License

MIT (but you are highly encouraged to **[❤️ sponsor me](https://github.com/sponsors/fabianmichael)**, if this piece of software helps you to pay your bills).
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
"description": "Better HTML attribute handling for your snippets and templates.",
"license": "MIT",
"type": "kirby-plugin",
"version": "1.2.2",
"version": "1.3.0",
"authors": [
{
"name": "Fabian Michael",
"email": "[email protected]"
}
],
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.13",
"phpunit/phpunit": "^9",
"phpmd/phpmd" : "@stable",
"vimeo/psalm": "^5.1",
"getkirby/cms": "^3.9"
},
"require": {
"getkirby/composer-installer": "^1.2",
"getkirby/cms": "^3.8"
"getkirby/composer-installer": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -41,11 +47,5 @@
"extra": {
"kirby-cms-path": false,
"installer-name": "template-attributes"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.13",
"phpunit/phpunit": "^9",
"phpmd/phpmd" : "@stable",
"vimeo/psalm": "^5.1"
}
}
Loading

0 comments on commit 913cc07

Please sign in to comment.