mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Rejigging syncer structuring
The goal is to separate out the saver handling from the syncadaptor handling; it will take a few steps to get there
This commit is contained in:
parent
82860aea33
commit
27f1f82a70
@ -62,8 +62,17 @@ exports.startup = function() {
|
||||
document: document
|
||||
});
|
||||
}
|
||||
// Find a working syncadaptor
|
||||
$tw.syncadaptor = undefined;
|
||||
$tw.modules.forEachModuleOfType("syncadaptor",function(title,module) {
|
||||
if(!$tw.syncadaptor && module.adaptorClass) {
|
||||
$tw.syncadaptor = new module.adaptorClass({wiki: $tw.wiki});
|
||||
}
|
||||
});
|
||||
// Set up the syncer object
|
||||
$tw.syncer = new $tw.Syncer({wiki: $tw.wiki});
|
||||
if($tw.syncadaptor) {
|
||||
$tw.syncer = new $tw.Syncer({wiki: $tw.wiki, syncadaptor: $tw.syncadaptor});
|
||||
}
|
||||
// Host-specific startup
|
||||
if($tw.browser) {
|
||||
// Install the popup manager
|
||||
|
@ -14,20 +14,15 @@ The syncer tracks changes to the store. If a syncadaptor is used then individual
|
||||
|
||||
/*
|
||||
Instantiate the syncer with the following options:
|
||||
syncadaptor: reference to syncadaptor to be used
|
||||
wiki: wiki to be synced
|
||||
*/
|
||||
function Syncer(options) {
|
||||
var self = this;
|
||||
this.wiki = options.wiki;
|
||||
this.syncadaptor = options.syncadaptor
|
||||
// Make a logger
|
||||
this.logger = new $tw.utils.Logger("syncer" + ($tw.browser ? "-browser" : "") + ($tw.node ? "-server" : ""));
|
||||
// Find a working syncadaptor
|
||||
this.syncadaptor = undefined;
|
||||
$tw.modules.forEachModuleOfType("syncadaptor",function(title,module) {
|
||||
if(!self.syncadaptor && module.adaptorClass) {
|
||||
self.syncadaptor = new module.adaptorClass(self);
|
||||
}
|
||||
});
|
||||
// Initialise our savers
|
||||
if($tw.browser) {
|
||||
this.initSavers();
|
||||
@ -603,6 +598,8 @@ Syncer.prototype.dispatchTask = function(task,callback) {
|
||||
}
|
||||
// Invoke the callback
|
||||
callback(null);
|
||||
},{
|
||||
tiddlerInfo: self.tiddlerInfo[task.title]
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
created: 20130825162100000
|
||||
modified: 20131129094907624
|
||||
modified: 20140814094907624
|
||||
tags: dev moduletypes
|
||||
title: SyncAdaptorModules
|
||||
type: text/vnd.tiddlywiki
|
||||
@ -27,12 +27,16 @@ Nothing should be exported if the adaptor detects that it isn't capable of opera
|
||||
|
||||
Adaptor modules must handle the following methods.
|
||||
|
||||
!! `Constructor(syncer)`
|
||||
!! `Constructor(options)`
|
||||
|
||||
Initialises a new adaptor instance.
|
||||
|
||||
|!Parameter |!Description |
|
||||
|syncer |Syncer object that is using this adaptor |
|
||||
|options |See below |
|
||||
|
||||
Options include:
|
||||
|
||||
* ''options.wiki'': reference to wiki to use with this syncadaptor
|
||||
|
||||
!! `getTiddlerInfo(tiddler)`
|
||||
|
||||
@ -91,10 +95,11 @@ Loads a tiddler from the server.
|
||||
|title |Title of tiddler to be retrieved |
|
||||
|callback |Callback function invoked with parameter `err,tiddlerFields` |
|
||||
|
||||
!! `deleteTiddler(title,callback)`
|
||||
!! `deleteTiddler(title,callback,tiddlerInfo)`
|
||||
|
||||
Delete a tiddler from the server.
|
||||
|
||||
|!Parameter |!Description |
|
||||
|title |Title of tiddler to be deleted |
|
||||
|callback |Callback function invoked with parameter `err` |
|
||||
|tiddlerInfo |The tiddlerInfo maintained by the syncer for this tiddler |
|
||||
|
@ -3,7 +3,7 @@ title: $:/plugins/tiddlywiki/filesystem/filesystemadaptor.js
|
||||
type: application/javascript
|
||||
module-type: syncadaptor
|
||||
|
||||
A sync adaptor module for synchronising with the local filesystem via node.js APIs
|
||||
A sync adaptor module for synchronising with the local filesystem via node.js APIs
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
@ -16,9 +16,9 @@ A sync adaptor module for synchronising with the local filesystem via node.js AP
|
||||
var fs = !$tw.browser ? require("fs") : null,
|
||||
path = !$tw.browser ? require("path") : null;
|
||||
|
||||
function FileSystemAdaptor(syncer) {
|
||||
function FileSystemAdaptor(options) {
|
||||
var self = this;
|
||||
this.syncer = syncer;
|
||||
this.wiki = options.wiki;
|
||||
this.watchers = {};
|
||||
this.pending = {};
|
||||
this.logger = new $tw.utils.Logger("FileSystem");
|
||||
@ -31,7 +31,7 @@ function FileSystemAdaptor(syncer) {
|
||||
var tiddlers = $tw.loadTiddlersFromFile(filename).tiddlers;
|
||||
for(var t in tiddlers) {
|
||||
if(tiddlers[t].title) {
|
||||
$tw.wiki.addTiddler(tiddlers[t]);
|
||||
self.wiki.addTiddler(tiddlers[t]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -152,7 +152,7 @@ FileSystemAdaptor.prototype.saveTiddler = function(tiddler,callback) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
content = $tw.wiki.renderTiddler("text/plain","$:/core/templates/tiddler-metadata",{variables: {currentTiddler: tiddler.fields.title}});
|
||||
content = self.wiki.renderTiddler("text/plain","$:/core/templates/tiddler-metadata",{variables: {currentTiddler: tiddler.fields.title}});
|
||||
fs.writeFile(fileInfo.filepath + ".meta",content,{encoding: "utf8"},function (err) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
@ -164,7 +164,7 @@ FileSystemAdaptor.prototype.saveTiddler = function(tiddler,callback) {
|
||||
} else {
|
||||
// Save the tiddler as a self contained templated file
|
||||
template = $tw.config.typeTemplates[fileInfo.type];
|
||||
content = $tw.wiki.renderTiddler("text/plain",template,{variables: {currentTiddler: tiddler.fields.title}});
|
||||
content = self.wiki.renderTiddler("text/plain",template,{variables: {currentTiddler: tiddler.fields.title}});
|
||||
fs.writeFile(fileInfo.filepath,content,{encoding: "utf8"},function (err) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
@ -188,7 +188,7 @@ FileSystemAdaptor.prototype.loadTiddler = function(title,callback) {
|
||||
/*
|
||||
Delete a tiddler and invoke the callback with (err)
|
||||
*/
|
||||
FileSystemAdaptor.prototype.deleteTiddler = function(title,callback) {
|
||||
FileSystemAdaptor.prototype.deleteTiddler = function(title,callback,options) {
|
||||
var self = this,
|
||||
fileInfo = $tw.boot.files[title];
|
||||
// Only delete the tiddler if we have writable information for the file
|
||||
|
@ -3,7 +3,7 @@ title: $:/plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js
|
||||
type: application/javascript
|
||||
module-type: syncadaptor
|
||||
|
||||
A sync adaptor module for synchronising with TiddlyWeb compatible servers
|
||||
A sync adaptor module for synchronising with TiddlyWeb compatible servers
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
@ -15,15 +15,15 @@ A sync adaptor module for synchronising with TiddlyWeb compatible servers
|
||||
var CONFIG_HOST_TIDDLER = "$:/config/tiddlyweb/host",
|
||||
DEFAULT_HOST_TIDDLER = "$protocol$//$host$/";
|
||||
|
||||
function TiddlyWebAdaptor(syncer) {
|
||||
this.syncer = syncer;
|
||||
function TiddlyWebAdaptor(options) {
|
||||
this.wiki = options.wiki;
|
||||
this.host = this.getHost();
|
||||
this.recipe = undefined;
|
||||
this.logger = new $tw.utils.Logger("TiddlyWebAdaptor");
|
||||
}
|
||||
|
||||
TiddlyWebAdaptor.prototype.getHost = function() {
|
||||
var text = this.syncer.wiki.getTiddlerText(CONFIG_HOST_TIDDLER,DEFAULT_HOST_TIDDLER),
|
||||
var text = this.wiki.getTiddlerText(CONFIG_HOST_TIDDLER,DEFAULT_HOST_TIDDLER),
|
||||
substitutions = [
|
||||
{name: "protocol", value: document.location.protocol},
|
||||
{name: "host", value: document.location.host}
|
||||
@ -46,8 +46,7 @@ Get the current status of the TiddlyWeb connection
|
||||
*/
|
||||
TiddlyWebAdaptor.prototype.getStatus = function(callback) {
|
||||
// Get status
|
||||
var self = this,
|
||||
wiki = self.syncer.wiki;
|
||||
var self = this;
|
||||
this.logger.log("Getting status");
|
||||
$tw.utils.httpRequest({
|
||||
url: this.host + "status",
|
||||
@ -174,7 +173,7 @@ TiddlyWebAdaptor.prototype.saveTiddler = function(tiddler,callback) {
|
||||
// Invoke the callback
|
||||
callback(null,{
|
||||
bag: etagInfo.bag
|
||||
}, etagInfo.revision);
|
||||
}, etagInfo.revision);
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -198,10 +197,12 @@ TiddlyWebAdaptor.prototype.loadTiddler = function(title,callback) {
|
||||
|
||||
/*
|
||||
Delete a tiddler and invoke the callback with (err)
|
||||
options include:
|
||||
tiddlerInfo: the syncer's tiddlerInfo for this tiddler
|
||||
*/
|
||||
TiddlyWebAdaptor.prototype.deleteTiddler = function(title,callback) {
|
||||
TiddlyWebAdaptor.prototype.deleteTiddler = function(title,callback,options) {
|
||||
var self = this,
|
||||
bag = this.syncer.tiddlerInfo[title].adaptorInfo.bag;
|
||||
bag = options.tiddlerInfo.adaptorInfo.bag;
|
||||
// If we don't have a bag it means that the tiddler hasn't been seen by the server, so we don't need to delete it
|
||||
if(!bag) {
|
||||
return callback(null);
|
||||
|
Loading…
Reference in New Issue
Block a user