From 1350701eecfe6845e1041169cb04fe83869a3fe5 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 28 Oct 2009 17:38:06 -0400 Subject: [PATCH] Update util.generateHelp. --- common/content/util.js | 74 +++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 44 deletions(-) diff --git a/common/content/util.js b/common/content/util.js index 38152b1a..07530b7c 100644 --- a/common/content/util.js +++ b/common/content/util.js @@ -276,60 +276,46 @@ const util = { //{{{ /** * Generates an Asciidoc help entry. * - * @param {Command|Mapping|Option} obj A liberator Command, - * Mapping or Option object - * @param {string} extraHelp Extra help text beyond the description. + * @param {Command|Map|Option} obj A liberator Command, + * Map or Option object + * @param {XMLList} extraHelp Extra help text beyond the description. * @returns {string} */ generateHelp: function generateHelp(obj, extraHelp) { - let start = "", end = ""; + let spec = util.identity; + let tag = util.identity; if (obj instanceof Command) - start = ":"; + tag = spec = function (cmd) <>:{cmd}; + else if (obj instanceof Map && obj.count) + spec = function (map) <>count{map}; else if (obj instanceof Option) - start = end = "'"; - - let ret = ""; - let longHelp = false; - if ((obj.help && obj.description) && (obj.help.length + obj.description.length) > 50) - longHelp = true; - - // the tags which are printed on the top right - for (let j = obj.names.length - 1; j >= 0; j--) - ret += "|" + start + obj.names[j] + end + "| "; - - if (longHelp) - ret += "+"; - - ret += "\n"; - - // the usage information - let usage = obj.names[0]; - if (obj.specs) // for :commands - usage = obj.specs[0]; - - usage = usage.replace(/{/, "\\\\{").replace(/}/, "\\\\}"); - usage = usage.replace(/'/, "\\'").replace(/`/, "\\`"); - ret += "||" + start + usage + end + "||"; - if (usage.length > 15) - ret += " +"; - - ret += "\n________________________________________________________________________________\n"; - - // the actual help text - if (obj.description) { - ret += obj.description + "."; // the help description - if (extraHelp) - ret += " +\n" + extraHelp; + spec = function (opt) {opt}; + tag = function (opt) <>'{opt}'; } - else - ret += "Sorry, no help available"; - // add more space between entries - ret += "\n________________________________________________________________________________\n\n\n"; + // E4X has its warts. + let br = <> + ; - return ret; + default xml namespace = ""; + XML.prettyPrinting = false; + XML.ignoreWhitespace = false; + + return <> + + + {template.map(obj.names, tag, " ")} + {spec((obj.specs || obj.names)[0])}{ + !obj.type ? "" : <> + {obj.type} + {obj.defaultValue}} + { + obj.description ? br+

{obj.description.replace(/\.?$/, ".")}

: "" }{ + extraHelp ? br+extraHelp : "" }{ + !(extraHelp || obj.description) ? br+

Sorry, no help available.

: "" } +
+
.toXMLString(); }, /**