mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-14 14:15:47 +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:
@@ -6,8 +6,7 @@ BUILD_DATE = $(shell date "+%Y/%m/%d %H:%M:%S")
|
||||
BASE = $(TOP)/../common
|
||||
|
||||
LOCALEDIR = locale
|
||||
DOC_SRC_FILES = $(wildcard $(LOCALEDIR)/*/*.txt)
|
||||
LOCALES = $(shell ls $(LOCALEDIR))
|
||||
DOC_FILES = $(wildcard $(LOCALEDIR)/*/*.xml)
|
||||
|
||||
MAKE_JAR = VERSION="$(VERSION)" DATE="$(BUILD_DATE)" sh $(BASE)/make_jar.sh
|
||||
|
||||
@@ -34,14 +33,13 @@ RDF_IN = $(RDF).in
|
||||
|
||||
BUILD_DIR = build.$(VERSION).$(OS)
|
||||
|
||||
ASCIIDOC = asciidoc
|
||||
AWK = awk
|
||||
|
||||
.SILENT:
|
||||
|
||||
#### rules
|
||||
|
||||
TARGETS = all help info doc jar xpi install clean distclean $(JAR)
|
||||
TARGETS = all help info jar xpi install clean distclean $(JAR)
|
||||
$(TARGETS:%=\%.%):
|
||||
echo MAKE $* $(@:$*.%=%)
|
||||
$(MAKE) -C $* $(@:$*.%=%)
|
||||
@@ -54,7 +52,6 @@ help:
|
||||
@echo
|
||||
@echo " make help - display this help"
|
||||
@echo " make info - show some info about the system"
|
||||
@echo " make doc - build doc files"
|
||||
@echo " make jar - build a JAR ($(JAR))"
|
||||
@echo " make xpi - build an XPI ($(XPI_NAME))"
|
||||
@echo " make release - updates update.rdf (this is not for you)"
|
||||
@@ -66,7 +63,7 @@ help:
|
||||
info:
|
||||
@echo "version $(VERSION)"
|
||||
@echo "release file $(XPI)"
|
||||
@echo "doc files $(DOC_SRC_FILES)"
|
||||
@echo "doc files $(DOC_FILES)"
|
||||
@echo "xpi files $(XPI_FILES)"
|
||||
|
||||
xpi: $(XPI)
|
||||
@@ -81,11 +78,11 @@ $(RDF): $(RDF_IN) Makefile
|
||||
< $< > $@
|
||||
@echo "SUCCESS: $@"
|
||||
|
||||
clean: $(LOCALEDIR)/$(LOCALES:%=%.clean)
|
||||
clean:
|
||||
@echo "General $(NAME) cleanup..."
|
||||
rm -f $(JAR) $(XPI)
|
||||
|
||||
distclean: $(LOCALEDIR)/$(LOCALES:%=%.distclean) clean
|
||||
distclean:
|
||||
@echo "More $(NAME) cleanup..."
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
@@ -100,12 +97,8 @@ $(XPI): $(JAR)
|
||||
|
||||
#### jar
|
||||
|
||||
$(JAR): doc
|
||||
$(JAR):
|
||||
@echo "Building JAR..."
|
||||
$(MAKE_JAR) "$(JAR)" "$(JAR_BASES)" "$(JAR_DIRS)" "$(JAR_TEXTS)" "$(JAR_BINS)" "$(JAR_FILES)"
|
||||
@echo "SUCCESS: $@"
|
||||
|
||||
#### doc (see Makefile.doc)
|
||||
|
||||
doc: $(LOCALES:%=$(LOCALEDIR)/%.doc) ;
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
# Symlink me to (or include me from) locale/*/Makefile
|
||||
|
||||
#### configuration
|
||||
|
||||
ASCIIDOC = asciidoc
|
||||
AWK = awk
|
||||
|
||||
LOCALE = $(shell basename `pwd`)
|
||||
DOCLANG = $(shell basename `pwd` | $(AWK) -F- '{ print ($$1 ~ /^[a-z][a-z]$$/) ? $$1 : "en" }')
|
||||
|
||||
SRC_FILES = $(wildcard *.txt)
|
||||
FILES = $(SRC_FILES:%.txt=%.html)
|
||||
DEPS = $(wildcard lang-$(DOCLANG).conf) ${BASE}/asciidoc.conf $(BASE)/Makefile.doc
|
||||
|
||||
DOC_FILES = $(FILES) version.html
|
||||
|
||||
.SILENT:
|
||||
|
||||
#### rules
|
||||
|
||||
.PHONY: all help doc asciidoc check-asciidoc clean distclean
|
||||
all: doc
|
||||
|
||||
doc: asciidoc
|
||||
|
||||
help:
|
||||
@echo "$(NAME) $(VERSION) build"
|
||||
@echo
|
||||
@echo " make help - display this help"
|
||||
@echo " make doc - build doc files"
|
||||
@echo " make clean - clean up"
|
||||
@echo " make distclean - clean up more"
|
||||
|
||||
clean:
|
||||
@echo "Cleanup of $(LOCALE) documentation..."
|
||||
|
||||
distclean: clean
|
||||
@echo "More cleanup of $(LOCALE) documentation..."
|
||||
rm -f $(DOC_FILES)
|
||||
|
||||
#### Makes single-file makes easier to type
|
||||
|
||||
%: %.html %.txt ;
|
||||
|
||||
#### asciidoc
|
||||
|
||||
asciidoc: check-asciidoc $(DOC_FILES)
|
||||
|
||||
check-asciidoc:
|
||||
@$(ASCIIDOC) --version | $(AWK) '{ exit $$2 !~ /^8\.4\./ }' || \
|
||||
echo >&2 "Warning: asciidoc versions other than 8.4.x are unsupported"
|
||||
|
||||
all.html: $(SRC_FILES)
|
||||
|
||||
version.html: ../../NEWS $(DEPS)
|
||||
@echo "DOC locale/$(LOCALE)/$@"
|
||||
# NOTE: asciidoc doesn't source the conf file implicitly when processing stdin
|
||||
sed -e '1i\
|
||||
heading::Version{nbsp}information[version-information]' \
|
||||
-e '/^[0-9]/d' \
|
||||
-e '/^ \+\* version /s/.*version \+\([0-9.]\+\).*/section::Version{nbsp}\1[version-\1]\
|
||||
/' ../../NEWS | \
|
||||
${ASCIIDOC} -f $(BASE)/asciidoc.conf -a doctitle=version.html -o version.html -
|
||||
|
||||
$(FILES): %.html: %.txt $(DEPS)
|
||||
@echo "DOC locale/$(LOCALE)/$@"
|
||||
$(ASCIIDOC) -f $(BASE)/asciidoc.conf -a configname=$(NAME) --unsafe -a linkcss -a quirks! -a lang=$(DOCLANG) -a doctitle="$$(basename $@)" -o $@ $<
|
||||
|
||||
38
common/components/about-handler.js
Normal file
38
common/components/about-handler.js
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2009 by Doug Kearns
|
||||
//
|
||||
// This work is licensed for reuse under an MIT license. Details are
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
function AboutHandler() {}
|
||||
|
||||
AboutHandler.prototype = {
|
||||
|
||||
classDescription: "About Vimperator Page",
|
||||
|
||||
classID: Components.ID("81495d80-89ee-4c36-a88d-ea7c4e5ac63f"),
|
||||
|
||||
contractID: "@mozilla.org/network/protocol/about;1?what=vimperator",
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
|
||||
|
||||
newChannel: function (uri)
|
||||
{
|
||||
let channel = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService)
|
||||
.newChannel("chrome://vimperator/content/about.html", null, null);
|
||||
|
||||
channel.originalURI = uri;
|
||||
|
||||
return channel;
|
||||
},
|
||||
|
||||
getURIFlags: function (uri) Ci.nsIAboutModule.ALLOW_SCRIPT,
|
||||
};
|
||||
|
||||
function NSGetModule(compMgr, fileSpec) XPCOMUtils.generateModule([AboutHandler]);
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
206
common/components/chrome-data.js
Normal file
206
common/components/chrome-data.js
Normal file
@@ -0,0 +1,206 @@
|
||||
// Copyright (c) 2008-2009 Kris Maglione <maglione.k at Gmail>
|
||||
//
|
||||
// This work is licensed for reuse under an MIT license. Details are
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
|
||||
|
||||
/* Adds support for data: URIs with chrome privileges
|
||||
* and fragment identifiers.
|
||||
*
|
||||
* "chrome-data:" <content-type> [; <flag>]* "," [<data>]
|
||||
*
|
||||
* By Kris Maglione, ideas from Ed Anuff's nsChromeExtensionHandler.
|
||||
*/
|
||||
|
||||
const Ci = Components.interfaces, Cc = Components.classes;
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
const NS_BINDING_ABORTED = 0x804b0002;
|
||||
const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
|
||||
|
||||
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
let channel = Components.classesByID["{61ba33c0-3031-11d3-8cd0-0060b0fc14a3}"]
|
||||
.getService(Ci.nsIProtocolHandler)
|
||||
.newChannel(ioService.newURI("chrome://liberator/content/data", null, null))
|
||||
.QueryInterface(Ci.nsIRequest);
|
||||
const systemPrincipal = channel.owner;
|
||||
channel.cancel(NS_BINDING_ABORTED);
|
||||
delete channel;
|
||||
|
||||
function makeChannel(url, orig)
|
||||
{
|
||||
let uri = ioService.newURI(url, null, null);
|
||||
let channel = ioService.newChannelFromURI(uri);
|
||||
channel.owner = systemPrincipal;
|
||||
channel.originalURI = orig;
|
||||
return channel;
|
||||
}
|
||||
function fakeChannel(orig)
|
||||
makeChannel("chrome://does/not/exist/in/any/reasonable/configuration", orig);
|
||||
function redirect(to, orig)
|
||||
{
|
||||
let html = <html><head><meta http-equiv="Refresh" content={"0;" + to}/></head></html>.toXMLString();
|
||||
return makeChannel('data:text/html,' + escape(html), orig);
|
||||
}
|
||||
|
||||
function ChromeData() {}
|
||||
ChromeData.prototype = {
|
||||
contractID: "@mozilla.org/network/protocol;1?name=chrome-data",
|
||||
classID: Components.ID("{c1b67a07-18f7-4e13-b361-2edcc35a5a0d}"),
|
||||
classDescription: "Data URIs with chrome privileges",
|
||||
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIProtocolHandler]),
|
||||
_xpcom_factory: {
|
||||
createInstance: function (outer, iid)
|
||||
{
|
||||
if (!ChromeData.instance)
|
||||
ChromeData.instance = new ChromeData();
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return ChromeData.instance.QueryInterface(iid);
|
||||
}
|
||||
},
|
||||
|
||||
scheme: "chrome-data",
|
||||
defaultPort: -1,
|
||||
allowPort: function (port, scheme) false,
|
||||
protocolFlags: nsIProtocolHandler.URI_NORELATIVE
|
||||
| nsIProtocolHandler.URI_NOAUTH
|
||||
| nsIProtocolHandler.URI_IS_UI_RESOURCE,
|
||||
|
||||
newURI: function (spec, charset, baseURI)
|
||||
{
|
||||
var uri = Components.classes["@mozilla.org/network/standard-url;1"]
|
||||
.createInstance(Components.interfaces.nsIStandardURL)
|
||||
.QueryInterface(Components.interfaces.nsIURI);
|
||||
uri.init(uri.URLTYPE_STANDARD, this.defaultPort, spec, charset, null);
|
||||
return uri;
|
||||
},
|
||||
|
||||
newChannel: function (uri)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (uri.scheme == this.scheme)
|
||||
return makeChannel(uri.spec.replace(/^.*?:\/*(.*)(?:#.*)?/, "data:$1"), uri);
|
||||
}
|
||||
catch (e) {}
|
||||
return fakeChannel();
|
||||
}
|
||||
};
|
||||
|
||||
function Liberator()
|
||||
{
|
||||
this.wrappedJSObject = this;
|
||||
|
||||
this.__defineGetter__("helpFiles", function () HELP_FILES ? HELP_FILES.slice() : null);
|
||||
this.__defineSetter__("helpFiles", function (files) {
|
||||
if (!HELP_FILES)
|
||||
parseHelpTags(files);
|
||||
});
|
||||
|
||||
function xpath(doc, expression)
|
||||
{
|
||||
let result = doc.evaluate(expression, doc,
|
||||
function lookupNamespaceURI(prefix) ({
|
||||
xhtml: "http://www.w3.org/1999/xhtml",
|
||||
liberator: "http://vimperator.org/namespaces/liberator",
|
||||
}[prefix] || null),
|
||||
5, null);
|
||||
result.__iterator__ = function () { let elem; while ((elem = this.iterateNext())) yield elem; };
|
||||
return result;
|
||||
}
|
||||
|
||||
function httpGet(url)
|
||||
{
|
||||
try
|
||||
{
|
||||
let xmlhttp = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
|
||||
xmlhttp.open("GET", url, false);
|
||||
xmlhttp.send(null);
|
||||
return xmlhttp;
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
const HELP_TAGS = {};
|
||||
this.HELP_TAGS = HELP_TAGS;
|
||||
var HELP_FILES = null;
|
||||
|
||||
function parseHelpTags(files)
|
||||
{
|
||||
const XSLT = Cc["@mozilla.org/document-transformer;1?type=xslt"].createInstance(Ci.nsIXSLTProcessor);
|
||||
XSLT.importStylesheet(httpGet("chrome://liberator/content/help.xsl").responseXML);
|
||||
for each (let file in files)
|
||||
{
|
||||
let res = httpGet("liberator://help/" + file);
|
||||
if (res)
|
||||
{
|
||||
let doc = XSLT.transformToDocument(res.responseXML);
|
||||
for (let elem in xpath(doc, "//liberator:tag/text()"))
|
||||
HELP_TAGS[elem.textContent] = file;
|
||||
}
|
||||
}
|
||||
HELP_FILES = Array.slice(files);
|
||||
}
|
||||
}
|
||||
Liberator.prototype = {
|
||||
contractID: "@mozilla.org/network/protocol;1?name=liberator",
|
||||
classID: Components.ID("{9c8f2530-51c8-4d41-b356-319e0b155c44}"),
|
||||
classDescription: "Liberator utility protocol",
|
||||
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIProtocolHandler]),
|
||||
_xpcom_factory: {
|
||||
createInstance: function (outer, iid)
|
||||
{
|
||||
if (!Liberator.instance)
|
||||
Liberator.instance = new Liberator();
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return Liberator.instance.QueryInterface(iid);
|
||||
}
|
||||
},
|
||||
|
||||
scheme: "liberator",
|
||||
defaultPort: -1,
|
||||
allowPort: function (port, scheme) false,
|
||||
protocolFlags: 0
|
||||
| nsIProtocolHandler.URI_IS_UI_RESOURCE
|
||||
| nsIProtocolHandler.URI_IS_LOCAL_RESOURCE,
|
||||
|
||||
newURI: function (spec, charset, baseURI)
|
||||
{
|
||||
var uri = Components.classes["@mozilla.org/network/standard-url;1"]
|
||||
.createInstance(Components.interfaces.nsIStandardURL)
|
||||
.QueryInterface(Components.interfaces.nsIURI);
|
||||
uri.init(uri.URLTYPE_STANDARD, this.defaultPort, spec, charset, baseURI);
|
||||
return uri;
|
||||
},
|
||||
|
||||
newChannel: function (uri)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch(uri.host)
|
||||
{
|
||||
case "help":
|
||||
return makeChannel("chrome://liberator/locale" + uri.path.replace(/#.*/, "") + ".xml", uri);
|
||||
case "help-tag":
|
||||
let tag = uri.path.substr(1);
|
||||
if (tag in this.HELP_TAGS)
|
||||
return redirect("liberator://help/" + this.HELP_TAGS[tag] + "#" + tag, uri);
|
||||
}
|
||||
}
|
||||
catch (e) { dump(e + "\n"); dump(e.stack); }
|
||||
return fakeChannel(uri);
|
||||
}
|
||||
};
|
||||
|
||||
var components = [ChromeData, Liberator];
|
||||
|
||||
function NSGetModule(compMgr, fileSpec)
|
||||
{
|
||||
return XPCOMUtils.generateModule(components);
|
||||
}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
45
common/components/commandline-handler.js
Normal file
45
common/components/commandline-handler.js
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2009 by Doug Kearns
|
||||
//
|
||||
// This work is licensed for reuse under an MIT license. Details are
|
||||
// given in the LICENSE.txt file included with this file.
|
||||
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
function CommandLineHandler()
|
||||
{
|
||||
this.wrappedJSObject = this;
|
||||
}
|
||||
|
||||
CommandLineHandler.prototype = {
|
||||
|
||||
classDescription: "Vimperator Command-line Handler",
|
||||
|
||||
classID: Components.ID("{16dc34f7-6d22-4aa4-a67f-2921fb5dcb69}"),
|
||||
|
||||
contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=vimperator",
|
||||
|
||||
_xpcom_categories: [{
|
||||
category: "command-line-handler",
|
||||
entry: "m-vimperator"
|
||||
}],
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler]),
|
||||
|
||||
handle: function (commandLine)
|
||||
{
|
||||
// TODO: handle remote launches differently?
|
||||
try
|
||||
{
|
||||
this.optionValue = commandLine.handleFlagWithParam("vimperator", false);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
//"vimperator: option -vimperator requires an argument"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function NSGetModule(compMgr, fileSpec) XPCOMUtils.generateModule([CommandLineHandler]);
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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
143
common/content/help.xsl
Normal 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("'", text(), "'")'/>
|
||||
</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('<', @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: -->
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -15,7 +15,7 @@ mkdir -p $stage
|
||||
|
||||
getfiles () {
|
||||
filter="\.($(echo $1 | tr ' ' '|'))$"; shift
|
||||
find "$@" -not -path '*CVS*' 2>/dev/null | grep -E "$filter" || true
|
||||
find "$@" -not -path '*\.hg*' 2>/dev/null | grep -E "$filter" || true
|
||||
}
|
||||
copytext () {
|
||||
sed -e "s,###VERSION###,$VERSION,g" \
|
||||
|
||||
Reference in New Issue
Block a user