mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 01:37:59 +01:00
Add machinery to allow app-specific help files.
--HG-- branch : xslt
This commit is contained in:
@@ -94,6 +94,11 @@ function Liberator()
|
|||||||
{
|
{
|
||||||
this.wrappedJSObject = this;
|
this.wrappedJSObject = this;
|
||||||
|
|
||||||
|
this.__defineGetter__("helpNamespaces", function () NAMESPACES ? NAMESPACES.slice() : null);
|
||||||
|
this.__defineSetter__("helpNamespaces", function (namespaces) {
|
||||||
|
if (!NAMESPACES)
|
||||||
|
NAMESPACES = Array.slice(namespaces)
|
||||||
|
});
|
||||||
this.__defineGetter__("helpFiles", function () HELP_FILES ? HELP_FILES.slice() : null);
|
this.__defineGetter__("helpFiles", function () HELP_FILES ? HELP_FILES.slice() : null);
|
||||||
this.__defineSetter__("helpFiles", function (files) {
|
this.__defineSetter__("helpFiles", function (files) {
|
||||||
if (!HELP_FILES)
|
if (!HELP_FILES)
|
||||||
@@ -124,8 +129,10 @@ function Liberator()
|
|||||||
catch (e) {}
|
catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const HELP_TAGS = {};
|
const self = this;
|
||||||
this.HELP_TAGS = HELP_TAGS;
|
this.HELP_TAGS = {};
|
||||||
|
this.FILE_MAP = {};
|
||||||
|
var NAMESPACES = null;
|
||||||
var HELP_FILES = null;
|
var HELP_FILES = null;
|
||||||
|
|
||||||
function parseHelpTags(files)
|
function parseHelpTags(files)
|
||||||
@@ -134,12 +141,26 @@ function Liberator()
|
|||||||
XSLT.importStylesheet(httpGet("chrome://liberator/content/help.xsl").responseXML);
|
XSLT.importStylesheet(httpGet("chrome://liberator/content/help.xsl").responseXML);
|
||||||
for each (let file in files)
|
for each (let file in files)
|
||||||
{
|
{
|
||||||
let res = httpGet("liberator://help/" + file);
|
try
|
||||||
if (res)
|
|
||||||
{
|
{
|
||||||
let doc = XSLT.transformToDocument(res.responseXML);
|
for each (let namespace in NAMESPACES)
|
||||||
for (let elem in xpath(doc, "//liberator:tag/text()"))
|
{
|
||||||
HELP_TAGS[elem.textContent] = file;
|
let url = ["chrome://", namespace, "/locale/", file, ".xml"].join("");
|
||||||
|
let res = httpGet(url);
|
||||||
|
if (res && res.responseXML.documentElement.localName == "document")
|
||||||
|
{
|
||||||
|
self.FILE_MAP[file] = url;
|
||||||
|
let doc = XSLT.transformToDocument(res.responseXML);
|
||||||
|
for (let elem in xpath(doc, "//liberator:tag/text()"))
|
||||||
|
self.HELP_TAGS[elem.textContent] = file;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
Components.utils.reportError(e);
|
||||||
|
dump(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HELP_FILES = Array.slice(files);
|
HELP_FILES = Array.slice(files);
|
||||||
@@ -184,14 +205,19 @@ Liberator.prototype = {
|
|||||||
switch(uri.host)
|
switch(uri.host)
|
||||||
{
|
{
|
||||||
case "help":
|
case "help":
|
||||||
return makeChannel("chrome://liberator/locale" + uri.path.replace(/#.*/, "") + ".xml", uri);
|
let url = this.FILE_MAP[uri.path.replace(/^\/|#.*/g, "")];
|
||||||
|
dump("name: " + uri.path.replace(/#.*/, "") + "\n");
|
||||||
|
dump("uri: " + url + "\n");
|
||||||
|
if (!url)
|
||||||
|
break;
|
||||||
|
return makeChannel(url, uri);
|
||||||
case "help-tag":
|
case "help-tag":
|
||||||
let tag = uri.path.substr(1);
|
let tag = uri.path.substr(1);
|
||||||
if (tag in this.HELP_TAGS)
|
if (tag in this.HELP_TAGS)
|
||||||
return redirect("liberator://help/" + this.HELP_TAGS[tag] + "#" + tag, uri);
|
return redirect("liberator://help/" + this.HELP_TAGS[tag] + "#" + tag, uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) { dump(e + "\n"); dump(e.stack); }
|
catch (e) {}
|
||||||
return fakeChannel(uri);
|
return fakeChannel(uri);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<xsl:output method="xml"/>
|
<xsl:output method="xml"/>
|
||||||
|
|
||||||
<xsl:variable name="local" select="concat('chrome://&liberator.name;/locale/', /liberator:document/@name, '.xml')"/>
|
<xsl:variable name="local" select="concat('chrome://&liberator.name;/locale/', /liberator:document/@name, '.xml')"/>
|
||||||
<xsl:variable name="localdoc" select="document($local)/liberator:document"/>
|
<xsl:variable name="localdoc" select="document($local)/liberator:overlay"/>
|
||||||
|
|
||||||
<xsl:template match="liberator:document">
|
<xsl:template match="liberator:document">
|
||||||
<html:html liberator:highlight="Help">
|
<html:html liberator:highlight="Help">
|
||||||
@@ -156,6 +156,12 @@
|
|||||||
</xsl:for-each>
|
</xsl:for-each>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
|
<xsl:template match="liberator:document/liberator:tags|liberator:document/liberator:tag">
|
||||||
|
<xsl:call-template name="splice-locals">
|
||||||
|
<xsl:with-param name="tag" select="substring-before(concat(., ' '), ' ')"/>
|
||||||
|
<xsl:with-param name="elem" select="self::node()"/>
|
||||||
|
</xsl:call-template>
|
||||||
|
</xsl:template>
|
||||||
<xsl:template match="liberator:document/*[liberator:tags]">
|
<xsl:template match="liberator:document/*[liberator:tags]">
|
||||||
<xsl:call-template name="splice-locals">
|
<xsl:call-template name="splice-locals">
|
||||||
<xsl:with-param name="tag" select="substring-before(concat(liberator:tags, ' '), ' ')"/>
|
<xsl:with-param name="tag" select="substring-before(concat(liberator:tags, ' '), ' ')"/>
|
||||||
|
|||||||
@@ -1724,6 +1724,7 @@ const liberator = (function () //{{{
|
|||||||
let start = Date.now();
|
let start = Date.now();
|
||||||
liberator.log("Initializing liberator object...", 0);
|
liberator.log("Initializing liberator object...", 0);
|
||||||
|
|
||||||
|
services.get("liberator:").helpNamespaces = [config.name.toLowerCase(), "liberator"];
|
||||||
services.get("liberator:").helpFiles = config.helpFiles.map(function (f) f.replace(/\..*/, ""));
|
services.get("liberator:").helpFiles = config.helpFiles.map(function (f) f.replace(/\..*/, ""));
|
||||||
|
|
||||||
config.features.push(getPlatformFeature());
|
config.features.push(getPlatformFeature());
|
||||||
|
|||||||
Reference in New Issue
Block a user