1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-31 03:32:38 +01:00

Death to E4X and stuff.

This commit is contained in:
Kris Maglione
2012-11-30 20:46:38 -08:00
parent dff13c70fc
commit da3785028d
6 changed files with 138 additions and 30 deletions

View File

@@ -103,7 +103,6 @@ var AutoCommands = Module("autocommands", {
return cmds;
}
XML.prettyPrinting = XML.ignoreWhitespace = false;
let table = (
["table", {},
["tr", { highlight: "Title" },

View File

@@ -8,10 +8,6 @@
/** @scope modules */
default xml namespace = XHTML;
XML.ignoreWhitespace = false;
XML.prettyPrinting = false;
var EVAL_ERROR = "__dactyl_eval_error";
var EVAL_RESULT = "__dactyl_eval_result";
var EVAL_STRING = "__dactyl_eval_string";
@@ -656,12 +652,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
help.initialize();
},
stringifyXML: function (xml) {
XML.prettyPrinting = false;
XML.ignoreWhitespace = false;
return UTF8(xml.toXMLString());
},
/**
* Generates a help entry and returns it as a string.
*
@@ -773,6 +763,105 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
.replace(/^ {12}|[ \t]+$/gm, "")
.replace(/^\s*\n|\n\s*$/g, "") + "\n";
},
_generateHelp: function generateHelp(obj, extraHelp, str, specOnly) {
// E4X-FIXME
let link, tag, spec;
link = tag = spec = util.identity;
let args = null;
if (obj instanceof Command) {
link = function (cmd) ["ex", {}, cmd];
args = obj.parseArgs("", CompletionContext(str || ""));
tag = function (cmd) DOM.DOMString(":" + cmd);
spec = function (cmd) [
obj.count ? ["oa", {}, "count"] : [],
cmd,
obj.bang ? ["oa", {}, "!"] : []
];
}
else if (obj instanceof Map) {
spec = function (map) obj.count ? [["oa", {}, "count"], map] : DOM.DOMString(map);
tag = function (map) [
let (c = obj.modes[0].char) c ? c + "_" : "",
map
]
link = function (map) {
let [, mode, name, extra] = /^(?:(.)_)?(?:<([^>]+)>)?(.*)$/.exec(map);
let k = ["k", {}, extra];
if (name)
k[1].name = name;
if (mode)
k[1].mode = mode;
return k;
};
}
else if (obj instanceof Option) {
spec = function () template_.map(obj.names, tag, " ");
tag = function (name) DOM.DOMString("'" + name + "'");
link = function (opt, name) ["o", {}, name];
args = { value: "", values: [] };
}
let br = "\n\
";
let res = [
["dt", {}, link(obj.helpTag || tag(obj.name), obj.name)], " ",
["dd", {},
template_.linkifyHelp(obj.description ? obj.description.replace(/\.$/, "") : "", true)]];
if (specOnly)
return res;
res.push(
["item", {},
["tags", {}, template_.map(obj.names.slice().reverse(),
tag,
" ")],
["spec", {},
let (name = (obj.specs || obj.names)[0])
spec(template_.highlightRegexp(tag(name),
/\[(.*?)\]/g,
function (m, n0) ["oa", {}, n0]),
name)],
!obj.type ? "" : [
["type", {}, obj.type],
["default", {}, obj.stringDefaultValue],
["description", {},
obj.description ? /*br*/ ["p", {}, template_.linkifyHelp(obj.description.replace(/\.?$/, "."), true)] : "",
extraHelp ? /*br*/ extraHelp : "",
!(extraHelp || obj.description) ? /*br*/ ["p", {}, /*L*/ "Sorry, no help available."] : ""]]]);
function add(ary) {
res.item.description.* += br +
let (br = br + " ")
["dl", {}, /*br*/ template_.map(ary,
function ([a, b]) [["dt", {}, a], " ",
["dd", {}, b]],
br)]
}
if (obj.completer && false)
add(completion._runCompleter(obj.closure.completer, "", null, args).items
.map(function (i) [i.text, i.description]));
if (obj.options && obj.options.some(function (o) o.description) && false)
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], ", "),
")"]]
]));
util.dump(util.prettifyJSON(res, null, true));
return DOM.toXML(res)
.replace(' xmlns="' + NS + '"', "", "g")
.replace(/^ {12}|[ \t]+$/gm, "")
.replace(/^\s*\n|\n\s*$/g, "") + "\n";
},
/**
* The map of global variables.
@@ -1232,7 +1321,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
cache: function initCache() {
cache.register("help/plugins.xml", function () {
// Process plugin help entries.
XML.ignoreWhiteSpace = XML.prettyPrinting = false;
let body = [];
for (let [, context] in Iterator(plugins.contexts))
@@ -1249,10 +1337,28 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
if (elem[attr].length())
info[attr] = elem[attr];
}
body.push(["h2", { xmlns: NS.uri, tag: info.@name + '-plugin' },
body.push(["h2", { xmlns: "dactyl", tag: info.@name + '-plugin' },
String(info.@summary)]);
body.push(info);
}
else if (DOM.isJSONXML(info)) {
let langs = info.slice(2).filter(function (e) isArray(e) && isObject(e[1]) && e[1].leng);
if (langs) {
let lang = config.bestLocale(l[1].lang for each (l in langs));
info = info.slice(0, 2).concat(
info.slice(2).filter(function (e) !isArray(e) || !isObject(e[1])
|| e[1].lang == lang));
for each (let elem in info.slice(2).filter(function (e) isArray(e) && e[0] == "info" && isObject(e[1])))
for (let attr in values(["name", "summary", "href"]))
if (attr in elem[1])
info[attr] = elem[1][attr];
}
body.push(["h2", { xmlns: "dactyl", tag: info.name + '-plugin' },
String(info.summary)]);
body.push(info);
}
}
catch (e) {
util.reportError(e);

View File

@@ -4,7 +4,7 @@
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
/* use strict */
"use strict";
/** @scope modules */
@@ -532,23 +532,23 @@ var Modes = Module("modes", {
for (let base in values(mode.bases))
tree[base.name][mode.name] = tree[mode.name];
let roots = iter([m.name, tree[m.name]] for (m in values(list)) if (!m.bases.length)).toObject();
let roots = iter([m.name, tree[m.name]]
for (m in values(list))
if (!m.bases.length)).toObject();
default xml namespace = NS;
function rec(obj) {
XML.ignoreWhitespace = XML.prettyPrinting = false;
let res = <ul dactyl:highlight="Dense" xmlns:dactyl={NS}/>;
let res = ["ul", { "dactyl:highlight": "Dense" }];
Object.keys(obj).sort().forEach(function (name) {
let mode = modes.getMode(name);
res.* += <li><em>{mode.displayName}</em>: {mode.description}{
rec(obj[name])
}</li>;
res.push(["li", {},
["em", {}, mode.displayName],
": ", mode.description,
rec(obj[name])]);
});
if (res.*.length())
if (res.length > 2)
return res;
return <></>;
return [];
}
return rec(roots);

View File

@@ -50,7 +50,6 @@ var StatusLine = Module("statusline", {
*/));
}
XML.ignoreWhitespace = true;
let _commandline = "if (window.dactyl) return dactyl.modules.commandline";
let prepend = [
["button", { id: "appmenu-button", label: "", image: "chrome://branding/content/icon16.png", highlight: "AppmenuButton", xmlns: "xul" }],

View File

@@ -483,10 +483,10 @@ var Contexts = Module("contexts", {
getDocs: function getDocs(context) {
try {
if (isinstance(context, ["Sandbox"])) {
let info = "INFO" in context && Cu.evalInSandbox("this.INFO instanceof XML && INFO.toXMLString()", context);
return info && XML(info);
let info = "INFO" in context && Cu.evalInSandbox("this.INFO instanceof XML ? INFO.toXMLString() : this.INFO", context);
return /^</.test(info) ? XML(info) : info;
}
if (typeof context.INFO == "xml")
if (typeof context.INFO == "xml" || DOM.isJSONXML(context.INFO))
return context.INFO;
}
catch (e) {}

View File

@@ -50,8 +50,12 @@ function NetError(orig, error) {
}).data.QueryInterface(Ci.nsIChannel);
}
function RedirectChannel(to, orig, time, message) {
let html = <html><head><meta http-equiv="Refresh" content={(time || 0) + ";" + to}/></head>
<body><h2 style="text-align: center">{message || ""}</h2></body></html>.toXMLString();
let html = DOM.toXML(
["html", {},
["head", {},
["meta", { "http-equiv": "Refresh", content: (time || 0) + ";" + to }]],
["body", {},
["h2", { style: "text-align: center" }, message || ""]]]);
return StringChannel(html, "text/html", services.io.newURI(to, null, null));
}