Skip to content
Browse files

Added config environment implementation

  • Loading branch information...
1 parent cb60e15 commit c8a37a8b2e7a156cbc70b2e13180d46455acb00c @fk1blow committed
Showing with 21 additions and 14 deletions.
  1. +2 −2 lib/Http/Request.js
  2. +2 −1 lib/Http/Response.js
  3. +9 −5 lib/View/Utils.js
  4. +8 −6 lib/View/View.js
View
4 lib/Http/Request.js
@@ -12,8 +12,8 @@ var Request = Klass({
setObject: function(request_object) {
this._request = request_object;
- this._url = request_object;
- this._method = request_object;
+ this._url = request_object.url;
+ this._method = request_object.method;
},
getRequest: function() {
View
3 lib/Http/Response.js
@@ -24,8 +24,9 @@ var Response = Klass({
for(var i in headers) {
this._setHeader(i, headers[i]);
}
+
this._setHeader('Content-Length', body.length);
- this._response.statusCode = status || 200;
+ this._response.statusCode = status || 200;
this._setBody(body);
},
View
14 lib/View/Utils.js
@@ -5,23 +5,27 @@ var Config = require('../Config'),
var ViewUtils = Klass({
statics: {
- layout_name: 'default.html.ejs',
+ layout_name: function() { return Config.env.defaults.layout },
+
+ ext: '.html.ejs',
layout_path: '/layouts',
loadTemplate: function(layout_name) {
var views_path = this._getViewsPath();
- var file_name = layout_name || this.layout_name;
+ var file_name = layout_name + this.ext || this.layout_name() + this.ext;
var path = views_path + this.layout_path + '/' + file_name;
- //console.log('layout ::', path)
+
+ cl(layout_name)
+
return fs.readFileSync(path, "utf-8");
},
loadViewFile: function(view) {
var views_path = this._getViewsPath();
- var file_name = view;
+ var file_name = view + this.ext;
var path = views_path + '/' + file_name;
- //console.log('view ::', path)
+
return fs.readFileSync(path, "utf-8");
},
View
14 lib/View/View.js
@@ -1,4 +1,5 @@
var fs = require('fs'),
+ Config = require('../Config'),
Response = require('../Http/Response'),
Mimes = require('../Http/Mimes'),
ViewUtils = require('./Utils'),
@@ -21,7 +22,7 @@ var Renderer = Klass({
attributes: {
debugmode: false,
- default_extension: '.ejs',
+ default_extension: '.html.ejs',
default_content_type: { 'Content-type': 'text/html' }
},
@@ -116,11 +117,11 @@ var Template = Klass({
},
_setLayout: function(layout) {
- this.layout = (layout === true) ? ('default.html' + this.default_extension) : layout;
+ this.layout = (layout === true) ? (Config.env.defaults.layout) : layout;
},
_setView: function(view) {
- this.view = view + this.default_extension;
+ this.view = view;
},
_setLocals: function(locals) {
@@ -176,7 +177,7 @@ var View = Klass({
},
_setView: function(view) {
- this.view = view + this.default_extension;
+ this.view = view;
},
_setLocals: function(locals) {
@@ -255,15 +256,16 @@ var Mixed = Klass({
if(has_view && has_layout == false) {
response = this.renderView(this.view, this.locals);
}
+
Response.sendToBody(response, this.content_type);
},
_setLayout: function(layout) {
- this.layout = (layout === true) ? ('default.html' + this.default_extension) : layout;
+ this.layout = (layout === true) ? (Config.env.defaults.layout) : layout;
},
_setView: function(view) {
- this.view = (view === null) ? view : view + this.default_extension;
+ this.view = (view === null) ? view : view;
},
_setWhat: function(what) {

0 comments on commit c8a37a8

Please sign in to comment.
Something went wrong with that request. Please try again.