1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-08 04:54:23 +00:00
TiddlyWiki5/core/modules/savers/beaker.js
Mario Pietsch ef9efbc399 Fix for beaker 072 - new dat API (#2918)
* initial version that works again with beaker 0.7.2

* activate path again
2017-06-24 21:54:44 +01:00

67 lines
1.3 KiB
JavaScript

/*\
title: $:/core/modules/savers/beaker.js
type: application/javascript
module-type: saver
Saves files using the Beaker browser's (https://beakerbrowser.com) Dat protocol (https://datproject.org/)
Compatible with beaker >= V0.7.2
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Set up the saver
*/
var BeakerSaver = function(wiki) {
this.wiki = wiki;
};
var dat = new DatArchive('' + window.location);
BeakerSaver.prototype.save = function(text,method,callback) {
var path = (location.pathname.toString()).split("#")[0];
dat.stat(path).then(function(value) {
if(value.isDirectory) {
path = path + "/index.html";
}
dat.writeFile(path,text,"utf8").then(function(value) {
callback(null);
},function(reason) {
callback("Beaker Saver Write Error: " + reason);
});
},function(reason) {
callback("Beaker Saver Stat Error: " + reason);
});
return true;
};
/*
Information about this saver
*/
BeakerSaver.prototype.info = {
name: "beaker",
priority: 3000,
capabilities: ["save", "autosave"]
};
/*
Static method that returns true if this saver is capable of working
*/
exports.canSave = function(wiki) {
return !!window.DatArchive;
};
/*
Create an instance of this saver
*/
exports.create = function(wiki) {
return new BeakerSaver(wiki);
};
})();