UNPKG

wns-mvc-package

Version:

MVC package/bundle for WNS Middleware

113 lines (90 loc) 1.87 kB
/** * @WNS - The NodeJS Middleware and Framework * * @copyright: Copyright © 2012- YEPT ® * @page: http://wns.yept.net/ * @docs: http://wns.yept.net/docs/ * @license: http://wns.yept.net/license/ */ /** * No description yet. * * @author Pedro Nasser */ // Exports module.exports = { /** * Class dependencies */ extend: ['wnComponent'], /** * PRIVATE */ private: {}, /** * Public Variables */ public: { /** * @var string Page's title */ title: null, /** * @var string Page's language */ language: '', /** * @var string Page's layout */ layout: '', /** * @var string Page's description */ description: '', /** * @var string Page's keywords */ keywords: '', // Keywords /** * @var string scripts that will be loaded and stored */ loadScript: [] }, /** * Methods */ methods: { /** * Initializer */ init: function () { this.controller = this.getConfig('controller'); }, /** * Renders the layout of the view with all the page's information. */ render: function (cb) { var exprt = {}; var viewResult=''; _.merge(exprt,self.data); exprt.view = this.export(); var lastModif = self.controller.app.cache.get('template-'+self.controller.uid); var viewName = self.controller.controllerName+'/'+self.name+'-'+lastModif; self.controller.template.render({ name: viewName, source: self.layout },exprt,function (err,result) { if (err) { console.log(err); self.controller.e.error(500,'Could not render the view: '+self.name); } else { cb&&cb(viewResult); viewResult=null; } }).on('data',function (chunk) { viewResult+=chunk; }); } } };