2012-05-02 16:27:42 +00:00
|
|
|
/*\
|
2012-05-03 20:47:16 +00:00
|
|
|
title: $:/core/modules/commands/load.js
|
2012-05-02 16:27:42 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: command
|
|
|
|
|
2012-05-19 17:23:14 +00:00
|
|
|
Command to load tiddlers from a file
|
2012-05-02 16:27:42 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
2012-05-04 17:49:04 +00:00
|
|
|
/*global $tw: false */
|
2012-05-02 16:27:42 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.info = {
|
|
|
|
name: "load",
|
|
|
|
synchronous: false
|
|
|
|
};
|
|
|
|
|
|
|
|
var Command = function(params,commander,callback) {
|
|
|
|
this.params = params;
|
|
|
|
this.commander = commander;
|
|
|
|
this.callback = callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
Command.prototype.execute = function() {
|
|
|
|
var self = this,
|
|
|
|
fs = require("fs"),
|
|
|
|
path = require("path");
|
|
|
|
if(this.params.length < 1) {
|
|
|
|
return "Missing filename";
|
|
|
|
}
|
2016-12-14 09:54:50 +00:00
|
|
|
var ext = path.extname(self.params[0]),
|
|
|
|
stat = fs.statSync(self.params[0]),
|
|
|
|
tiddlers = $tw.loadTiddlersFromPath(self.params[0]),
|
|
|
|
count = 0;
|
|
|
|
$tw.utils.each(tiddlers,function(tiddlerInfo) {
|
|
|
|
$tw.utils.each(tiddlerInfo.tiddlers,function(tiddler) {
|
|
|
|
self.commander.wiki.importTiddler(new $tw.Tiddler(tiddler));
|
|
|
|
count++;
|
|
|
|
});
|
2012-05-02 16:27:42 +00:00
|
|
|
});
|
2016-12-14 09:54:50 +00:00
|
|
|
if(!count) {
|
|
|
|
self.callback("No tiddlers found in file \"" + self.params[0] + "\"");
|
|
|
|
} else {
|
|
|
|
self.callback(null);
|
|
|
|
}
|
2012-05-02 16:27:42 +00:00
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.Command = Command;
|
|
|
|
|
|
|
|
})();
|