@@ -15,12 +15,20 @@
*/
Ext.define('Ext.server.view.View', {

// {{{ requires

requires: [
'Ext.server.view.Static',
'Ext.server.view.Template'
],

// }}}
// {{{ extend

extend: 'Ext.app.view.View',

// }}}
// {{{ controller
// {{{ constructor

constructor: function() {

@@ -38,11 +46,13 @@ Ext.define('Ext.server.view.View', {

modified: function(req, res, headers) {

var headers = headers || res._headers || {},
modifiedSince = req.headers['if-modified-since'],
lastModified = headers['last-modified'],
noneMatch = req.headers['if-none-match'],
etag = headers['etag'];
var headers, modifiedSince, lastModified, noneMatch, etag;

headers = headers || res._headers || {};
modifiedSince = req.headers['if-modified-since'];
lastModified = headers['last-modified'];
noneMatch = req.headers['if-none-match'];
etag = headers['etag'];

if(noneMatch) {
noneMatch = noneMatch.split(/ *, */);
@@ -130,12 +140,9 @@ Ext.define('Ext.server.view.View', {
// }}}
// {{{ isTempalte

isTemplate: function(ext) {
isTemplate: function(ext, template_exts) {

var me = this,
// ext = me.ext,
template_exts = this.template_exts,
isTemplate = true;
var ret = true;

if(ext || ext === '') {

@@ -146,18 +153,99 @@ Ext.define('Ext.server.view.View', {
ext = ext.substr(1);

if(Ext.Array.indexOf(template_exts, ext) === -1) {
isTemplate = false;
ret = false;
}

}

return isTemplate;

return ret;
},

// }}}
// {{{ render

render: function(config, next) {

var me, req, res, url, path, paths, ext,
directoryIndex, template_exts,
actionResultConfig, mime, options;

me = this;
req = config.req;
res = config.res;
url = require('url').parse(req.url);
path = decodeURIComponent(url.pathname);
paths = config.config.app.paths;
ext = require('path').extname(require('url').parse(req.url, true).pathname);
directoryIndex = config.config.app.directoryIndex;
template_exts = config.config.app.template_exts;
mime = Ext.$dependencies.mime;
actionResultConfig = config.actionResultConfig;

if(actionResultConfig.abort) {

if(actionResultConfig.abort === 500) {

// internal server error
me.printErrors(500);

} else if(actionResultConfig.forbidden) {

// forbidden
me.printErrors(403);

} else if(actionResultConfig.redirect) {

// redirect
res.statusCode = 302;
res.setHeader('Location', actionResultConfig.redirect);
res.end('Redirecting to ' + actionResultConfig.redirect);

}

return;
}

options = {
root: config.config.app.paths.public,
req: config.req,
res: config.res
};

if(res.headerSent) {
return;
}

config.res.actionresult = config.res.actionresult || {};

if(config.res.actionresult.$switchTemplate) {
root = me.paths.templates;
me.path = decodeURIComponent(node.url.parse(config.res.actionresult.$switchTemplate).pathname)
}

if(this.isTemplate(
require('path').extname(require('url').parse(config.req.url, true).pathname),
config.config.app.template_exts
) === false) {

Ext.create('Ext.server.view.Static', Ext.apply(options, {}), next);

} else {

Ext.create('Ext.server.view.Template', Ext.apply(options, {
engineName : config.config.app.template_engine,
path : path
}), options, next);

}

},

// }}}



/*
render: function(config, next) {
var me, node, chain;
@@ -228,7 +316,6 @@ Ext.define('Ext.server.view.View', {
return;
}

// special dir check.
if(this.config.app.dirs.special && this.url.path.substr(0, this.config.app.dirs.special.length) === this.config.app.dirs.special) {
@@ -492,6 +579,7 @@ Ext.define('Ext.server.view.View', {
}
// }}}
*/

});