mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-30 11:55:46 +01:00
Partially auto-generate help index. Still needs tag linkification and mappings.
This commit is contained in:
@@ -127,6 +127,8 @@ const Command = Class("Command", {
|
||||
this.options = this.options.map(CommandOption.fromArray, CommandOption);
|
||||
},
|
||||
|
||||
get helpTag() ":" + this.name,
|
||||
|
||||
/**
|
||||
* Execute this command.
|
||||
*
|
||||
@@ -1449,6 +1451,7 @@ const Commands = Module("commands", {
|
||||
dactyl.addUsageCommand({
|
||||
name: ["listc[ommands]", "lc"],
|
||||
description: "List all Ex commands along with their short descriptions",
|
||||
index: "ex-cmd",
|
||||
iterate: function (args) commands,
|
||||
format: {
|
||||
description: function (cmd) template.linkifyHelp(cmd.description + (cmd.replacementText ? ": " + cmd.action : "")),
|
||||
|
||||
@@ -27,6 +27,7 @@ const Dactyl = Module("dactyl", {
|
||||
Object.defineProperty(window, "liberator", prop);
|
||||
Object.defineProperty(modules, "liberator", prop);
|
||||
this.commands = {};
|
||||
this.indices = {};
|
||||
this.modules = modules;
|
||||
this.observers = {};
|
||||
|
||||
@@ -149,6 +150,12 @@ const Dactyl = Module("dactyl", {
|
||||
},
|
||||
options: params.options || []
|
||||
});
|
||||
if (params.index)
|
||||
this.indices[params.index] = function () {
|
||||
for (let obj in (params.iterateIndex || params.iterate)())
|
||||
if (obj.helpTag in services["dactyl:"].HELP_TAGS)
|
||||
yield dactyl.generateHelp(obj, null, null, true);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -557,6 +564,17 @@ const Dactyl = Module("dactyl", {
|
||||
</document>.toXMLString()));
|
||||
fileMap["plugins"] = function () ['text/xml;charset=UTF-8', help];
|
||||
|
||||
overlayMap["index"] = function () ['text/xml;charset=UTF-8',
|
||||
'<?xml version="1.0"?>\n' +
|
||||
'<overlay xmlns="' + NS + '">\n' +
|
||||
unescape(encodeURI( // UTF-8 handling hack.
|
||||
template.map(dactyl.indices, function ([name, iter])
|
||||
<dl insertafter={name + "-index"}>{
|
||||
template.map(iter(), util.identity)
|
||||
}</dl>, <>{"\n\n"}</>)))
|
||||
.replace('xmlns="' + XHTML + '"', "", "g") +
|
||||
'\n</overlay>'];
|
||||
|
||||
addTags("plugins", util.httpGet("dactyl://help/plugins").responseXML);
|
||||
this.helpInitialized = true;
|
||||
}
|
||||
@@ -717,49 +735,50 @@ const Dactyl = Module("dactyl", {
|
||||
|
||||
let res = <res>
|
||||
<dt>{link(obj.name)}</dt> <dd>{obj.description ? obj.description.replace(/\.$/, "") : ""}</dd></res>;
|
||||
if (!specOnly) {
|
||||
res.* += <>
|
||||
<item>
|
||||
<tags>{template.map(obj.names.slice().reverse(), tag, " ")}</tags>
|
||||
<spec>{
|
||||
spec(template.highlightRegexp((obj.specs || obj.names)[0],
|
||||
/\[(.*?)\]/g,
|
||||
function (m, n0) <oa>{n0}</oa>))
|
||||
}</spec>{
|
||||
!obj.type ? "" : <>
|
||||
<type>{obj.type}</type>
|
||||
<default>{obj.stringDefaultValue}</default></>}
|
||||
<description>{
|
||||
obj.description ? br + <p>{obj.description.replace(/\.?$/, ".")}</p> : "" }{
|
||||
extraHelp ? br + extraHelp : "" }{
|
||||
!(extraHelp || obj.description) ? br + <p>Sorry, no help available.</p> : "" }
|
||||
</description>
|
||||
</item></>;
|
||||
if (specOnly)
|
||||
return res.*;
|
||||
|
||||
function add(ary) {
|
||||
res.item.description.* += br +
|
||||
let (br = br + <> </>)
|
||||
<><dl>{ br + template.map(ary, function ([a, b]) <><dt>{a}</dt> <dd>{b}</dd></>, br) }
|
||||
</dl>
|
||||
</>;
|
||||
}
|
||||
res.* += <>
|
||||
<item>
|
||||
<tags>{template.map(obj.names.slice().reverse(), tag, " ")}</tags>
|
||||
<spec>{
|
||||
spec(template.highlightRegexp((obj.specs || obj.names)[0],
|
||||
/\[(.*?)\]/g,
|
||||
function (m, n0) <oa>{n0}</oa>))
|
||||
}</spec>{
|
||||
!obj.type ? "" : <>
|
||||
<type>{obj.type}</type>
|
||||
<default>{obj.stringDefaultValue}</default></>}
|
||||
<description>{
|
||||
obj.description ? br + <p>{obj.description.replace(/\.?$/, ".")}</p> : "" }{
|
||||
extraHelp ? br + extraHelp : "" }{
|
||||
!(extraHelp || obj.description) ? br + <p>Sorry, no help available.</p> : "" }
|
||||
</description>
|
||||
</item></>;
|
||||
|
||||
if (obj.completer)
|
||||
add(completion._runCompleter(obj.completer, "", null, args).items
|
||||
.map(function (i) [i.text, i.description]));
|
||||
|
||||
if (obj.options && obj.options.some(function (o) o.description))
|
||||
add(obj.options.filter(function (o) o.description)
|
||||
.map(function (o) [
|
||||
o.names[0],
|
||||
<>{o.description}{
|
||||
o.names.length == 1 ? "" :
|
||||
<> (short name: {
|
||||
template.map(o.names.slice(1), function (n) <em>{n}</em>, <>, </>)
|
||||
})</>
|
||||
}</>
|
||||
]));
|
||||
function add(ary) {
|
||||
res.item.description.* += br +
|
||||
let (br = br + <> </>)
|
||||
<><dl>{ br + template.map(ary, function ([a, b]) <><dt>{a}</dt> <dd>{b}</dd></>, br) }
|
||||
</dl>
|
||||
</>;
|
||||
}
|
||||
|
||||
if (obj.completer)
|
||||
add(completion._runCompleter(obj.completer, "", null, args).items
|
||||
.map(function (i) [i.text, i.description]));
|
||||
|
||||
if (obj.options && obj.options.some(function (o) o.description))
|
||||
add(obj.options.filter(function (o) o.description)
|
||||
.map(function (o) [
|
||||
o.names[0],
|
||||
<>{o.description}{
|
||||
o.names.length == 1 ? "" :
|
||||
<> (short name: {
|
||||
template.map(o.names.slice(1), function (n) <em>{n}</em>, <>, </>)
|
||||
})</>
|
||||
}</>
|
||||
]));
|
||||
return res.*.toXMLString().replace(/^ {12}|[ \t]+$/gm, "").replace(/^.*\n|\n.*$/g, "") + "\n";
|
||||
},
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ const Option = Class("Option", {
|
||||
this.globalValue = this.defaultValue;
|
||||
},
|
||||
|
||||
get helpTag() "'" + this.name + "'",
|
||||
|
||||
initValue: function () {
|
||||
dactyl.trapErrors(function () this.value = this.value, this);
|
||||
},
|
||||
@@ -842,6 +844,7 @@ const Options = Module("options", {
|
||||
dactyl.addUsageCommand({
|
||||
name: ["listo[ptions]", "lo"],
|
||||
description: "List all options along with their short descriptions",
|
||||
index: "option",
|
||||
iterate: function (args) options,
|
||||
format: {
|
||||
description: function (opt) (XML.ignoreWhitespace = false, XML.prettyPrinting = false, <>
|
||||
|
||||
Reference in New Issue
Block a user