From 610fc28e8a9716c9bd0e85f76e06394d0ee586cf Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Mon, 25 Apr 2011 22:20:39 +0000 Subject: [PATCH] nixos-gui: Improve pretty-print: - Handle int & derivations. - Change the new-line policy. svn path=/nixos/trunk/; revision=26975 --- gui/chrome/content/nixos.js | 55 +++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/gui/chrome/content/nixos.js b/gui/chrome/content/nixos.js index 3718cbc53e97..d880331f076b 100644 --- a/gui/chrome/content/nixos.js +++ b/gui/chrome/content/nixos.js @@ -142,41 +142,47 @@ Option.prototype = { var xml2nix_pptable = { attrs: function (node, depth, pp) { - var out = ""; - out += "{"; var children = node.children().not( function () { var name = $(this).attr("name"); return name.charAt(0) == "_"; } ); - if (children.lenght != 0) - { - depth += 1; - children.each( - function (idx) { out += pp.dispatch($(this), depth, pp); } - ); - depth -= 1; - out += this.indent(depth) + ""; - } + var c = 0; + var out = ""; + out += "{"; + depth += 1; + children.each( + function (idx) { + c += 1; + out += pp.indent(depth); + out += pp.dispatch($(this), depth, pp); + } + ); + depth -= 1; + if (c > 0) + out += this.indent(depth); else out += " "; out += "}"; return out; }, list: function (node, depth, pp) { + var children = node.children(); + var c = 0; var out = ""; out += "["; - var children = node.children(); - if (children.lenght != 0) - { - depth += 1; - children.each( - function (idx) { out += pp.dispatch($(this), depth, pp); } - ); - depth -= 1; + depth += 1; + children.each( + function (idx) { + c += 1; + out += pp.indent(depth); + out += pp.dispatch($(this), depth, pp); + } + ); + depth -= 1; + if (c > 0) out += this.indent(depth); - } else out += " "; out += "]"; @@ -186,13 +192,10 @@ var xml2nix_pptable = { var name = node.attr("name"); var out = ""; var val = ""; - out += this.indent(depth); out += name + " = "; depth += 1; val = pp.dispatch(node.children().first(), depth, pp); out += val; - if (val.indexOf("\n") != -1) - out += this.indent(depth);; depth -= 1; out += ";"; return out; @@ -206,9 +209,15 @@ var xml2nix_pptable = { bool: function (node, depth, pp) { return node.attr("value"); }, + "int": function (node, depth, pp) { + return node.attr("value"); + }, null: function (node, depth, pp) { return "null"; }, + derivation: function (node, depth, pp) { + return ""; + }, function: function (node, depth, pp) { return ""; },