diff options
| author | Sean Fridman <fridman@mail.sfsu.edu> | 2015-04-06 12:28:38 -0400 |
|---|---|---|
| committer | Sean Fridman <fridman@mail.sfsu.edu> | 2015-04-06 15:27:53 -0400 |
| commit | 2175598ab95f33b3779d83e2df433eeedd25e70c (patch) | |
| tree | b3797a269a1da1664e8d7238f43534a4c2f97fec /app/index.js | |
| parent | 03fef46a1e34015cc9fed4baf54fa04285f8798b (diff) | |
Inject OKServer views as dependencies
Diffstat (limited to 'app/index.js')
| -rw-r--r-- | app/index.js | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/app/index.js b/app/index.js index 8ab7743..82be55b 100644 --- a/app/index.js +++ b/app/index.js @@ -34,9 +34,15 @@ function OKCMS(options) { var schemas = this._schemas = this._createSchemas(schemaConfig); var resources = this._resources = this._createResources(resourceConfig, db, schemas); + + // Create view instances from config var views = this._views = - this._createViews(viewConfig, db, meta, resources, templateCache); - this._initViews(server, views); + this._createViews(viewConfig, db, meta, resources, templateProvider); + var server = this._server = new OKServer({ + views: views, + root: root, + adminRoot: adminRoot + }); } OKCMS.prototype.listen = function listen(port, options) { @@ -74,16 +80,17 @@ OKCMS.prototype._createResources = function(resourceConfig, db, schemaCache) { }; OKCMS.prototype._createViews = function(viewConfig, db, - meta, resourceCache, templateCache) { + meta, resourceCache, templateProvider) { viewConfig = viewConfig || {}; var self = this; var createQueries = this._createQueries.bind(this); return Object.keys(viewConfig).reduce(function(cache, route) { var config = viewConfig[route]; var templateName = config.template || getDefaultTemplate(route, config); - var template = templateCache.getTemplate(templateName); - if (!template) + var template = templateProvider.getTemplate(templateName); + if (!template) { throw new Error(format('No template named "%s" found', templateName)); + } var queryConfig = config.data || []; var queries = createQueries(queryConfig, resourceCache); // Instantiate! |
