fixed issue with toXMLGeneric and also made it indented
This commit is contained in:
parent
cbd6262c10
commit
4a4f90b613
|
@ -4,13 +4,24 @@ nixpkgs.lib.extend (
|
||||||
toXMLGeneric = let
|
toXMLGeneric = let
|
||||||
toXMLRecursive =
|
toXMLRecursive =
|
||||||
toXmlRecursive'
|
toXmlRecursive'
|
||||||
"<?xml version='1.0' encoding='utf-8'?>";
|
"<?xml version='1.0' encoding='utf-8'?>\n"
|
||||||
|
0;
|
||||||
|
|
||||||
toXmlRecursive' = str: xml: let
|
indent = depth: (
|
||||||
parseTag = str: xml: (builtins.concatStringsSep "" [
|
if (depth <= 0)
|
||||||
|
then ""
|
||||||
|
else (" " + (indent (depth - 1)))
|
||||||
|
);
|
||||||
|
|
||||||
|
toXmlRecursive' = str: depth: xml: let
|
||||||
|
# depth = if (builtins.isInt depth) then depth else (throw "DEPTH ISNT AN INT??? WTFFF");
|
||||||
|
parseTag = str: depth: xml: (builtins.concatStringsSep "" [
|
||||||
str
|
str
|
||||||
"\n"
|
"${indent depth}<${xml.name}${
|
||||||
"<${xml.name}"
|
if (builtins.hasAttr "content" xml)
|
||||||
|
then ">"
|
||||||
|
else " "
|
||||||
|
}"
|
||||||
|
|
||||||
(
|
(
|
||||||
if (builtins.hasAttr "properties" xml)
|
if (builtins.hasAttr "properties" xml)
|
||||||
|
@ -24,20 +35,20 @@ nixpkgs.lib.extend (
|
||||||
|
|
||||||
(
|
(
|
||||||
if builtins.hasAttr "content" xml
|
if builtins.hasAttr "content" xml
|
||||||
then ((toXmlRecursive' "" xml.content) + "\n</${xml.name}>")
|
then ((toXmlRecursive' "\n" (depth + 1) xml.content) + "</${xml.name}>")
|
||||||
else "/>"
|
else "/>"
|
||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
output =
|
in
|
||||||
if (builtins.isAttrs xml)
|
if (builtins.isAttrs xml)
|
||||||
then (parseTag str xml)
|
then "${parseTag str depth xml}\n${indent (depth - 1)}"
|
||||||
else if (builtins.isList xml)
|
else if (builtins.isList xml)
|
||||||
then (builtins.concatStringsSep "\n" (builtins.map (x: (toXmlRecursive' "" x)) xml))
|
then "\n${(builtins.concatStringsSep "" (builtins.map (x: (toXmlRecursive' "" depth x)) xml))}${indent (depth - 1)}"
|
||||||
else if ((builtins.isBool xml) || (builtins.isInt xml) || (builtins.isNull xml) || (builtins.isFloat xml))
|
else if ((builtins.isBool xml) || (builtins.isInt xml) || (builtins.isNull xml) || (builtins.isFloat xml))
|
||||||
then (builtins.toString xml)
|
then (builtins.toString xml)
|
||||||
else nixpkgs.lib.abort "Cannot convert a ${builtins.typeOf xml} to XML";
|
else if (builtins.isString xml)
|
||||||
in
|
then xml
|
||||||
output;
|
else throw "Cannot convert a ${builtins.typeOf xml} to XML";
|
||||||
in
|
in
|
||||||
toXMLRecursive;
|
toXMLRecursive;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue