1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-08 05:04:12 +01:00

Replace asciidoc with native XSLT transforms.

--HG--
branch : xslt
rename : common/Makefile.common => common/Makefile
rename : vimperator/components/about-handler.js => common/components/about-handler.js
rename : vimperator/components/chrome-data.js => common/components/chrome-data.js
rename : vimperator/components/commandline-handler.js => common/components/commandline-handler.js
This commit is contained in:
Kris Maglione
2009-10-21 04:46:29 -04:00
parent 2add32c3f2
commit 0d44d919bc
75 changed files with 7363 additions and 5466 deletions

View File

@@ -233,7 +233,10 @@ CompletionContext.prototype = {
if (!context.hasItems)
return [];
let prefix = self.value.substring(minStart, context.offset);
return context.items.map(function makeItem(item) ({ text: prefix + item.text, item: item.item }));
return context.items.map(function (item) {
item.text = prefix + item.text;
return item;
});
});
return { start: minStart, items: util.Array.flatten(items), longestSubstring: this.longestAllSubstring };
}

View File

@@ -1,17 +1,22 @@
// Copyright (c) 2009 by Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2009 by Kris Maglione <kris@vimperator.org>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
const win = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Ci.nsIWindowWatcher)
.activeWindow;
const liberator = win.liberator;
function checkFragment()
{
document.title = document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "title")[0].textContent;
var frag = document.location.hash.substr(1);
var elem = document.getElementById(frag);
if (elem)
window.content.scrollTo(0, window.content.scrollY + elem.getBoundingClientRect().top - 10); // 10px context
}
let page = liberator.findHelp(decodeURIComponent(document.location.search.substr(1)));
let url = page ? "chrome://liberator/locale/" + page : content.history.previous;
win.getBrowser().loadURIWithFlags(url, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY, null, null, null);
document.addEventListener("load", checkFragment, true);
window.addEventListener("message", function (event) {
if (event.data == "fragmentChange")
checkFragment();
}, true);
// vim: set fdm=marker sw=4 ts=4 et:

143
common/content/help.xsl Normal file
View File

@@ -0,0 +1,143 @@
<xsl:stylesheet version="1.0"
xmlns="http://vimperator.org/namespaces/liberator"
xmlns:liberator="http://vimperator.org/namespaces/liberator"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="str">
<xsl:output method="xml"/>
<xsl:template match="liberator:document">
<html:html liberator:highlight="Help">
<html:head>
<html:title><xsl:value-of select="@title"/></html:title>
<html:base href="liberator://help/{@name}"/>
<html:script type="text/javascript"
src="chrome://liberator/content/help.js"/>
</html:head>
<html:body liberator:highlight="HelpBody">
<html:div class="liberator-logo"/>
<xsl:call-template name="parse-tags">
<xsl:with-param name="text" select="concat(@name, '.html')"/>
</xsl:call-template>
<xsl:apply-templates/>
</html:body>
</html:html>
</xsl:template>
<xsl:template match="liberator:include">
<xsl:apply-templates select="document(@href)/liberator:document/node()"/>
</xsl:template>
<xsl:template match="liberator:dl">
<xsl:copy>
<column/>
<column/>
<xsl:for-each select="liberator:dt">
<tr>
<xsl:apply-templates select="."/>
<xsl:apply-templates select="following-sibling::liberator:dd[position()=1]"/>
</tr>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="liberator:tags">
<xsl:call-template name="parse-tags">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="parse-tags">
<xsl:param name="text"/>
<tags>
<xsl:for-each select="str:tokenize($text)">
<html:a id="{.}"><tag><xsl:value-of select="."/></tag></html:a>
</xsl:for-each>
</tags>
</xsl:template>
<xsl:template match="liberator:default[not(@type='plain')]">
<xsl:variable name="type" select="preceding-sibling::liberator:type[1] | following-sibling::liberator:type[1]"/>
<xsl:copy>
<xsl:choose>
<xsl:when test="starts-with($type, 'string')">
<str><xsl:apply-templates/></str>
</xsl:when>
<xsl:otherwise>
<span>
<xsl:choose>
<xsl:when test="$type = 'boolean'">
<xsl:attribute name="highlight" namespace="http://vimperator.org/namespaces/liberator">Boolean</xsl:attribute>
</xsl:when>
<xsl:when test="$type = 'number'">
<xsl:attribute name="highlight" namespace="http://vimperator.org/namespaces/liberator">Number</xsl:attribute>
</xsl:when>
<xsl:when test="$type = 'charlist'">
<xsl:attribute name="highlight" namespace="http://vimperator.org/namespaces/liberator">String</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:apply-templates/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template name="linkify-tag">
<xsl:param name="contents"/>
<xsl:variable name="tag" select="str:tokenize($contents, ' [')[1]"/>
<html:a href="liberator://help-tag/{$tag}" style="color: inherit">
<xsl:if test="
//liberator:tags[contains(concat(' ', ., ' '), concat(' ', $tag, ' '))] |
//liberator:tag[contains(concat(' ', ., ' '), concat(' ', $tag, ' '))] |
//@tag[contains(concat(' ', ., ' '), concat(' ', $tag, ' '))]">
<xsl:attribute name="href">#<xsl:value-of select="$tag"/></xsl:attribute>
</xsl:if>
<xsl:value-of select="$contents"/>
</html:a>
</xsl:template>
<xsl:template match="liberator:o">
<xsl:copy>
<xsl:call-template name="linkify-tag">
<xsl:with-param name="contents" select='concat("&#39;", text(), "&#39;")'/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template match="liberator:k">
<xsl:copy>
<xsl:call-template name="linkify-tag">
<xsl:with-param name="contents" select="text()"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template match="liberator:k[@name]">
<xsl:copy>
<xsl:call-template name="linkify-tag">
<xsl:with-param name="contents" select="concat('&lt;', @name, '>', .)"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template match="liberator:ex">
<xsl:copy>
<xsl:call-template name="linkify-tag">
<xsl:with-param name="contents" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template match="liberator:tag|@tag">
<xsl:call-template name="parse-tags">
<xsl:with-param name="text"><xsl:value-of select="."/></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<!-- vim:se ft=xslt sts=4 sw=4 et: -->

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript;version=1.8"
src="chrome://liberator/content/help.js"/>
</window>

View File

@@ -310,8 +310,7 @@ const liberator = (function () //{{{
function ()
{
liberator.open("chrome://mozapps/content/extensions/extensions.xul",
(options["newtab"] && options.get("newtab").has("all", "addons"))
? liberator.NEW_TAB: liberator.CURRENT_TAB);
{ from: "addons" });
},
{ argCount: "0" });
@@ -487,9 +486,7 @@ const liberator = (function () //{{{
if (args.bang)
window.openDialog(extension.options, "_blank", "chrome");
else
liberator.open(extension.options,
options.get("newtab").has("all", "extoptions")
? liberator.NEW_TAB : liberator.CURRENT_TAB);
liberator.open(extension.options, { from: "extoptions" });
},
{
argCount: "1",
@@ -577,8 +574,7 @@ const liberator = (function () //{{{
if (args.bang) // open JavaScript console
{
liberator.open("chrome://global/content/console.xul",
(options["newtab"] && options.get("newtab").has("all", "javascript"))
? liberator.NEW_TAB : liberator.CURRENT_TAB);
{ from: "javascript" });
}
else
{
@@ -848,19 +844,9 @@ const liberator = (function () //{{{
context.title = ["Help"];
context.anchored = false;
context.key = unchunked;
context.generate = function ()
{
let files = unchunked ? ["all.html"] : config.helpFiles;
let res = files.map(function (file) {
let resp = util.httpGet("chrome://liberator/locale/" + file);
if (!resp)
return [];
let doc = resp.responseXML;
return Array.map(doc.getElementsByClassName("tag"),
function (elem) [elem.textContent, file]);
});
return util.Array.flatten(res);
};
context.completions = services.get("liberator:").HELP_TAGS;
if (unchunked)
context.keys = { text: "text", description: function () "all" };
};
completion.menuItem = function menuItem(context) {
@@ -941,10 +927,10 @@ const liberator = (function () //{{{
getExtension: function (name) this.extensions.filter(function (e) e.name == name)[0],
// Global constants
CURRENT_TAB: 1,
NEW_TAB: 2,
NEW_BACKGROUND_TAB: 3,
NEW_WINDOW: 4,
CURRENT_TAB: [],
NEW_TAB: [],
NEW_BACKGROUND_TAB: [],
NEW_WINDOW: [],
forceNewTab: false,
forceNewWindow: false,
@@ -1371,23 +1357,22 @@ const liberator = (function () //{{{
findHelp: function (topic, unchunked)
{
unchunked = !!unchunked;
let items = completion.runCompleter("help", topic, null, unchunked);
let items = completion._runCompleter("help", topic, null, unchunked).items;
let partialMatch = null;
function format(item) item[1] + "#" + encodeURIComponent(item[0]);
function format(item) item.description + "#" + encodeURIComponent(item.text);
for (let [i, item] in Iterator(items))
{
if (item[0] == topic)
if (item.text == topic)
return format(item);
else if (!partialMatch && item[0].indexOf(topic) > -1)
else if (!partialMatch && topic)
partialMatch = item;
}
if (partialMatch)
return format(partialMatch);
else
return null;
return null;
},
/**
@@ -1400,15 +1385,11 @@ const liberator = (function () //{{{
*/
help: function (topic, unchunked)
{
let where = (options["newtab"] && options.get("newtab").has("all", "help"))
? liberator.NEW_TAB : liberator.CURRENT_TAB;
if (!topic && !unchunked)
{
let helpFile = options["helpfile"];
if (config.helpFiles.indexOf(helpFile) != -1)
liberator.open("chrome://liberator/locale/" + helpFile, where);
liberator.open("liberator://help/" + helpFile, { from: "help" });
else
liberator.echomsg("Sorry, help file " + helpFile.quote() + " not found");
return;
@@ -1418,8 +1399,8 @@ const liberator = (function () //{{{
if (page == null)
return void liberator.echoerr("E149: Sorry, no help for " + topic);
liberator.open("chrome://liberator/locale/" + page, where);
if (where == this.CURRENT_TAB)
liberator.open("liberator://help/" + page, { from: "help" });
if (options.get("activate").has("all", "help"))
content.postMessage("fragmentChange", "*");
},
@@ -1550,12 +1531,16 @@ const liberator = (function () //{{{
}
let flags = 0;
if (where instanceof Object)
if (where && !(where instanceof Array))
{
for (let [opt, flag] in Iterator({ replace: "REPLACE_HISTORY", hide: "BYPASS_HISTORY" }))
if (where[opt])
flags |= Ci.nsIWebNavigation["LOAD_FLAGS_" + flag];
where = liberator.CURRENT_TAB;
if ("from" in where)
where = (options["newtab"] && options.get("newtab").has("all", where.from))
? liberator.NEW_TAB : liberator.CURRENT_TAB;
else
where = where.where || liberator.CURRENT_TAB;
}
if (urls.length == 0)
@@ -1739,6 +1724,8 @@ const liberator = (function () //{{{
let start = Date.now();
liberator.log("Initializing liberator object...", 0);
services.get("liberator:").helpFiles = config.helpFiles.map(function (f) f.replace(/\..*/, ""));
config.features.push(getPlatformFeature());
try
@@ -1965,29 +1952,6 @@ const liberator = (function () //{{{
window.liberator = liberator;
// FIXME: Ugly, etc.
window.addEventListener("liberatorHelpLink", function (event) {
let elem = event.target;
if (/^(option|mapping|command|jump)$/.test(elem.className))
var tag = elem.textContent.replace(/\s.*/, "");
if (/^(mapping|command)$/.test(elem.className))
tag = tag.replace(/^\d+/, "");
if (elem.className == "command")
tag = tag.replace(/\[.*?\]/g, "").replace(/(\w+)!$/, "$1");
if (tag)
{
let page = liberator.findHelp(tag, /\/all.html($|#)/.test(elem.ownerDocument.location.href));
if (page)
elem.href = "chrome://liberator/locale/" + page;
}
// TODO: use HashChange event in Gecko 1.9.2
if (elem.href)
setTimeout(function () { content.postMessage("fragmentChange", "*"); }, 0);
}, true, true);
// called when the chrome is fully loaded and before the main window is shown
window.addEventListener("load", liberator.startup, false);
window.addEventListener("unload", liberator.shutdown, false);

View File

@@ -22,17 +22,19 @@ function Services()
function create(classes, ifaces, meth)
{
ifaces = Array.concat(ifaces);
try
{
let res = Cc[classes][meth || "getService"](ifaces.shift());
let res = Cc[classes][meth || "getService"]();
if (!ifaces)
return res.wrappedJSObject;
ifaces = Array.concat(ifaces);
ifaces.forEach(function (iface) res.QueryInterface(iface));
return res;
}
catch (e)
{
// liberator.log() is not defined at this time, so just dump any error
dump("Service creation failed for '" + classes + "': " + e);
dump("Service creation failed for '" + classes + "': " + e + "\n");
}
}
@@ -97,6 +99,7 @@ function Services()
self.add("extensionManager", "@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager);
self.add("favicon", "@mozilla.org/browser/favicon-service;1", Ci.nsIFaviconService);
self.add("json", "@mozilla.org/dom/json;1", Ci.nsIJSON, "createInstance");
self.add("liberator:", "@mozilla.org/network/protocol;1?name=liberator");
self.add("livemark", "@mozilla.org/browser/livemark-service;2", Ci.nsILivemarkService);
self.add("observer", "@mozilla.org/observer-service;1", Ci.nsIObserverService);
self.add("io", "@mozilla.org/network/io-service;1", Ci.nsIIOService);

View File

@@ -121,12 +121,79 @@ Highlights.prototype.CSS = <![CDATA[
HintActive,,* background-color: #88FF00; color: black;
HintImage,,* opacity: .5;
Help font-size: 8pt; line-height: 1.4em; font-family: -moz-fixed;
HelpArg,liberator|a color: #6A97D4;
HelpArg::before content: "{";
HelpArg::after content: "}";
HelpOptionalArg,liberator|oa color: #6A97D4;
HelpOptionalArg::before content: "[";
HelpOptionalArg::after content: "]";
HelpBody display: block; margin: 1em auto; max-width: 100ex;
HelpBorder,liberator|* border-color: silver; border-width: 0px; border-style: solid;
HelpCode,liberator|code display: block; white-space: pre; margin-left: 2em; font-family: courier, monospace;
HelpDefault,liberator|default display: block; float: left; margin-right: 1ex; margin-bottom: 1em; white-space: pre;
HelpDefault::after content: ")"
HelpDefault::before content: "(default: ";
HelpDescription,liberator|description display: block; clear: both;
HelpEm,liberator|em font-weight: bold;
HelpEx,liberator|ex display: inline-block; color: #527BBD; font-weight: bold;
HelpEx:hover text-decoration: underline; cursor: pointer;
HelpExample,liberator|example display: block; margin: 1em 0;
HelpExample::before content: "Example: "; font-weight: bold;
HelpHead,liberator|h1 display: block; margin: 1em 0; padding-bottom: .2ex; border-bottom-width: 1px; font-size: 2em; font-weight: bold; color: #527BBD; clear: both;
HelpItem,liberator|item display: block; margin: 1em 1em 1em 10em;
HelpKey,liberator|k color: #102663;
HelpLink,liberator|*>html|a text-decoration: none;
HelpLink:hover text-decoration: underline;
HelpList,liberator|ul display: block; list-style: outside disc;
HelpOrderedList,liberator|ol display: block; list-style: outside numeric;
HelpListItem,liberator|li display: list-item; margin-left: 1.5em;
HelpNote,liberator|note display: block; margin: 1em 0em;
HelpNote::before content: "Note: "; color: red; font-weight: bold;
HelpOpt,liberator|o color: #106326;
HelpOpt:hover text-decoration: underline; cursor: pointer;
HelpParagraph,liberator|p display: block; margin: 1em 0em; clear: right;
HelpSpec,liberator|spec display: block; margin: 0 2em 0 -10em; float: left; clear: left; color: #527BBD;
HelpString,liberator|str display: inline-block; color: green; font-weight: normal;
HelpString::before content: '"';
HelpString::after content: '"';
HelpSubhead,liberator|h2 display: block; margin: 1em 0; padding-bottom: .2ex; border-bottom-width: 1px; font-size: 1.2em; font-weight: bold; color: #527BBD; clear: both;
HelpSubsubhead,liberator|h3 display: block; margin: 1em 0; padding-bottom: .2ex; font-size: 1.1em; font-weight: bold; color: #527BBD; clear: both;
HelpTab,liberator|dl display: table; width: 100%; margin: 1em 0; border-bottom-width: 1px; border-top-width: 1px; padding: .5ex 0; table-layout: fixed;
HelpTabColumn,liberator|column display: table-column;
HelpTabColumn1,liberator|column:nth-of-type(1) display: table-column; width: 25%;
HelpTabColumn2,liberator|column:nth-of-type(2) display: table-column; width: 75%;
HelpTabTitle,liberator|dt display: table-cell; padding: .1ex 1ex; font-weight: bold;
HelpTabDescription,liberator|dd display: table-cell; padding: .1ex 1ex;
HelpTabRow,liberator|dl>* display: table-row;
HelpTag,liberator|tag display: inline-block; color: #527BBD; margin-left: 1ex; font-size: 8pt; font-weight: bold;
HelpTags,liberator|tags display: block; float: right; clear: right;
HelpType,liberator|type display: block; float: left; margin-right: 1ex; margin-bottom: 1em;
HelpWarning,liberator|warning display: block; margin: 1em 0em;
HelpWarning::before content: "Warning: "; color: red; font-weight: bold;
Search,,* {
font-size: inherit;
padding: 0;
color: black;
background-color: yellow;
padding: 0;
}
]]>.toString();
@@ -142,10 +209,18 @@ function Highlights(name, store)
let highlight = {};
let styles = storage.styles;
const Highlight = Struct("class", "selector", "filter", "default", "value");
Highlight.defaultValue("filter", function () ["chrome://liberator/content/buffer.xhtml"].concat(config.styleableChrome).join(","));
const Highlight = Struct("class", "selector", "filter", "default", "value", "base");
Highlight.defaultValue("filter", function ()
this.base ? this.base.filter :
["chrome://liberator/*",
"liberator:*",
"file://*"].concat(config.styleableChrome).join(","));
Highlight.defaultValue("selector", function () self.selector(this.class));
Highlight.defaultValue("value", function () this.default);
Highlight.defaultValue("base", function () {
let base = this.class.match(/^(\w*)/)[0];
return base != this.class && base in highlight ? highlight[base] : null;
});
Highlight.prototype.toString = function () "Highlight(" + this.class + ")\n\t" + [k + ": " + util.escapeString(v || "undefined") for ([k, v] in this)].join("\n\t");
function keys() [k for ([k, v] in Iterator(highlight))].sort();
@@ -185,7 +260,7 @@ function Highlights(name, store)
{
css = style.selector + " { " + css + " }";
let error = styles.addSheet(true, style.selector, style.filter, css, true);
let error = styles.addSheet(true, "highlight:" + style.class, style.filter, css, true);
if (error)
return error;
}
@@ -201,7 +276,10 @@ function Highlights(name, store)
this.selector = function (class)
{
let [, hl, rest] = class.match(/^(\w*)(.*)/);
return "[liberator|highlight~=" + hl + "]" + rest;
let class = "[liberator|highlight~=" + hl + "]"
if (highlight[hl] && highlight[hl].class != class)
class = highlight[hl].selector;
return class + rest;
};
/**
@@ -221,13 +299,13 @@ function Highlights(name, store)
*/
this.loadCSS = function (css)
{
css.replace(/\{((?:.|\n)*?)\}/g, function (_, _1) _1.replace(/\n\s*/g, " "))
css.replace(/^(\s*\S*\s+)\{((?:.|\n)*?)\}\s*$/gm, function (_, _1, _2) _1 + _2.replace(/\n\s*/g, " "))
.split("\n").filter(function (s) /\S/.test(s))
.forEach(function (style)
{
style = Highlight.apply(Highlight, Array.slice(style.match(/^\s*([^,\s]+)(?:,([^,\s]+)?)?(?:,([^,\s]+))?\s*(.*)$/), 1));
if (/^[>+ ]/.test(style.selector))
style.selector = self.selector(style.class + style.selector);
style.selector = self.selector(style.class) + style.selector;
let old = highlight[style.class];
highlight[style.class] = style;