UNPKG

hikaru-coffee

Version:

A static site generator that generates routes based on directories naturally.

65 lines (56 loc) 1.63 kB
// Generated by CoffeeScript 2.3.1 (function() { var Generator, Promise, colors; colors = require("colors/safe"); Promise = require("bluebird"); Generator = class Generator { constructor(logger) { // fn: param site, change site. this.register = this.register.bind(this); this.generate = this.generate.bind(this); this.logger = logger; this._ = { "beforeProcessing": [], "afterProcessing": [] }; } register(type, fn) { var i, len, t; if (!(fn instanceof Function)) { throw new TypeError("fn must be a Function!"); return; } if (type instanceof Array) { for (i = 0, len = type.length; i < len; i++) { t = type[i]; if (!(type in this._)) { throw new TypeError(`type must be a String in ${Object.keys(this._)}!`); continue; } this._[t].push(fn); } return; } if (!(type in this._)) { throw new TypeError(`type must be a String in ${Object.keys(this._)}!`); return; } return this._[type].push(fn); } async generate(type, site) { var fn, i, len, ref; if (!(type in this._)) { throw new TypeError(`type must be a String in ${Object.keys(this._)}!`); return; } this.logger.debug(`Hikaru is generating \`${colors.blue(type)}\`...`); ref = this._[type]; for (i = 0, len = ref.length; i < len; i++) { fn = ref[i]; site = (await fn(site)); } return site; } }; module.exports = Generator; }).call(this);