From 7024a90eb8adca407ade43de7b55c247466743c9 Mon Sep 17 00:00:00 2001 From: Jens Scherbl Date: Tue, 17 Jan 2023 21:01:16 +0100 Subject: [PATCH] Drops dependency and renames plugin --- README.md | 7 +++++-- composer.json | 15 +++++++-------- index.php | 16 ++++------------ src/{Xml.php => XMLProcessor.php} | 13 ++++++++----- 4 files changed, 24 insertions(+), 27 deletions(-) rename src/{Xml.php => XMLProcessor.php} (61%) diff --git a/README.md b/README.md index 1a3010f..904a423 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ -# templates-xml -Post-processing for XML and XHTML templates. Ensures well-formed output and strips whitespace between nodes. +# Kirby XHTML + +Ensures well-formed XML and XHTML output for [Kirby][1] templates and strips whitespace between nodes. + +[1]: https://getkirby.com diff --git a/composer.json b/composer.json index b8afb35..6732b95 100755 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "kenshodigital/templates-xml", - "description": "Post-processing for XML and XHTML templates.", + "name": "kenshodigital/kirby-xhtml", + "description": "Ensures well-formed XML and XHTML output for Kirby templates.", "type": "kirby-plugin", - "version": "2.0.0", - "homepage": "https://github.com/kenshodigital/templates-xml", + "version": "1.0.0", + "homepage": "https://github.com/kenshodigital/kirby-xhtml", "license": "MIT", "authors": [ @@ -17,15 +17,14 @@ "php": "^8.2", "ext-dom": "*", "ext-libxml": "*", - "getkirby/cms": "^3.8.3", - "getkirby/composer-installer": "^1.2", - "kenshodigital/templates": "^2.0" + "getkirby/cms": "^3.9", + "getkirby/composer-installer": "^1.2" }, "autoload": { "psr-4": { - "Kenshō\\Templates\\": "./src/" + "Kenshō\\Xhtml\\": "./src/" } } } diff --git a/index.php b/index.php index 0862ccc..e573993 100755 --- a/index.php +++ b/index.php @@ -1,23 +1,15 @@ [ - /** - * Ensures well-formed output and - * strips whitespace between nodes - * for XML templates. - */ 'page.render:after' => function (string $contentType, array $data, string $html): string { - if (\in_array($contentType, Xml::TYPES)) { - $html = (new Xml(new DOMDocument))->process($html); + if (\in_array($contentType, XMLProcessor::TYPES)) { + $html = (new XMLProcessor(new DOMDocument))->process($html); } return $html; }, diff --git a/src/Xml.php b/src/XMLProcessor.php similarity index 61% rename from src/Xml.php rename to src/XMLProcessor.php index 4e93c82..54bb613 100755 --- a/src/Xml.php +++ b/src/XMLProcessor.php @@ -1,14 +1,15 @@ '; + public function __construct( private readonly DOMDocument $document ) { @@ -28,7 +31,7 @@ public function __construct( public function process(string $output): string { - $this->document->loadXML($output); + $this->document->loadXML(self::XML_DECLARATION . $output); return $this->document->saveXML(); }