diff --git a/content/bookmarks.js b/content/bookmarks.js index 304eb37f..83f42643 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -233,7 +233,7 @@ liberator.Bookmarks = function () //{{{ var sh = getWebNavigation().sessionHistory; let entries = [sh.getEntryAtIndex(i, false) for (i in liberator.util.range(0, sh.count))]; - let list = liberator.buffer.template.jumps(sh.index, entries); + let list = liberator.template.jumps(sh.index, entries); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); }, { argCount: "0" }); @@ -482,7 +482,7 @@ liberator.Bookmarks = function () //{{{ if (openItems) return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB); - let list = liberator.buffer.template.bookmarks("title", ( + let list = liberator.template.bookmarks("title", ( { url: item[0], title: item[1], @@ -767,7 +767,7 @@ liberator.History = function () //{{{ } else { - let list = liberator.buffer.template.bookmarks("title", ( + let list = liberator.template.bookmarks("title", ( { title: item[1], url: item[0], @@ -942,7 +942,7 @@ liberator.QuickMarks = function () //{{{ } let items = ({title: mark, url: qmarks.get(mark)} for each (mark in marks)); - let list = liberator.buffer.template.bookmarks("QuickMark", items); + let list = liberator.template.bookmarks("QuickMark", items); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); } }; diff --git a/content/buffer.js b/content/buffer.js index 0144a6af..ca3a6ee4 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -1289,7 +1289,7 @@ liberator.Buffer = function () //{{{ { let opt = options[option]; if (opt && opt[0].length > 0) - pageInfoText += br + liberator.buffer.template.table(opt[1], opt[0]); + pageInfoText += br + liberator.template.table(opt[1], opt[0]); if (!br) br = "
"; } @@ -1297,117 +1297,6 @@ liberator.Buffer = function () //{{{ liberator.echo(pageInfoText, liberator.commandline.FORCE_MULTILINE); }, - template: - { - add: function (a, b) a + b, - join: function (c) function (a, b) a + c + b, - maybeXML: function (xml) - { - try - { - return new XML(xml) - } - catch (e) {} - return xml; - }, - - generic: function (xml) - { - return (<>:{liberator.commandline.getCommand()}
+ xml).toXMLString(); - }, - - bookmarks: function (header, items) - { - XML.prettyPrinting = false; - return this.generic( - - - - - {[ - - - - - for each (item in items)].reduce(this.add, <>) - } -
{header}URL
{liberator.util.clip(item.title, 50)} - {item.url}  - { - (item.extra && item.extra.length) ? - - ({ - [<>{e[0]}: {e[1]} - for each (e in item.extra)].reduce(this.join(<> )) - }) - - : "" - } -
); - }, - - jumps: function (index, elems) - { - XML.prettyPrinting = false; - return this.generic( - - - - - {[ - - - - - - - for ([idx, val] in Iterator(elems))].reduce(this.add, <>) - } -
jumptitleURI
{idx == index ? {">"} : ""} {Math.abs(idx - index)}{val.title}{val.URI.spec}
); - }, - - marks: function (marks) - { - XML.prettyPrinting = false; - return this.generic( - - - - - - - - {[ - - - - - - - for each (mark in marks)].reduce(this.add, <>) - } -
marklinecolfile
{mark[0]}{Math.round(mark[1].position.y * 100)}%{Math.round(mark[1].position.x * 100)}%{mark[1].location}
); - }, - - table: function (title, data) - { - XML.prettyPrinting = false; - return this.generic( - - - - - { - [ - - - - for each (datum in data)].reduce(this.add, <>) - } -
{title}
{datum[0]}{this.maybeXML(datum[1])}
); - } - }, - viewSelectionSource: function () { // copied (and tuned somebit) from browser.jar -> nsContextMenu.js @@ -1812,7 +1701,7 @@ liberator.Marks = function () //{{{ } } - var list = liberator.buffer.template.marks(marks); + var list = liberator.template.marks(marks); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); } @@ -1820,4 +1709,150 @@ liberator.Marks = function () //{{{ //}}} }; //}}} +liberator.template = { + add: function (a, b) a + b, + join: function (c) function (a, b) a + c + b, + + map: function (iter, fn, sep) + { + if (sep == undefined) + sep = <>; + let ret = <>; + let n = 0; + for each (let i in iter) { + if (n++) + ret += sep; + ret += fn(i); + } + return ret; + }, + map2: function (iter, fn, sep) + { + // Could cause performance problems. + return this.map(Iterator(iter), function (x) fn.apply(null, x), sep); + }, + + maybeXML: function (xml) + { + try + { + return new XML(xml) + } + catch (e) {} + return xml; + }, + + generic: function (xml) + { + XML.prettyPrinting = false; + return (<>:{liberator.commandline.getCommand()}
+ xml).toXMLString(); + }, + + bookmarks: function (header, items) + { + return this.generic( + + + + + { + this.map(items, function (item) + + + + ) + } +
{header}URL
{liberator.util.clip(item.title, 50)} + {item.url}  + { + !(item.extra && item.extra.length) ? "" : + + ({ + liberator.template.map(item.extra, function (e) + <>{e[0]}: {e[1]}, + <> ) + }) + + } +
); + }, + + jumps: function (index, elems) + { + return this.generic( + + + + + { + this.map2(elems, function (idx, val) + + + + + + ) + } +
jumptitleURI
{idx == index ? {">"} : ""} {Math.abs(idx - index)}{val.title}{val.URI.spec}
); + }, + + marks: function (marks) + { + return this.generic( + + + + + + + + { + this.map(marks, function (mark) + + + + + + ) + } +
marklinecolfile
{mark[0]}{Math.round(mark[1].position.y * 100)}%{Math.round(mark[1].position.x * 100)}%{mark[1].location}
); + }, + + options: function (title, opts) + { + return liberator.template.generic( + + + + + { + liberator.template.map(opts, function (opt) + + + ) + } +
--- {title} ---
+ {opt.pre}{opt.name}{opt.value} + {opt.isDefault || opt.default == null ? "" : (default: {opt.default})} +
); + }, + + table: function (title, data) + { + return this.generic( + + + + + { + this.map(data, function(datum) + + + + ) + } +
{title}
{datum[0]}{this.maybeXML(datum[1])}
); + } +}; + // vim: set fdm=marker sw=4 ts=4 et: diff --git a/content/commands.js b/content/commands.js index d862c5a6..b6a8d402 100644 --- a/content/commands.js +++ b/content/commands.js @@ -698,20 +698,20 @@ liberator.Commands = function () //{{{ if (cmdlist.length > 0) { XML.prettyPrinting = false; - var str = liberator.buffer.template.generic( + var str = liberator.template.generic( - {[ + { + liberator.template.map(cmdlist, function (cmd) - - for each (cmd in cmdlist)].reduce(liberator.buffer.template.add, <>) + ) }
Name Args Definition
{cmd.name} * {cmd.replacementText || "function () { ... }"}
); liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); diff --git a/content/events.js b/content/events.js index a6513ec2..6f859254 100644 --- a/content/events.js +++ b/content/events.js @@ -205,23 +205,21 @@ liberator.AutoCommands = function () //{{{ let cmds = (item for (item in Iterator(autoCommands)) if ((!auEvent || item[0] == auEvent) && item[1].length)); - // Okay, maybe a bit scary. --Kris - XML.prettyPrinting = false; - var list = liberator.buffer.template.generic( + var list = liberator.template.generic( - {[ + { + liberator.template.map2(cmds, function (event, items) - + [ - - - - for each (item in items)].reduce(liberator.buffer.template.add) - for ([event, items] in cmds)].reduce(liberator.buffer.template.add, <>) + + liberator.template.map(items, function (item) + + + + )) }
----- Auto Commands -----
{event}
 {item[0]}{item[1]}
 {item[0]}{item[1]}
); @@ -669,13 +667,13 @@ liberator.Events = function () //{{{ { XML.prettyPrinting = false; var str = - {[ + { + liberator.template.map2(liberator.events.getMacros(args), + function(macro, keys) - - for ([macro, keys] in Iterator(liberator.events.getMacros(args))) - ].reduce(liberator.buffer.template.add, <>) + ) }
{macro} {keys}
.toXMLString(); liberator.echo(str, liberator.commandline.FORCE_MULTILINE); diff --git a/content/io.js b/content/io.js index 5fa67c1a..a71670f0 100644 --- a/content/io.js +++ b/content/io.js @@ -317,12 +317,12 @@ liberator.IO = function () //{{{ XML.prettyPrinting = false; var list = - {[ + { + liberator.template.map2(scriptNames, function (i, name) - - for ([i, name] in Iterator(striptNames))].reduce(liberator.buffer.template.add, <>) + ) }
{i+1} {name}
.toXMLString(); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); diff --git a/content/liberator.js b/content/liberator.js index dcf237e7..b3eff8c1 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -276,12 +276,12 @@ const liberator = (function () //{{{ // TODO: clicking on these should open the help XML.prettyPrinting = false; var usage = - {[ + { + liberator.template.map(liberator.commands, function (command) - - for each (command in liberator.commands)].reduce(liberator.buffer.template.add) + ) }
{command.name} {command.description}
.toXMLString(); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); @@ -428,8 +428,7 @@ const liberator = (function () //{{{ var totalUnits = "msec"; } - XML.prettyPrinting = false; - var str = liberator.buffer.template.generic( + var str = liberator.template.generic( @@ -501,12 +500,12 @@ const liberator = (function () //{{{ // TODO: clicking on these should open the help XML.prettyPrinting = false; var usage =
Code execution summary
- {[ + { + liberator.template.add(liberator.mappings, function (mapping) - - for each (mapping in liberator.mappings)].reduce(liberator.buffer.template.add) + ) }
{mapping.names[0]} {mapping.description}
.toXMLString(); diff --git a/content/mappings.js b/content/mappings.js index da7061a7..908b8bcc 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -419,15 +419,14 @@ liberator.Mappings = function () //{{{ if (output[i])); XML.prettyPrinting = false; let list = - {[ - [ + { + liberator.template.map(_maps, function (map) + liberator.template.map(map.names, function (name) - - for each (name in map.names)].reduce(liberator.buffer.template.add) - for each (map in _maps)].reduce(liberator.buffer.template.add) + )) }
{modeSign} {name} {map.noremap ? "*" : " "} {map.rhs || "function () { ... }"}
diff --git a/content/options.js b/content/options.js index 149bb93a..dbd1f3b2 100644 --- a/content/options.js +++ b/content/options.js @@ -240,27 +240,6 @@ liberator.Options = function () //{{{ } } - function echoOptions(title, opts) { - XML.prettyPrinting = false; - let list = liberator.buffer.template.generic( - - - - - {[ - - - - for each (opt in opts)].reduce(liberator.buffer.template.add, <>) - } -
--- {title} ---
- {opt.pre}{opt.name}{opt.value} - {opt.isDefault || opt.default == null ? "" : (default: {opt.default})} -
); - - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); - } - // // firefox preferences which need to be changed to work well with vimperator // @@ -888,7 +867,8 @@ liberator.Options = function () //{{{ } } - echoOptions("Options", opts()); + let list = liberator.template.options("Options", opts()); + liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); }, listPrefs: function (onlyNonDefault, filter) @@ -921,7 +901,8 @@ liberator.Options = function () //{{{ } } - echoOptions(liberator.config.hostApplication + " Options", prefs()); + let list = liberator.template.options(liberator.config.hostApplication + " Options", prefs()); + liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); }, get store() liberator.storage.options, diff --git a/content/tabs.js b/content/tabs.js index 209b84fa..d4e45032 100644 --- a/content/tabs.js +++ b/content/tabs.js @@ -711,7 +711,6 @@ liberator.Tabs = function () //{{{ { // TODO: move this to liberator.tabs.get() - XML.prettyPrinting = false; let items = <>; for (let [i, item] in Iterator(liberator.completion.buffer("")[1])) { @@ -732,7 +731,7 @@ liberator.Tabs = function () //{{{ ; } - let list = liberator.buffer.template.generic({items}
); + let list = liberator.template.generic({items}
); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); },