UNPKG

qwebs

Version:
94 lines (73 loc) 2.74 kB
/*! * qwebs * Copyright(c) 2015 Benoît Claveau * MIT Licensed */ "use strict"; var path = require("path"), Injector = require("./injector"), configLoader = require("./loaders/config"), bundleLoader = require("./loaders/bundle"), assetsLoader = require("./loaders/assets"), routesLoader = require("./loaders/routes"), Q = require("q"); function Qwebs (options) { options = options || {}; this.root = path.dirname(require.main.filename); //execution folder if (options.dirname) this.root = options.dirname; this.injector = new Injector(); this.inject("$qwebs", this); this.inject("$injector", this.injector); this.inject("$config", configLoader.create(this, options.config)); this.inject("$router", "./router", { local: true }); this.inject("$response", "./services/response", { local: true }); this.inject("$responseProxy", "./services/response-proxy", { local: true }); this.inject("$qjimp", "./services/qjimp", { local: true }); this.inject("$repository", "./services/repository", { local: true, instanciate: false }); this.router = this.resolve("$router"); this.loaded = false; }; Qwebs.prototype.load = function() { var self = this; return assetsLoader.load(self).then(function() { return bundleLoader.load(self).then(function() { return routesLoader.load(self).then(function() { self.injector.load(); self.router.load(); self.loaded = true; console.log("Qwebs is loaded.") return self; }); }); }); }; Qwebs.prototype.inject = function(name, location, options) { return this.injector.inject(name, location, options); }; Qwebs.prototype.resolve = function(name) { return this.injector.resolve(name); }; Qwebs.prototype.get = function(route, service, method) { var item = this.router.get(route); item.register(service, method); return item; }; Qwebs.prototype.post = function(route, service, method) { var item = this.router.post(route); item.register(service, method); return item; }; Qwebs.prototype.put = function(route, service, method) { var item = this.router.put(route); item.register(service, method); return item; }; Qwebs.prototype.delete = function(route, service, method) { var item = this.router.delete(route); item.register(service, method); return item; }; Qwebs.prototype.invoke = function(request, response, url) { return this.router.invoke(request, response, url); }; exports = module.exports = Qwebs;