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

master
Jean-Christian Paul 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/">
<module id="improve">
<name>improve</name>
<version>0.4</version>
<author>Jean-Christian Denis and contributors</author>
<desc>Tiny tools to fix things for module devs</desc>
<file>https://github.com/JcDenis/improve/releases/download/v0.4/plugin-improve.zip</file>
<da:dcmin>2.19</da:dcmin>
<da:details>https://github.com/JcDenis/improve</da:details>
<da:support>https://github.com/JcDenis/improve</da:support>
</module>
</modules>
<module id="improve">
<name>improve</name>
<version>0.4</version>
<author>Jean-Christian Denis and contributors</author>
<desc>Tiny tools to fix things for module devs</desc>
<file>https://github.com/JcDenis/improve/releases/download/v0.4/plugin-improve.zip</file>
<da:dcmin>2.19</da:dcmin>
<da:details>https://github.com/JcDenis/improve</da:details>
<da:support>https://github.com/JcDenis/improve</da:support>
</module>
</modules>

View File

@ -60,6 +60,8 @@ class ImproveActionDcstore extends ImproveAction
return false;
}
$content = $this->prettyXML($content);
try {
files::putContent($this->module['sroot'] . '/dcstore.xml', $content);
$this->setSuccess(__('Write dcstore.xml file.'));
@ -166,7 +168,21 @@ class ImproveActionDcstore extends ImproveAction
$res = new xmlTag('modules', $rsp);
$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()