kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Update savers to specify variables, including filename
Now the `tm-download-file` and `tm-save-file` messages use the hashmap to specify variables to be applied when rendering the tiddler. We also add a convention that the variable “filename” is used to specify a filename for the download.print-window-tiddler
rodzic
b70b85aa9e
commit
b520efdeb8
|
@ -89,14 +89,16 @@ function SaverHandler(options) {
|
||||||
$tw.rootWidget.addEventListener("tm-save-wiki",function(event) {
|
$tw.rootWidget.addEventListener("tm-save-wiki",function(event) {
|
||||||
self.saveWiki({
|
self.saveWiki({
|
||||||
template: event.param,
|
template: event.param,
|
||||||
downloadType: "text/plain"
|
downloadType: "text/plain",
|
||||||
|
variables: event.paramObject
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$tw.rootWidget.addEventListener("tm-download-file",function(event) {
|
$tw.rootWidget.addEventListener("tm-download-file",function(event) {
|
||||||
self.saveWiki({
|
self.saveWiki({
|
||||||
method: "download",
|
method: "download",
|
||||||
template: event.param,
|
template: event.param,
|
||||||
downloadType: "text/plain"
|
downloadType: "text/plain",
|
||||||
|
variables: event.paramObject
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -143,9 +145,10 @@ SaverHandler.prototype.saveWiki = function(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var self = this,
|
var self = this,
|
||||||
method = options.method || "save",
|
method = options.method || "save",
|
||||||
|
variables = options.variables || {},
|
||||||
template = options.template || "$:/core/save/all",
|
template = options.template || "$:/core/save/all",
|
||||||
downloadType = options.downloadType || "text/plain",
|
downloadType = options.downloadType || "text/plain",
|
||||||
text = this.wiki.renderTiddler(downloadType,template),
|
text = this.wiki.renderTiddler(downloadType,template,options),
|
||||||
callback = function(err) {
|
callback = function(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
alert("Error while saving:\n\n" + 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
|
// Call the highest priority saver that supports this method
|
||||||
for(var t=this.savers.length-1; t>=0; t--) {
|
for(var t=this.savers.length-1; t>=0; t--) {
|
||||||
var saver = this.savers[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);
|
this.logger.log("Saving wiki with method",method,"through saver",saver.info.name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,17 @@ Select the appropriate saver module and set it up
|
||||||
var DownloadSaver = function(wiki) {
|
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
|
// Get the current filename
|
||||||
var filename = "tiddlywiki.html",
|
var filename = options.variables.filename;
|
||||||
p = document.location.pathname.lastIndexOf("/");
|
if(!filename) {
|
||||||
if(p !== -1) {
|
var p = document.location.pathname.lastIndexOf("/");
|
||||||
filename = document.location.pathname.substr(p+1);
|
if(p !== -1) {
|
||||||
|
filename = document.location.pathname.substr(p+1);
|
||||||
|
} else {
|
||||||
|
filename = "tiddlywiki.html";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Set up the link
|
// Set up the link
|
||||||
var link = document.createElement("a");
|
var link = document.createElement("a");
|
||||||
|
|
|
@ -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]].
|
|
@ -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]].
|
Ładowanie…
Reference in New Issue