fix dcstore xml rendering (thanks @franck-paul) closes #4

This commit is contained in:
Jean-Christian Denis 2021-11-05 22:51:04 +01:00
parent 27c8f2d0af
commit e127b460e9
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
2 changed files with 29 additions and 12 deletions

View file

@ -1,12 +1,13 @@
<?xml version="1.0"?>
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="improve"> <module id="improve">
<name>improve</name> <name>improve</name>
<version>0.4</version> <version>0.4</version>
<author>Jean-Christian Denis and contributors</author> <author>Jean-Christian Denis and contributors</author>
<desc>Tiny tools to fix things for module devs</desc> <desc>Tiny tools to fix things for module devs</desc>
<file>https://github.com/JcDenis/improve/releases/download/v0.4/plugin-improve.zip</file> <file>https://github.com/JcDenis/improve/releases/download/v0.4/plugin-improve.zip</file>
<da:dcmin>2.19</da:dcmin> <da:dcmin>2.19</da:dcmin>
<da:details>https://github.com/JcDenis/improve</da:details> <da:details>https://github.com/JcDenis/improve</da:details>
<da:support>https://github.com/JcDenis/improve</da:support> <da:support>https://github.com/JcDenis/improve</da:support>
</module> </module>
</modules> </modules>

View file

@ -60,6 +60,8 @@ class ImproveActionDcstore extends ImproveAction
return false; return false;
} }
$content = $this->prettyXML($content);
try { try {
files::putContent($this->module['sroot'] . '/dcstore.xml', $content); files::putContent($this->module['sroot'] . '/dcstore.xml', $content);
$this->setSuccess(__('Write dcstore.xml file.')); $this->setSuccess(__('Write dcstore.xml file.'));
@ -166,7 +168,21 @@ class ImproveActionDcstore extends ImproveAction
$res = new xmlTag('modules', $rsp); $res = new xmlTag('modules', $rsp);
$res->insertAttr('xmlns:da', 'http://dotaddict.org/da/'); $res->insertAttr('xmlns:da', 'http://dotaddict.org/da/');
return str_replace('><', ">\n<", $res->toXML()); return self::prettyXML($res->toXML());
}
private static function prettyXML(string $str): string
{
if (class_exists('DOMDocument')) {
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($str);
return $dom->saveXML();
}
return str_replace('><', ">\n<", $str);
} }
private function parseFilePattern() private function parseFilePattern()