diff --git a/core/modules/saver-handler.js b/core/modules/saver-handler.js index 1e1fd4d6b..0669ec917 100644 --- a/core/modules/saver-handler.js +++ b/core/modules/saver-handler.js @@ -89,14 +89,16 @@ function SaverHandler(options) { $tw.rootWidget.addEventListener("tm-save-wiki",function(event) { self.saveWiki({ template: event.param, - downloadType: "text/plain" + downloadType: "text/plain", + variables: event.paramObject }); }); $tw.rootWidget.addEventListener("tm-download-file",function(event) { self.saveWiki({ method: "download", template: event.param, - downloadType: "text/plain" + downloadType: "text/plain", + variables: event.paramObject }); }); } @@ -143,9 +145,10 @@ SaverHandler.prototype.saveWiki = function(options) { options = options || {}; var self = this, method = options.method || "save", + variables = options.variables || {}, template = options.template || "$:/core/save/all", downloadType = options.downloadType || "text/plain", - text = this.wiki.renderTiddler(downloadType,template), + text = this.wiki.renderTiddler(downloadType,template,options), callback = function(err) { if(err) { alert("Error while saving:\n\n" + err); @@ -168,7 +171,7 @@ SaverHandler.prototype.saveWiki = function(options) { // Call the highest priority saver that supports this method for(var t=this.savers.length-1; t>=0; t--) { var saver = this.savers[t]; - if(saver.info.capabilities.indexOf(method) !== -1 && saver.save(text,method,callback)) { + if(saver.info.capabilities.indexOf(method) !== -1 && saver.save(text,method,callback,{variables: {filename: variables.filename}})) { this.logger.log("Saving wiki with method",method,"through saver",saver.info.name); return true; } diff --git a/core/modules/savers/download.js b/core/modules/savers/download.js index ad23ecd11..0192cfd69 100644 --- a/core/modules/savers/download.js +++ b/core/modules/savers/download.js @@ -18,12 +18,17 @@ Select the appropriate saver module and set it up var DownloadSaver = function(wiki) { }; -DownloadSaver.prototype.save = function(text,method,callback) { +DownloadSaver.prototype.save = function(text,method,callback,options) { + options = options || {}; // Get the current filename - var filename = "tiddlywiki.html", - p = document.location.pathname.lastIndexOf("/"); - if(p !== -1) { - filename = document.location.pathname.substr(p+1); + var filename = options.variables.filename; + if(!filename) { + var p = document.location.pathname.lastIndexOf("/"); + if(p !== -1) { + filename = document.location.pathname.substr(p+1); + } else { + filename = "tiddlywiki.html"; + } } // Set up the link var link = document.createElement("a"); diff --git a/editions/prerelease/tiddlers/WidgetMessage_ tm-download-file.tid b/editions/prerelease/tiddlers/WidgetMessage_ tm-download-file.tid new file mode 100644 index 000000000..5e5229213 --- /dev/null +++ b/editions/prerelease/tiddlers/WidgetMessage_ tm-download-file.tid @@ -0,0 +1,16 @@ +created: 20140811112201235 +modified: 20141110133723696 +tags: Messages +title: WidgetMessage: tm-download-file +type: text/vnd.tiddlywiki +caption: tm-download-file + +The download file message causes the current saver module to prompt the user to download the result of parsing a specified template tiddler as a file. It requires the following properties on the `event` object: + +|!Name |!Description | +|param |Title of a tiddler to use as a template for the new tiddler | +|paramObject |Optional hashmap of variable values to use for the rendering | + +The download file message is usually generated with the ButtonWidget. + +The download file message is handled by the TiddlyWiki core SyncMechanism which invokes the current [[SaverModule|SaverModules]]. diff --git a/editions/prerelease/tiddlers/WidgetMessage_ tm-save-wiki.tid b/editions/prerelease/tiddlers/WidgetMessage_ tm-save-wiki.tid new file mode 100644 index 000000000..605ee37e8 --- /dev/null +++ b/editions/prerelease/tiddlers/WidgetMessage_ tm-save-wiki.tid @@ -0,0 +1,16 @@ +created: 20140811112325641 +modified: 20141110133723696 +tags: Messages +title: WidgetMessage: tm-save-wiki +type: text/vnd.tiddlywiki +caption: tm-save-wiki + +The save wiki message causes the current saver module to perform a full save operation. The save operation can involve user interaction. It requires the following properties on the `event` object: + +|!Name |!Description | +|param |Title of a tiddler to use as a template for rendering the wiki (defaults to `$:/core/save/all`) | +|paramObject |Optional hashmap of variable values to use for the rendering | + +The save wiki message is usually generated by the ButtonWidget. + +The save wiki message is handled by the TiddlyWiki core SyncMechanism which invokes the current [[SaverModule|SaverModules]].