From 2217e98fa6bab1457124fde50e2a9bac7a08d3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schwei=C3=9Finger?= Date: Mon, 24 Apr 2023 10:25:03 +0200 Subject: [PATCH] add readme and license file --- LICENSE.md | 21 ++++++++++++++++ README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3cb2529 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 visuellverstehen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index ca5b18a..70f34e3 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,10 @@ -# Statamic Content Renderer +# Content Renderer -> Statamic Content Renderer is a Statamic addon that does something pretty neat. - -## Features - -This addon does: - -- This -- And this -- And even this +A Statamic addon that renders content from bard and replicator fields to make their content searchable with [search transformers](https://statamic.dev/search#transforming-fields). ## How to Install -You can search for this addon in the `Tools > Addons` section of the Statamic control panel and click **install**, or run the following command from your project root: +Run the following command from your project root: ``` bash composer require visuellverstehen/statamic-content-renderer @@ -20,4 +12,61 @@ composer require visuellverstehen/statamic-content-renderer ## How to Use -Here's where you can explain how to use this wonderful addon. +The content renderer is available through the `Renderer()` class. To render the content of a replicator or bard field, the class requires a view that provides the info of how to display all the configured sets, e. g.: + +```antlers +{{# resources/views/sets.antlers.php #}} + +{{ my_replicator_field }} + {{ partial src="sets/{type}" }} +{{ /my_replicator_field }} +``` + +This view needs to be passed on to the renderer class. + +```php +use VV\ContentRenderer\Renderer; + +// ... + +$renderer = new Renderer(); +$renderer->setContent($entry, 'my_replicator_field'); +$renderer->setView('sets'); + +$content = $renderer->render(); +``` + +The renderer uses the view to render all sets (and all written content of bard fields), sanitizes the content (strips all HTML tags etc.) and returns a string containing every written word from within the field. + +This can be used within a [search transformer](https://statamic.dev/search#transforming-fields) to make the content of bard and replicator fields available for full-text search: + +```php +namespace App\SearchTransformers; + +use VV\ContentRenderer\Renderer; + +class MyReplicatorFieldTransformer +{ + public function handle($value, $field, $searchable) + { + $renderer = new Renderer(); + $renderer->setContent($searchable, 'my_replicator_field'); + $renderer->setView('sets'); + + return $renderer->render(); + } +} +``` + +If you want to keep the HTML tags and/or modify the content in your own way, you can instruct the renderer to keep them: + +```php +$renderer = (new Renderer())->withHtmlTags(); +``` + +## More about us + +- [www.visuellverstehen.de](https://visuellverstehen.de) + +## License +The MIT license (MIT). Please take a look at the [license file](LICENSE.md) for more information. \ No newline at end of file