From 0d44d919bc83a023e359a632372f38b3ac009b35 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 21 Oct 2009 04:46:29 -0400 Subject: [PATCH 01/27] 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 --- common/{Makefile.common => Makefile} | 19 +- common/Makefile.doc | 68 - .../components/about-handler.js | 0 common/components/chrome-data.js | 206 +++ .../components/commandline-handler.js | 0 common/content/completion.js | 5 +- common/content/help.js | 23 +- common/content/help.xsl | 143 ++ common/content/help.xul | 7 - common/content/liberator.js | 88 +- common/content/services.js | 9 +- common/content/style.js | 92 +- common/make_jar.sh | 2 +- muttator/Makefile | 2 +- muttator/components | 1 + muttator/components/chrome-data.js | 89 -- muttator/components/commandline-handler.js | 45 - vimperator/Makefile | 2 +- vimperator/components | 1 + vimperator/components/chrome-data.js | 109 -- vimperator/content/config.js | 2 +- vimperator/locale/en-US/Makefile | 3 - vimperator/locale/en-US/all.txt | 102 -- vimperator/locale/en-US/all.xml | 109 ++ vimperator/locale/en-US/autocommands.txt | 97 -- vimperator/locale/en-US/autocommands.xml | 132 ++ vimperator/locale/en-US/browsing.txt | 373 ----- vimperator/locale/en-US/browsing.xml | 546 +++++++ vimperator/locale/en-US/buffer.txt | 378 ----- vimperator/locale/en-US/buffer.xml | 536 +++++++ vimperator/locale/en-US/cmdline.txt | 78 - vimperator/locale/en-US/cmdline.xml | 119 ++ vimperator/locale/en-US/developer.txt | 88 -- vimperator/locale/en-US/developer.xml | 72 + vimperator/locale/en-US/eval.txt | 82 - vimperator/locale/en-US/eval.xml | 127 ++ vimperator/locale/en-US/gui.txt | 192 --- vimperator/locale/en-US/gui.xml | 278 ++++ vimperator/locale/en-US/hints.txt | 76 - vimperator/locale/en-US/hints.xml | 109 ++ vimperator/locale/en-US/index.txt | 358 ----- vimperator/locale/en-US/index.xml | 447 ++++++ vimperator/locale/en-US/insert.txt | 28 - vimperator/locale/en-US/insert.xml | 50 + vimperator/locale/en-US/intro.txt | 138 -- vimperator/locale/en-US/intro.xml | 206 +++ vimperator/locale/en-US/liberator.dtd | 5 + vimperator/locale/en-US/map.txt | 457 ------ vimperator/locale/en-US/map.xml | 605 ++++++++ vimperator/locale/en-US/marks.txt | 251 --- vimperator/locale/en-US/marks.xml | 353 +++++ vimperator/locale/en-US/message.txt | 59 - vimperator/locale/en-US/message.xml | 82 + vimperator/locale/en-US/options.txt | 934 ------------ vimperator/locale/en-US/options.xml | 1351 +++++++++++++++++ vimperator/locale/en-US/pattern.txt | 68 - vimperator/locale/en-US/pattern.xml | 103 ++ vimperator/locale/en-US/print.txt | 32 - vimperator/locale/en-US/print.xml | 52 + vimperator/locale/en-US/repeat.txt | 152 -- vimperator/locale/en-US/repeat.xml | 225 +++ vimperator/locale/en-US/starting.txt | 105 -- vimperator/locale/en-US/starting.xml | 159 ++ vimperator/locale/en-US/styling.txt | 157 -- vimperator/locale/en-US/styling.xml | 208 +++ vimperator/locale/en-US/tabs.txt | 269 ---- vimperator/locale/en-US/tabs.xml | 385 +++++ vimperator/locale/en-US/tutorial.txt | 255 ---- vimperator/locale/en-US/tutorial.xml | 369 +++++ vimperator/locale/en-US/various.txt | 161 -- vimperator/locale/en-US/various.xml | 237 +++ xulmus/Makefile | 2 +- xulmus/components | 1 + xulmus/components/chrome-data.js | 110 -- xulmus/components/commandline-handler.js | 45 - 75 files changed, 7363 insertions(+), 5466 deletions(-) rename common/{Makefile.common => Makefile} (84%) delete mode 100644 common/Makefile.doc rename {vimperator => common}/components/about-handler.js (100%) create mode 100644 common/components/chrome-data.js rename {vimperator => common}/components/commandline-handler.js (100%) create mode 100644 common/content/help.xsl delete mode 100644 common/content/help.xul create mode 120000 muttator/components delete mode 100644 muttator/components/chrome-data.js delete mode 100644 muttator/components/commandline-handler.js create mode 120000 vimperator/components delete mode 100644 vimperator/components/chrome-data.js delete mode 100644 vimperator/locale/en-US/Makefile delete mode 100644 vimperator/locale/en-US/all.txt create mode 100644 vimperator/locale/en-US/all.xml delete mode 100644 vimperator/locale/en-US/autocommands.txt create mode 100644 vimperator/locale/en-US/autocommands.xml delete mode 100644 vimperator/locale/en-US/browsing.txt create mode 100644 vimperator/locale/en-US/browsing.xml delete mode 100644 vimperator/locale/en-US/buffer.txt create mode 100644 vimperator/locale/en-US/buffer.xml delete mode 100644 vimperator/locale/en-US/cmdline.txt create mode 100644 vimperator/locale/en-US/cmdline.xml delete mode 100644 vimperator/locale/en-US/developer.txt create mode 100644 vimperator/locale/en-US/developer.xml delete mode 100644 vimperator/locale/en-US/eval.txt create mode 100644 vimperator/locale/en-US/eval.xml delete mode 100644 vimperator/locale/en-US/gui.txt create mode 100644 vimperator/locale/en-US/gui.xml delete mode 100644 vimperator/locale/en-US/hints.txt create mode 100644 vimperator/locale/en-US/hints.xml delete mode 100644 vimperator/locale/en-US/index.txt create mode 100644 vimperator/locale/en-US/index.xml delete mode 100644 vimperator/locale/en-US/insert.txt create mode 100644 vimperator/locale/en-US/insert.xml delete mode 100644 vimperator/locale/en-US/intro.txt create mode 100644 vimperator/locale/en-US/intro.xml create mode 100644 vimperator/locale/en-US/liberator.dtd delete mode 100644 vimperator/locale/en-US/map.txt create mode 100644 vimperator/locale/en-US/map.xml delete mode 100644 vimperator/locale/en-US/marks.txt create mode 100644 vimperator/locale/en-US/marks.xml delete mode 100644 vimperator/locale/en-US/message.txt create mode 100644 vimperator/locale/en-US/message.xml delete mode 100644 vimperator/locale/en-US/options.txt create mode 100644 vimperator/locale/en-US/options.xml delete mode 100644 vimperator/locale/en-US/pattern.txt create mode 100644 vimperator/locale/en-US/pattern.xml delete mode 100644 vimperator/locale/en-US/print.txt create mode 100644 vimperator/locale/en-US/print.xml delete mode 100644 vimperator/locale/en-US/repeat.txt create mode 100644 vimperator/locale/en-US/repeat.xml delete mode 100644 vimperator/locale/en-US/starting.txt create mode 100644 vimperator/locale/en-US/starting.xml delete mode 100644 vimperator/locale/en-US/styling.txt create mode 100644 vimperator/locale/en-US/styling.xml delete mode 100644 vimperator/locale/en-US/tabs.txt create mode 100644 vimperator/locale/en-US/tabs.xml delete mode 100644 vimperator/locale/en-US/tutorial.txt create mode 100644 vimperator/locale/en-US/tutorial.xml delete mode 100644 vimperator/locale/en-US/various.txt create mode 100644 vimperator/locale/en-US/various.xml create mode 120000 xulmus/components delete mode 100644 xulmus/components/chrome-data.js delete mode 100644 xulmus/components/commandline-handler.js diff --git a/common/Makefile.common b/common/Makefile similarity index 84% rename from common/Makefile.common rename to common/Makefile index e2a8dab6..564bc08a 100644 --- a/common/Makefile.common +++ b/common/Makefile @@ -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) ; - diff --git a/common/Makefile.doc b/common/Makefile.doc deleted file mode 100644 index 5d4cab1b..00000000 --- a/common/Makefile.doc +++ /dev/null @@ -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 $@ $< - diff --git a/vimperator/components/about-handler.js b/common/components/about-handler.js similarity index 100% rename from vimperator/components/about-handler.js rename to common/components/about-handler.js diff --git a/common/components/chrome-data.js b/common/components/chrome-data.js new file mode 100644 index 00000000..a52875e3 --- /dev/null +++ b/common/components/chrome-data.js @@ -0,0 +1,206 @@ +// Copyright (c) 2008-2009 Kris Maglione +// +// 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:" [; ]* "," [] + * + * 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 = .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: diff --git a/vimperator/components/commandline-handler.js b/common/components/commandline-handler.js similarity index 100% rename from vimperator/components/commandline-handler.js rename to common/components/commandline-handler.js diff --git a/common/content/completion.js b/common/content/completion.js index 716f0a08..269d7e75 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -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 }; } diff --git a/common/content/help.js b/common/content/help.js index 638e7037..a07745f8 100644 --- a/common/content/help.js +++ b/common/content/help.js @@ -1,17 +1,22 @@ -// Copyright (c) 2009 by Kris Maglione +// Copyright (c) 2009 by Kris Maglione // // 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: diff --git a/common/content/help.xsl b/common/content/help.xsl new file mode 100644 index 00000000..2edb85cd --- /dev/null +++ b/common/content/help.xsl @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Boolean + + + Number + + + String + + + + + + + + + + + + + + + # + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/common/content/help.xul b/common/content/help.xul deleted file mode 100644 index 16be6018..00000000 --- a/common/content/help.xul +++ /dev/null @@ -1,7 +0,0 @@ - - - -