added toXml function
This commit is contained in:
parent
59e19e162a
commit
32e4e2614a
44
lib/default.nix
Normal file
44
lib/default.nix
Normal file
|
@ -0,0 +1,44 @@
|
|||
{nixpkgs, ...}:
|
||||
nixpkgs.lib.extend (
|
||||
final: prev: {
|
||||
toXMLGeneric = let
|
||||
toXMLRecursive =
|
||||
toXmlRecursive'
|
||||
"<?xml version='1.0' encoding='utf-8'?>";
|
||||
|
||||
toXmlRecursive' = str: xml: let
|
||||
parseTag = str: xml: (builtins.concatStringsSep "" [
|
||||
str
|
||||
"\n"
|
||||
"<${xml.name}"
|
||||
|
||||
(
|
||||
if (builtins.hasAttr "properties" xml)
|
||||
then
|
||||
(" "
|
||||
+ builtins.concatStringsSep " " (nixpkgs.lib.attrsets.mapAttrsToList
|
||||
(name: value: "${name}=\"${nixpkgs.lib.strings.escapeXML value}\"")
|
||||
xml.properties))
|
||||
else ""
|
||||
)
|
||||
|
||||
(
|
||||
if builtins.hasAttr "content" xml
|
||||
then ((toXmlRecursive' "" xml.content) + "\n</${xml.name}>")
|
||||
else "/>"
|
||||
)
|
||||
]);
|
||||
output =
|
||||
if (builtins.isAttrs xml)
|
||||
then (parseTag str xml)
|
||||
else if (builtins.isList xml)
|
||||
then (builtins.concatStringsSep "\n" (builtins.map (x: (toXmlRecursive' "" x)) xml))
|
||||
else if ((builtins.isBool xml) || (builtins.isInt xml) || (builtins.isNull xml) || (builtins.isFloat xml))
|
||||
then (builtins.toString xml)
|
||||
else nixpkgs.lib.abort "Cannot convert a ${builtins.typeOf xml} to XML";
|
||||
in
|
||||
output;
|
||||
in
|
||||
toXMLRecursive;
|
||||
}
|
||||
)
|
|
@ -1,7 +0,0 @@
|
|||
{nixpkgs, ...}:
|
||||
nixpkgs.lib.extend (
|
||||
final: prev: {
|
||||
fromXml = {
|
||||
};
|
||||
}
|
||||
)
|
Loading…
Reference in a new issue