QWiki can now be required as a module. If run directly, an instance of QWiki is created and started, as per before.

master
kts of kettek 2016-01-27 02:55:36 -08:00
parent 2144e6d877
commit 7501ca4e41
1 changed files with 43 additions and 41 deletions

View File

@ -165,9 +165,26 @@ QWiki.prototype.savePage = function(wiki_page, content, cb) {
QWiki.prototype.deleteFile = function(file, cb) { QWiki.prototype.deleteFile = function(file, cb) {
fs.unlink('wiki/'+file, cb); fs.unlink('wiki/'+file, cb);
}; };
/*********************************
* qwiki instance * if (require.main === module) {
*********************************/ var port = 8080;
process.argv.forEach(function (val, index, array) {
var parts = val.split('=');
var key = '';
var value = '';
if (parts[0].substr(0, 2) == '--') {
key = parts[0].substr(2);
value = parts[1];
}
if (key == 'port') {
if (value == '') {
console.log(key + ' needs a value');
} else {
port = Number(value);
}
}
});
var qwiki = new QWiki(); var qwiki = new QWiki();
qwiki.addMIMEtype('png', 'image/png'); qwiki.addMIMEtype('png', 'image/png');
@ -190,22 +207,7 @@ qwiki.addFormat('md', 'Markdown', function(source) {
qwiki.setDefault('format', 'md'); qwiki.setDefault('format', 'md');
var port = 8080;
process.argv.forEach(function (val, index, array) {
var parts = val.split('=');
var key = '';
var value = '';
if (parts[0].substr(0, 2) == '--') {
key = parts[0].substr(2);
value = parts[1];
}
if (key == 'port') {
if (value == '') {
console.log(key + ' needs a value');
} else {
port = Number(value);
}
}
});
qwiki.listen(port, function() { qwiki.loadWikiIndex(); }); qwiki.listen(port, function() { qwiki.loadWikiIndex(); });
}
module.exports = QWiki;