This repository has been archived on 2023-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
2018-01-10 20:01:38 +00:00
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach model and render view
|
|
|
|
* @param {String} view View name
|
|
|
|
* @param {Object} response Http response
|
|
|
|
*/
|
|
|
|
render: function(view, args, response) {
|
|
|
|
let instance = require(`./views/${view}/index.js`);
|
|
|
|
|
2018-01-16 19:31:19 +00:00
|
|
|
if (!instance.partials)
|
|
|
|
return response.render(`${view}/index`, instance);
|
|
|
|
|
2018-01-10 20:01:38 +00:00
|
|
|
instance.init(args, () => {
|
|
|
|
this.getPartials(instance, args, (instance) => {
|
|
|
|
response.render(`${view}/index`, instance);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach partial models
|
|
|
|
* @param {Object} instance Main instance
|
|
|
|
* @return {Object} Merged instance
|
|
|
|
*/
|
|
|
|
getPartials: function(instance, args, cb) {
|
|
|
|
let index = 0;
|
|
|
|
|
|
|
|
for(let partial in instance.partials) {
|
|
|
|
let subInstance = require(`./views/${partial}/index.js`);
|
|
|
|
|
|
|
|
subInstance.init(args, () => {
|
|
|
|
Object.assign(instance, subInstance);
|
|
|
|
index++;
|
|
|
|
|
|
|
|
if (index == Object.keys(instance.partials).length)
|
|
|
|
cb(instance);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|