nixos-gui: Improve pretty-print:

- Handle int & derivations.
- Change the new-line policy.

svn path=/nixos/trunk/; revision=26975
This commit is contained in:
Nicolas Pierron 2011-04-25 22:20:39 +00:00
parent 45026f8540
commit 610fc28e8a

View File

@ -142,41 +142,47 @@ Option.prototype = {
var xml2nix_pptable = { var xml2nix_pptable = {
attrs: function (node, depth, pp) { attrs: function (node, depth, pp) {
var out = "";
out += "{";
var children = node.children().not( var children = node.children().not(
function () { function () {
var name = $(this).attr("name"); var name = $(this).attr("name");
return name.charAt(0) == "_"; return name.charAt(0) == "_";
} }
); );
if (children.lenght != 0) var c = 0;
{ var out = "";
out += "{";
depth += 1; depth += 1;
children.each( children.each(
function (idx) { out += pp.dispatch($(this), depth, pp); } function (idx) {
c += 1;
out += pp.indent(depth);
out += pp.dispatch($(this), depth, pp);
}
); );
depth -= 1; depth -= 1;
out += this.indent(depth) + ""; if (c > 0)
} out += this.indent(depth);
else else
out += " "; out += " ";
out += "}"; out += "}";
return out; return out;
}, },
list: function (node, depth, pp) { list: function (node, depth, pp) {
var children = node.children();
var c = 0;
var out = ""; var out = "";
out += "["; out += "[";
var children = node.children();
if (children.lenght != 0)
{
depth += 1; depth += 1;
children.each( children.each(
function (idx) { out += pp.dispatch($(this), depth, pp); } function (idx) {
c += 1;
out += pp.indent(depth);
out += pp.dispatch($(this), depth, pp);
}
); );
depth -= 1; depth -= 1;
if (c > 0)
out += this.indent(depth); out += this.indent(depth);
}
else else
out += " "; out += " ";
out += "]"; out += "]";
@ -186,13 +192,10 @@ var xml2nix_pptable = {
var name = node.attr("name"); var name = node.attr("name");
var out = ""; var out = "";
var val = ""; var val = "";
out += this.indent(depth);
out += name + " = "; out += name + " = ";
depth += 1; depth += 1;
val = pp.dispatch(node.children().first(), depth, pp); val = pp.dispatch(node.children().first(), depth, pp);
out += val; out += val;
if (val.indexOf("\n") != -1)
out += this.indent(depth);;
depth -= 1; depth -= 1;
out += ";"; out += ";";
return out; return out;
@ -206,9 +209,15 @@ var xml2nix_pptable = {
bool: function (node, depth, pp) { bool: function (node, depth, pp) {
return node.attr("value"); return node.attr("value");
}, },
"int": function (node, depth, pp) {
return node.attr("value");
},
null: function (node, depth, pp) { null: function (node, depth, pp) {
return "null"; return "null";
}, },
derivation: function (node, depth, pp) {
return "<derivation>";
},
function: function (node, depth, pp) { function: function (node, depth, pp) {
return "<function>"; return "<function>";
}, },