diff --git a/content/buffer.js b/content/buffer.js index 6f467c1f..c8ae29e5 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -1558,8 +1558,9 @@ liberator.Buffer = function () //{{{ let file = content.document.location.pathname.split("/").pop() || "[No Name]"; let title = content.document.title || "[No Title]"; - let info = liberator.template.map("gf", - function (opt) liberator.template.map(pageInfo[opt][0](), function (val) val, ", "), + let info = liberator.template.map("gf", function (opt) + liberator.template.map(pageInfo[opt][0](), + function (val) val, ", "), ", "); if (liberator.bookmarks.isBookmarked(this.URL)) diff --git a/content/editor.js b/content/editor.js index 3b70272d..f4be1a0f 100644 --- a/content/editor.js +++ b/content/editor.js @@ -931,7 +931,7 @@ liberator.Editor = function () //{{{ let list = { - liberator.template.map(abbrev, function (lhs, rhs) + liberator.template.map(abbrev, function ([lhs, rhs]) liberator.template.map(rhs, function (abbr) searchFilter.indexOf(abbr[0]) < 0 ? undefined : diff --git a/content/events.js b/content/events.js index c54a482f..c4da4aca 100644 --- a/content/events.js +++ b/content/events.js @@ -233,7 +233,7 @@ liberator.AutoCommands = function () //{{{ { - liberator.template.map(cmds, function (event, items) + liberator.template.map(cmds, function ([event, items]) diff --git a/content/liberator.js b/content/liberator.js index 52cecbe0..45485d50 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -280,15 +280,7 @@ const liberator = (function () //{{{ else { // TODO: clicking on these should open the help - var usage =
----- Auto Commands -----
{event}
- { - liberator.template.map(liberator.commands, function (command) - - - - ) - } -
{command.name}{command.description}
; + var usage = liberator.template.usage(liberator.commands); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); } }, @@ -361,15 +353,7 @@ const liberator = (function () //{{{ else { // TODO: clicking on these should open the help - var usage = - { - liberator.template.map(liberator.options, function (option) - - - - ) - } -
{option.name}{option.description}
; + var usage = liberator.template.usage(liberator.options); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); } }, @@ -523,15 +507,7 @@ const liberator = (function () //{{{ else { // TODO: clicking on these should open the help - var usage = - { - liberator.template.add(liberator.mappings, function (mapping) - - - - ) - } -
{mapping.names[0]}{mapping.description}
; + var usage = liberator.template.usage(liberator.mappings); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); } }, diff --git a/content/options.js b/content/options.js index fe9aceb0..6e3a4441 100644 --- a/content/options.js +++ b/content/options.js @@ -284,7 +284,7 @@ liberator.Options = function () //{{{ var str = { - liberator.template.map(liberator.globalVariables, function (i, value) { + liberator.template.map(liberator.globalVariables, function ([i, value]) { let prefix = typeof value == "number" ? "#" : typeof value == "function" ? "*" : " "; diff --git a/content/template.js b/content/template.js index 3ded5750..dce43378 100644 --- a/content/template.js +++ b/content/template.js @@ -5,17 +5,11 @@ liberator.template = { map: function (iter, fn, sep) { - if (fn.length > 1) - { - iter = Iterator(iter); - let oldfn = fn; - fn = function (x) oldfn.apply(null, x); - } - else if (iter.length) /* Kludge? */ + if (iter.length) /* Kludge? */ iter = liberator.util.arrayIter(iter); let ret = <>; let n = 0; - for each (let i in iter) + for each (let i in Iterator(iter)) { let val = fn(i); if (val == undefined) @@ -215,12 +209,26 @@ liberator.template = { this.map(iter, function (row) { - liberator.template.map(row, function (i, d) + liberator.template.map(Iterator(row), function ([i, d]) ) } ) }
{d}
); }, + + usage: function (iter) + { + return this.generic( + + { + this.map(iter, function (item) + + + + ) + } +
{item.name || item.names[0]}{item.description}
); + }, };