'use strict';


// nodeca
var HashTree = require('nlib').Support.HashTree;


// internals
var static_helpers = require('./view_renderer/helpers');


////////////////////////////////////////////////////////////////////////////////


module.exports = function view_renderer(params, callback) {
  var data, view;

  if (!this.origin.http || this.skipViewRenderer) {
    // skip non-http requests or when skip rendering was requested
    callback();
    return;
  }

  view = HashTree.get(nodeca.runtime.views, this.response.view);
  data = _.extend({}, static_helpers, this.response.data);

  if (!view) {
    callback('View ' + this.response.view + ' not found');
    return;
  }

  try {
    this.response.headers['Content-Type'] = 'text/html';
    this.response.body = view.en(data);
  } catch (err) {
    callback(err);
    return;
  }

  callback();
};

@@ -294,14 +294,8 @@
  var
- data,
  vie
@@ -325,33 +325,8 @@
 http
- %7C%7C this.skipViewRenderer
 ) %7B%0A
@@ -358,45 +358,8 @@
 ests
- or when skip rendering was requested
 %0A   
@@ -456,67 +456,8 @@
 ew);
-%0A  data = _.extend(%7B%7D, static_helpers, this.response.data);
 %0A%0A  
@@ -549,18 +549,8 @@
  %7D%0A%0A
-  try %7B%0A  
   th
@@ -604,46 +604,187 @@
 l';%0A
-    this.response.body = view.en(
+%0A  if (this.skipViewRenderer) %7B%0A    // skip rendering was requested%0A    callback();%0A  %7D%0A%0A  try %7B%0A    this.response.body = view.en(_.extend(%7B%7D, static_helpers, this.response.
 data)
+)
 ;%0A  

Improve view renderer logic