From 8e582e002bc66e19070dd059c1d6becfc8b5cdc7 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 26 Apr 2013 22:18:46 +0100 Subject: [PATCH] Experimental plugin for Tahoe-LAFS --- bld.sh | 10 +++- .../tahoelafs/tiddlers/DefaultTiddlers.tid | 3 + editions/tahoelafs/tiddlers/HelloThere.tid | 6 ++ editions/tahoelafs/tiddlers/SiteSubtitle.tid | 4 ++ editions/tahoelafs/tiddlers/SiteTitle.tid | 4 ++ .../tahoelafs/tiddlers/tests/test-wikitext.js | 47 +++++++++++++++ editions/tahoelafs/tiddlywiki.info | 5 ++ plugins/tiddlywiki/tahoelafs/plugin.info | 7 +++ plugins/tiddlywiki/tahoelafs/saver.js | 57 +++++++++++++++++++ 9 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 editions/tahoelafs/tiddlers/DefaultTiddlers.tid create mode 100644 editions/tahoelafs/tiddlers/HelloThere.tid create mode 100644 editions/tahoelafs/tiddlers/SiteSubtitle.tid create mode 100644 editions/tahoelafs/tiddlers/SiteTitle.tid create mode 100644 editions/tahoelafs/tiddlers/tests/test-wikitext.js create mode 100644 editions/tahoelafs/tiddlywiki.info create mode 100644 plugins/tiddlywiki/tahoelafs/plugin.info create mode 100644 plugins/tiddlywiki/tahoelafs/saver.js diff --git a/bld.sh b/bld.sh index 3635f8156..18c25eab0 100755 --- a/bld.sh +++ b/bld.sh @@ -59,7 +59,15 @@ node ./tiddlywiki.js \ --savetiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/empty.html text/plain \ || exit 1 -# Fourth, run the test edition to run the node.js tests and to generate test.html for tests in the browser +# Fourth, tahoelafs.html: empty wiki with plugin for Tahoe-LAFS + +node ./tiddlywiki.js \ + ./editions/tahoelafs \ + --verbose \ + --savetiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/tahoelafs.html text/plain \ + || exit 1 + +# Fifth, run the test edition to run the node.js tests and to generate test.html for tests in the browser node ./tiddlywiki.js \ ./editions/test \ diff --git a/editions/tahoelafs/tiddlers/DefaultTiddlers.tid b/editions/tahoelafs/tiddlers/DefaultTiddlers.tid new file mode 100644 index 000000000..cc98f9dd6 --- /dev/null +++ b/editions/tahoelafs/tiddlers/DefaultTiddlers.tid @@ -0,0 +1,3 @@ +title: $:/DefaultTiddlers + +HelloThere diff --git a/editions/tahoelafs/tiddlers/HelloThere.tid b/editions/tahoelafs/tiddlers/HelloThere.tid new file mode 100644 index 000000000..7fad51906 --- /dev/null +++ b/editions/tahoelafs/tiddlers/HelloThere.tid @@ -0,0 +1,6 @@ +title: HelloThere + +This is an experimental edition of TiddlyWiki5 for use with [[Tahoe-LAFS|https://tahoe-lafs.org/]]. At this point it is largely for experimentation by @zooko. Click the ''save changes'' button to PUT the updated TiddlyWiki HTML file back to the server. + +<$button message="tw-new-tiddler" class="btn btn-mini btn-success">New Tiddler +<$button message="tw-save-wiki" class="btn btn-mini btn-primary">Save Changes diff --git a/editions/tahoelafs/tiddlers/SiteSubtitle.tid b/editions/tahoelafs/tiddlers/SiteSubtitle.tid new file mode 100644 index 000000000..a924d874b --- /dev/null +++ b/editions/tahoelafs/tiddlers/SiteSubtitle.tid @@ -0,0 +1,4 @@ +title: SiteSubtitle +modifier: JeremyRuston + +Tahoe-LAFS edition \ No newline at end of file diff --git a/editions/tahoelafs/tiddlers/SiteTitle.tid b/editions/tahoelafs/tiddlers/SiteTitle.tid new file mode 100644 index 000000000..5280b839a --- /dev/null +++ b/editions/tahoelafs/tiddlers/SiteTitle.tid @@ -0,0 +1,4 @@ +title: SiteTitle +modifier: JeremyRuston + +TiddlyWiki5 \ No newline at end of file diff --git a/editions/tahoelafs/tiddlers/tests/test-wikitext.js b/editions/tahoelafs/tiddlers/tests/test-wikitext.js new file mode 100644 index 000000000..dfddeedec --- /dev/null +++ b/editions/tahoelafs/tiddlers/tests/test-wikitext.js @@ -0,0 +1,47 @@ +/*\ +title: test-wikitext.js +type: application/javascript +tags: [[$:/tags/test-spec]] + +Tests the wikitext rendering pipeline end-to-end. We also need tests that individually test parsers, rendertreenodes etc., but this gets us started. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +describe("WikiText tests", function() { + + // Create a wiki + var wiki = new $tw.Wiki(); + // Add a couple of tiddlers + wiki.addTiddler({title: "TiddlerOne", text: "The quick brown fox"}); + wiki.addTiddler({title: "TiddlerTwo", text: "The rain in Spain\nfalls mainly on the plain"}); + wiki.addTiddler({title: "TiddlerThree", text: "The speed of sound\n\nThe light of speed"}); + + it("should render tiddlers with no special markup render as-is", function() { + expect(wiki.renderTiddler("text/plain","TiddlerOne")).toBe("The quick brown fox"); + }); + it("should preserve single new lines", function() { + expect(wiki.renderTiddler("text/plain","TiddlerTwo")).toBe("The rain in Spain\nfalls mainly on the plain"); + }); + it("should use double new lines to create paragraphs", function() { + // The paragraphs are lost in the conversion to plain text + expect(wiki.renderTiddler("text/plain","TiddlerThree")).toBe("The speed of soundThe light of speed"); + }); + + it("should render plain text tiddlers as a paragraph", function() { + expect(wiki.renderTiddler("text/html","TiddlerOne")).toBe("

