From bac2c0ec07cf1773217eccb488953919b49ca6b4 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sun, 6 May 2012 13:23:29 +0100 Subject: [PATCH] Added a download macro This enables us to save changes by cooking a new tiddlywiki and forcing a download of it --- core/modules/macros/download.js | 52 +++++++++++++++++++++++++++++++ tw5.com/tiddlers/Introduction.tid | 6 ++-- 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 core/modules/macros/download.js diff --git a/core/modules/macros/download.js b/core/modules/macros/download.js new file mode 100644 index 000000000..15262c06d --- /dev/null +++ b/core/modules/macros/download.js @@ -0,0 +1,52 @@ +/*\ +title: $:/core/modules/macros/download.js +type: application/javascript +module-type: macro + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.info = { + name: "download", + params: { + title: {byName: "default", type: "text"}, + type: {byName: true, type: "text"}, + "filename": {byName: true, type: "text"}, + "label": {byName: true, type: "text"} + }, + events: ["click"] +}; + +exports.handleEvent = function(event) { + switch(event.type) { + case "click": + var text = this.wiki.renderTiddler(this.downloadType,this.downloadTitle), + link = document.createElement("a"); + link.setAttribute("download",this.downloadFilename); + link.setAttribute("href","data:" + this.downloadType + "," + encodeURIComponent(text)); + link.click(); + event.preventDefault(); + return false; + } + return true; +}; + +exports.executeMacro = function() { + this.downloadTitle = this.params.title || "$:/core/tiddlywiki5.template.html"; + this.downloadType = this.params.type || "text/plain"; + this.downloadFilename = this.params.filename || this.downloadTitle; + var attributes = {}, + content = []; + if(this.hasParameter("label")) { + content.push($tw.Tree.Text(this.params.label)); + } else { + content.push($tw.Tree.Text("Download \"" + this.downloadFilename + "\"")); + } + return [$tw.Tree.Element("button",attributes,content)]; +}; + +})(); diff --git a/tw5.com/tiddlers/Introduction.tid b/tw5.com/tiddlers/Introduction.tid index f16f38a68..6fd6a5a12 100644 --- a/tw5.com/tiddlers/Introduction.tid +++ b/tw5.com/tiddlers/Introduction.tid @@ -2,7 +2,10 @@ title: Introduction TiddlyWiki5 gains new capabilities through a [[completely rebuilt architecture|TiddlyWikiArchitecture]] using the latest features of HTML5 and node.js. It runs natively under node.js, and can also use its own components to construct a version of itself that works entirely within the browser, just as TiddlyWiki has always done. -TiddlyWiki5 also functions as the build system for earlier versions of TiddlyWiki, replacing the elderly Cook and Ginsu tools (see https://github.com/TiddlyWiki/cooker for details). See the CommandLineInterface for details. +You can modify this wiki, and then download a copy by clicking this button: +<> + +You can download a static copy of the tiddlers that are currently displayed in this wiki by clicking this button: <> {{alert alert-error{ Try out the prototype touch features: @@ -14,7 +17,6 @@ Learning more about TiddlyWiki5: * Some very rough UserInterfaceSketches showing where it is heading Some useful tiddlers for feature testing: -* ClockTiddler showing automatic refreshing of tiddlers * ImageTests showing different ways of embedding images * SampleData showing how JSON tiddlers are handled * SampleJavaScript and SampleJavaScriptWithError showing how JavaScript code is displayed