Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

revert to non OOP 3.0.0 Express. Lets try again

  • Loading branch information...
commit 921deb033b9c5b22d128e79fd6bbdd0f4bdfc70d 1 parent 45ccba7
@pauliusuza pauliusuza authored
Showing with 38 additions and 1 deletion.
  1. +1 −0  lib/application.js
  2. +37 −1 lib/view.js
View
1  lib/application.js
@@ -512,6 +512,7 @@ app.render = function(name, options, fn){
if (!view) {
view = new View(name, {
defaultEngine: this.get('view engine')
+ , defaultLayout: this.get('view layout') || 'layout'
, root: this.get('views') || process.cwd() + '/views'
, engines: engines
});
View
38 lib/view.js
@@ -43,6 +43,7 @@ function View(name, options) {
this.name = name;
this.root = options.root;
var engines = options.engines;
+ this.defaultLayout = options.defaultLayout;
this.defaultEngine = options.defaultEngine;
var ext = this.ext = extname(name);
if (!ext) name += (ext = this.ext = '.' + this.defaultEngine);
@@ -79,5 +80,40 @@ View.prototype.lookup = function(path){
*/
View.prototype.render = function(options, fn){
- this.engine(this.path, options, fn);
+ //this.engine(this.path, options, fn);
+ var self = this;
+
+ self.engine(self.path, options, function(err, res) {
+ var layout = options.layout || self.defaultLayout;
+ var extension = options.engine || self.defaultEngine;
+
+ /* Expose render function to views for subview rendering */
+ options.render = function(locpath, opts) {
+ var local = options;
+ if (opts) utils.merge(local, opts);
+ var localext = local.engine || self.defaultEngine;
+ var result;
+ while(result == undefined) {
+ try {
+ self.engine(local.settings.views+'/'+locpath+'.'+localext, local, function(lerr, lres) {
+ if(lerr) result = lerr;
+ });
+ result = lres;
+ } catch(eall) {
+ console.log(eall);
+ }
+ }
+ return result;
+ };
+ if(layout != false) {
+ try {
+ options.body = res;
+ self.engine(options.settings.views+'/'+layout+'.'+extension, options, fn);
+ } catch(eall) {
+ console.log(eall);
+ }
+ } else {
+ fn(err, res);
+ }
+ });
};
Please sign in to comment.
Something went wrong with that request. Please try again.