-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscribunto-console.js
121 lines (102 loc) · 3.08 KB
/
scribunto-console.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* Shirt module.
* @module ScribuntoConsole
*/
module.exports = (function(){
//var fs = require('fs');
var extend = require('extend');
var querystring = require('querystring');
/**
* Constructs an instance of ScribuntoConsole
* @name ScribuntoConsole
* @class
* @@classdesc Description of ScribuntoConsole....
* @param {Object} options -
* @param {string} [txt] - Module content
*/
function ScribuntoConsole(options, txt){
this.options = extend(true, {}, ScribuntoConsole.defaults, options || {});
this.session = null;
this.content = null;
this.serverOptions = extend(true, {}, ScribuntoConsole.ServerDefaults,
{
hostname: this.options.wikiHostName,
path: this.options.wikiAPIPath
}
);
if(typeof txt == "string")
this.setContent(txt);
if(options.setAsDefault)
ScribuntoConsole.setServerDefaults(this.serverOptions);
return this;
}
ScribuntoConsole.defaults = {
wikiHostName: 'starwars.wikia.com',
wikiAPIPath: '/api.php',
stripComments: true
};
ScribuntoConsole.ServerDefaults = {
port: 80,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': 0
}
};
Object.defineProperties(ScribuntoConsole.ServerDefaults, {
/**
* @property {string}
* @name ScribuntoConsole.ServerDefaults#hostname
*/
hostname: {
get: function(){return ScribuntoConsole.defaults.wikiHostName;},
set: function(v){ScribuntoConsole.defaults.wikiHostName = v;},
enumerable: true,
configurable: false
},
/**
* @property {string}
* @name ScribuntoConsole.ServerDefaults#path
*/
path: {
get: function(){return ScribuntoConsole.defaults.wikiAPIPath;},
set: function(v){
ScribuntoConsole.defaults.wikiAPIPath = v;
try {ScribuntoConsole.defaults.wikiAPIPath = ScribuntoConsole.defaults.wikiAPIPath.split('?')[0];} catch(e) {}
},
enumerable: true,
configurable: false
}
});
ScribuntoConsole.debug = false;
ScribuntoConsole.fn = ScribuntoConsole.prototype;
ScribuntoConsole.setServerDefaults = function(obj){
ScribuntoConsole.ServerDefaults = extend(true, ScribuntoConsole.ServerDefaults, obj || {});
return ScribuntoConsole;
};
/*
function forEachFile(dirPath, callback){
var files = fs.readdirSync(dirPath);
for (var i in files){
var fPath = dirPath + '/' + files[i];
if (fs.statSync(fPath).isFile()){
try {callback(fPath, files[i]);} catch(e) {}
}
}
}
function requireMember(filePath){return require(filePath)(ScribuntoConsole);}
forEachFile('./static', requireMember);
forEachFile('./proto', requireMember);
*/
/* Static Members */
require('./static/parseWikiText.js')(ScribuntoConsole);
/* Prototype */
require('./proto/exec.js')(ScribuntoConsole);
require('./proto/clear.js')(ScribuntoConsole);
require('./proto/getQuery.js')(ScribuntoConsole);
require('./proto/parseWiki.js')(ScribuntoConsole);
require('./proto/setContent.js')(ScribuntoConsole);
require('./proto/setContentFromFile.js')(ScribuntoConsole);
require('./proto/setContentFromPage.js')(ScribuntoConsole);
return ScribuntoConsole;
})();