hikaru-coffee
Version:
A static site generator that generates routes based on directories naturally.
84 lines (74 loc) • 2.15 kB
JavaScript
// Generated by CoffeeScript 2.3.1
(function() {
var Site;
Site = class Site {
constructor(workDir) {
this.get = this.get.bind(this);
this.set = this.set.bind(this);
// Put a file into an array.
// If a file with the same docPath already in array, replace it.
// Else append it.
this.put = this.put.bind(this);
this.del = this.del.bind(this);
this.raw = this.raw.bind(this);
this._ = {
"workDir": workDir,
"siteConfig": {},
"themeConfig": {},
"templates": {},
"assets": [],
"pages": [],
"subs": [],
"posts": [],
"files": [],
"categories": [],
// Flattend categories length.
"categoriesLength": 0,
"tags": [],
// Flattend tags length.
"tagsLength": 0
};
}
get(key) {
if (typeof key !== "string" || !(key in this._)) {
throw new TypeError(`key must be a string in ${Object.keys(this._)}!`);
}
return this._[key];
}
set(key, value) {
if (typeof key !== "string") {
throw new TypeError("key must be a string!");
}
return this._[key] = value;
}
put(key, file) {
var i, j, ref;
if ((key == null) || (file == null)) {
return;
}
for (i = j = 0, ref = this._[key].length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {
if (this._[key][i]["docPath"] === file["docPath"] && this._[key][i]["docDir"] === file["docDir"]) {
this._[key][i] = file;
return;
}
}
return this._[key].push(file);
}
del(key, file) {
var i, j, ref;
if ((key == null) || (file == null)) {
return null;
}
for (i = j = 0, ref = this._[key].length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {
if (this._[key][i]["srcPath"] === file["srcPath"] && this._[key][i]["srcDir"] === file["srcDir"]) {
return this._[key].splice(i, 1);
}
}
return null;
}
raw() {
return this._;
}
};
module.exports = Site;
}).call(this);