liberator.template = { add: function (a, b) a + b, join: function (c) function (a, b) a + c + b, map: function (iter, fn, sep) { if (iter.length) /* Kludge? */ iter = liberator.util.arrayIter(iter); let ret = <>; let n = 0; for each (let i in iter) { let val = fn(i); if (val == undefined) continue; if (sep && n++) ret += sep; ret += val; } 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) { if (typeof xml == "xml") return xml; try { return new XMLList(xml); } catch (e) {} return <>{xml}; }, // if "processStrings" is true, any passed strings will be surrounded by " and // any line breaks are displayed as \n highlight: function (arg, processStrings) { // some objects like window.JSON or getBrowsers()._browsers need the try/catch try { switch (arg == null ? "undefined" : typeof arg) { case "number": return {arg}; case "string": if (processStrings) arg = <>{liberator.util.escapeString(arg)}; return {arg}; case "boolean": return {arg}; case "function": return {arg}; return {String(arg).replace(/\{(.|\n)*/, "{ ... }")}; /* } vim */ case "undefined": return {arg}; case "object": // for java packages value.toString() would crash so badly // that we cannot even try/catch it if (/^\[JavaPackage.*\]$/.test(arg)) return <>[JavaPackage]; return <>{arg}; default: return ]]>; } } catch (e) { return]]>; } }, highlightFilter: function (str, filter) { let lcstr = str.toLowerCase(); let lcfilter = filter.toLowerCase(); let s = <>; let start = 0; let i; while ((i = lca.indexOf(lcfilter, start)) > -1) { s += <>{str.substring(start, i)}; s += {str.substr(i, filter.length)}; start = i + filter.length; } return s + <>{str.substr(start)}; }, highlightURL: function (str, force) { if (force || /^[a-zA-Z]+:\/\//.test(str)) return {str}; else return str; }, generic: function (xml) { return <>:{liberator.commandline.getCommand()}
+ xml; }, 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]}, /* Non-breaking space */) }) }
); }, 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}
); }, options: function (title, opts) { return this.generic( { this.map(opts, function (opt) ) }
--- {title} ---
{opt.pre}{opt.name}{opt.value} {opt.isDefault || opt.default == null ? "" : (default: {opt.default})}
); }, table: function (title, data, indent) { let table = { this.map(data, function (datum) ) }
{title}
{datum[0]} {liberator.template.maybeXML(datum[1])}
; if (table.tr.length() > 1) return table; }, tabular: function (headings, style, iter) { /* This might be mind-bogglingly slow. We'll see. */ return this.generic( { this.map(headings, function (h) ) } { this.map(iter, function (row) { liberator.template.map2(row, function (i, d) ) } ) }
{h}
{d}
); }, };