\nThe quick brown fox

"); + }); + it("should preserve single new lines", function() { + expect(wiki.renderTiddler("text/html","TiddlerTwo")).toBe("

\nThe rain in Spain\nfalls mainly on the plain

"); + }); + it("should use double new lines to create paragraphs", function() { + expect(wiki.renderTiddler("text/html","TiddlerThree")).toBe("

\nThe speed of sound

\nThe light of speed

"); + }); + +}); + +})(); diff --git a/editions/tahoelafs/tiddlywiki.info b/editions/tahoelafs/tiddlywiki.info new file mode 100644 index 000000000..49bd181c2 --- /dev/null +++ b/editions/tahoelafs/tiddlywiki.info @@ -0,0 +1,5 @@ +{ + "plugins": [ + "tiddlywiki/tahoelafs" + ] +} \ No newline at end of file diff --git a/plugins/tiddlywiki/tahoelafs/plugin.info b/plugins/tiddlywiki/tahoelafs/plugin.info new file mode 100644 index 000000000..5cf716bae --- /dev/null +++ b/plugins/tiddlywiki/tahoelafs/plugin.info @@ -0,0 +1,7 @@ +{ + "title": "$:/plugins/tiddlywiki/tahoelafs", + "description": "Support for saving changes to Tahoe-LAFS", + "author": "JeremyRuston", + "version": "0.0.0", + "coreVersion": ">=5.0.0" +} diff --git a/plugins/tiddlywiki/tahoelafs/saver.js b/plugins/tiddlywiki/tahoelafs/saver.js new file mode 100644 index 000000000..2e508352e --- /dev/null +++ b/plugins/tiddlywiki/tahoelafs/saver.js @@ -0,0 +1,57 @@ +/*\ +title: $:/plugins/tiddlywiki/tahoelafs/saver.js +type: application/javascript +module-type: saver + +A bare bones saver for Tahoe-LAFS. It just PUTs the new HTML file back to the server at the same URL. + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +/* +Select the appropriate saver module and set it up +*/ +var TahoeSaver = function(wiki) { + this.wiki = wiki; +}; + +TahoeSaver.prototype.save = function(text) { + // Do the HTTP post + var http = new XMLHttpRequest(); + http.open("PUT",document.location.toString(),true); + http.onreadystatechange = function() { + if(http.readyState == 4 && http.status == 200) { + window.alert("Saved to Tahoe-LAFS: " + http.responseText); + } + }; + http.send(text); + return true; +}; + +/* +Information about this saver +*/ +TahoeSaver.prototype.info = { + name: "tahoelafs", + priority: 1000 +}; + +/* +Static method that returns true if this saver is capable of working +*/ +exports.canSave = function(wiki) { + return true; +}; + +/* +Create an instance of this saver +*/ +exports.create = function(wiki) { + return new TahoeSaver(wiki); +}; + +})();