1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-14 20:43:33 +01:00

Get rid of template.map overloading, add standard "usage" template for ex/vi/option

This commit is contained in:
Kris Maglione
2008-10-08 03:41:55 +00:00
parent 10376ecb77
commit 4ff5adcc4e
6 changed files with 26 additions and 41 deletions

View File

@@ -1558,8 +1558,9 @@ liberator.Buffer = function () //{{{
let file = content.document.location.pathname.split("/").pop() || "[No Name]"; let file = content.document.location.pathname.split("/").pop() || "[No Name]";
let title = content.document.title || "[No Title]"; let title = content.document.title || "[No Title]";
let info = liberator.template.map("gf", let info = liberator.template.map("gf", function (opt)
function (opt) liberator.template.map(pageInfo[opt][0](), function (val) val, ", "), liberator.template.map(pageInfo[opt][0](),
function (val) val, ", "),
", "); ", ");
if (liberator.bookmarks.isBookmarked(this.URL)) if (liberator.bookmarks.isBookmarked(this.URL))

View File

@@ -931,7 +931,7 @@ liberator.Editor = function () //{{{
let list = let list =
<table> <table>
{ {
liberator.template.map(abbrev, function (lhs, rhs) liberator.template.map(abbrev, function ([lhs, rhs])
liberator.template.map(rhs, function (abbr) liberator.template.map(rhs, function (abbr)
searchFilter.indexOf(abbr[0]) < 0 ? undefined : searchFilter.indexOf(abbr[0]) < 0 ? undefined :
<tr> <tr>

View File

@@ -233,7 +233,7 @@ liberator.AutoCommands = function () //{{{
<td class="hl-Title" colspan="2">----- Auto Commands -----</td> <td class="hl-Title" colspan="2">----- Auto Commands -----</td>
</tr> </tr>
{ {
liberator.template.map(cmds, function (event, items) liberator.template.map(cmds, function ([event, items])
<tr> <tr>
<td class="hl-Title" colspan="2">{event}</td> <td class="hl-Title" colspan="2">{event}</td>
</tr> </tr>

View File

@@ -280,15 +280,7 @@ const liberator = (function () //{{{
else else
{ {
// TODO: clicking on these should open the help // TODO: clicking on these should open the help
var usage = <table> var usage = liberator.template.usage(liberator.commands);
{
liberator.template.map(liberator.commands, function (command)
<tr>
<td class="hl-Title" style="padding-right: 20px">{command.name}</td>
<td>{command.description}</td>
</tr>)
}
</table>;
liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE);
} }
}, },
@@ -361,15 +353,7 @@ const liberator = (function () //{{{
else else
{ {
// TODO: clicking on these should open the help // TODO: clicking on these should open the help
var usage = <table> var usage = liberator.template.usage(liberator.options);
{
liberator.template.map(liberator.options, function (option)
<tr>
<td class="hl-Title" style="padding-right: 20px">{option.name}</td>
<td>{option.description}</td>
</tr>)
}
</table>;
liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE);
} }
}, },
@@ -523,15 +507,7 @@ const liberator = (function () //{{{
else else
{ {
// TODO: clicking on these should open the help // TODO: clicking on these should open the help
var usage = <table> var usage = liberator.template.usage(liberator.mappings);
{
liberator.template.add(liberator.mappings, function (mapping)
<tr>
<td class="hl-Title" style="padding-right: 20px"> {mapping.names[0]}</td>
<td>{mapping.description}</td>
</tr>)
}
</table>;
liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE);
} }
}, },

View File

@@ -284,7 +284,7 @@ liberator.Options = function () //{{{
var str = var str =
<table> <table>
{ {
liberator.template.map(liberator.globalVariables, function (i, value) { liberator.template.map(liberator.globalVariables, function ([i, value]) {
let prefix = typeof value == "number" ? "#" : let prefix = typeof value == "number" ? "#" :
typeof value == "function" ? "*" : typeof value == "function" ? "*" :
" "; " ";

View File

@@ -5,17 +5,11 @@ liberator.template = {
map: function (iter, fn, sep) map: function (iter, fn, sep)
{ {
if (fn.length > 1) if (iter.length) /* Kludge? */
{
iter = Iterator(iter);
let oldfn = fn;
fn = function (x) oldfn.apply(null, x);
}
else if (iter.length) /* Kludge? */
iter = liberator.util.arrayIter(iter); iter = liberator.util.arrayIter(iter);
let ret = <></>; let ret = <></>;
let n = 0; let n = 0;
for each (let i in iter) for each (let i in Iterator(iter))
{ {
let val = fn(i); let val = fn(i);
if (val == undefined) if (val == undefined)
@@ -215,12 +209,26 @@ liberator.template = {
this.map(iter, function (row) this.map(iter, function (row)
<tr> <tr>
{ {
liberator.template.map(row, function (i, d) liberator.template.map(Iterator(row), function ([i, d])
<td style={style[i] || ""}>{d}</td>) <td style={style[i] || ""}>{d}</td>)
} }
</tr>) </tr>)
} }
</table>); </table>);
}, },
usage: function (iter)
{
return this.generic(
<table>
{
this.map(iter, function (item)
<tr>
<td class="hl-Title" style="padding-right: 20px">{item.name || item.names[0]}</td>
<td>{item.description}</td>
</tr>)
}
</table>);
},
}; };