Permalink
Browse files

start major refactoring

  • Loading branch information...
1 parent c43b69b commit 85e7604f9afb31da3924adb530a05e3065404b71 @Grigore147 committed Dec 3, 2013
View
@@ -59,8 +59,8 @@ App.command('create [path]')
},
function(callback) {
var paths = [
- path + 'application/config/production',
- path + 'application/models',
+ path + 'app/config/production',
+ path + 'app/models',
path + 'public/images',
path + 'public/scripts',
path + 'public/css',
View
@@ -1,61 +0,0 @@
-var EventEmitter = require('events').EventEmitter;
-var Async = require('async');
-
-EventEmitter.prototype.emitParallel = EventEmitter.prototype.parallel = function(event, callback) {
- emit.call(this, event, callback, Array.prototype.slice.call(arguments, 2), 'parallel');
-}
-
-EventEmitter.prototype.emitSeries = EventEmitter.prototype.series = function(event, callback) {
- emit.call(this, event, callback, Array.prototype.slice.call(arguments, 2), 'series');
-}
-
-var fn = function(listener, args) {
- return function(callback) {
- args = args.concat(callback);
-
- listener.apply(listener, args);
- }
-}
-
-function emit(event, callback, args, type) {
- var listeners = this.listeners(event);
-
- var list = [];
-
- if (args.length) {
- for (var i=0; i<listeners.length; i++) {
- var f = fn(listeners[i], args);
-
- list.push(f);
- }
- } else {
- list = listeners;
- }
-
- var method = type === 'parallel' ? Async.parallel : Async.series;
-
- method(list, callback || function(error, results) {
- if (error) { throw error; }
- });
-}
-
-Joose.Managed.Builder.meta.addMethod('call', function(targetMeta, info) {
- targetMeta.addMethodModifier('initialize', function() {
- var methods = {};
- var around = {};
-
- this.meta.getMethods().eachOwn(function(fn, name) {
- methods[name] = fn;
- });
-
- Joose.O.each(info, function (value, name) {
- for (method in methods) {
- if (new RegExp(name).test(method)) {
- around[method] = value;
- }
- }
- });
-
- this.meta.extend({ around: around });
- }, Joose.Managed.Property.MethodModifier.Before);
-});
View
@@ -1,61 +0,0 @@
-var Path = require('path');
-var Fs = require('fs');
-
-var merge = require('./utils').merge;
-
-var Config = {};
-
-module.exports = function(config) {
- if (!config) { return Config.application.application; }
-
- var module = 'application';
-
- if (m = config.match(/(.*)(\:|\.)(.*)/i)) {
- module = m[1];
- config = m[3]!=='' ? m[3] : module;
- }
-
- if (!Config[module]) { Config[module] = {}; }
-
- if (config === '*') {
- return Config[module];
- }
-
- if (Config[module][config] === undefined) { Config[module][config] = {}; }
-
- return Config[module][config];
-}
-
-module.exports.load = function(module) {
- module = module || 'application';
-
- var path = module=='application' ? root+'application/config/' : root+'modules/'+module+'/config/';
-
- if (!Config[module]) { Config[module] = {}; }
-
- if (Fs.existsSync(path + 'development') && Fs.statSync(path + 'development').isDirectory()) {
- Fs.readdirSync(path + 'development').forEach(function(file) {
- var name = Path.basename(file, Path.extname(file));
-
- Config[module][name] = require(path +'development/'+ name);
- });
- }
-
- if (env !== 'development') {
- if (Fs.existsSync(path + env) && Fs.statSync(path + env).isDirectory()) {
- Fs.readdirSync(path + env).forEach(function(file) {
- var name = Path.basename(file, Path.extname(file));
-
- var config = require(path + env +'/'+ name);
-
- merge(Config[module][name], Config[module][name], config);
- });
- }
- }
-
- return Config[module];
-}
-
-module.exports.Config = Config;
-
-module.exports.load();
View
@@ -1,25 +1,33 @@
-var View = App.View;
-
-var extend = require('./utils').extend;
-
-Class('Katana.Core.Controller', {
- have: {
- data: []
- },
-
- methods: {
- set: function(name, value) {
- if (typeof(name) === 'object') {
- return this.data = extend(this.data, name);
- }
-
- this.data[name] = value;
- },
-
- render: function(template, data, callback) {
- View.render(template, extend(this.data, data), callback);
- }
+var merge = App.utils.merge;
+
+var Controller = module.exports = new Function;
+
+Controller.prototype.data = {};
+
+Controller.prototype.set = function(name, value) {
+ this.data[name] = value;
+}
+
+Controller.prototype.render = function(template, data, callback) {
+ if (typeof(data) === 'function') {
+ callback = data;
+ data = {};
}
-});
-module.exports = Katana.Core.Controller;
+ data = merge(this.data, data || {});
+
+ App.render(template, data, callback || function(error, content) {
+ if (error) {
+ throw error;
+ }
+ });
+}
+
+module.exports = Controller;
+
+if (typeof(Joose) !== 'undefined') {
+ module.exports = Class({
+ meta: Joose.Meta.Class,
+ isa: Controller
+ });
+}
View
@@ -1,101 +0,0 @@
-var sanitize = require('./utils').sanitize;
-
-var cookies = {};
-
-cookies.CookieCollection = function (req) {
- this.collection = {};
- if (req.headers['cookie']) {
- this.parse(req.headers['cookie'] || {});
- }
-};
-
-cookies.CookieCollection.prototype = new function () {
- this.parse = function (header) {
- var c = header.split(';');
- var item;
- var parsed, name, value;
- for (var i = 0; i < c.length; i++) {
- item = sanitize(c[i]).trim();
- parsed = item.split('=');
- name = parsed[0];
- value = parsed[1];
- this.collection[name] = new cookies.Cookie(name, value);
- }
- };
-
- this.toArray = function () {
- var send = [];
- var c;
- for (var p in this.collection) {
- c = this.collection[p];
- if (c.send) {
- send.push(c.toString());
- }
- }
- return send;
- };
-
- this.get = function (name) {
- var c = this.collection[name] || {};
- return c.value;
- };
-
- this.set = function (name, value, opts) {
- var c = new cookies.Cookie(name, value, opts);
- c.send = true;
- this.collection[name] = c;
- };
-
- this.delete = function(name) {
- this.set(name, null, { expires: 0 });
- };
-}();
-
-cookies.Cookie = function (name, value, o) {
- var opts = o || {};
- this.name = name;
- this.value = value;
- this.path = opts.path || '/';
- this.expires = opts.expires || null;
- this.domain = opts.domain || null;
- this.httpOnly = opts.httpOnly || false;
- this.send = false;
-
- if (opts.lifetime != null) {
- this.expires = new Date(Date.now() + opts.lifetime).toGMTString();
- }
-};
-
-cookies.Cookie.prototype.toString = function () {
- var res = [this.name + '=' + this.value];
- var keys = ['path', 'expires', 'domain'];
- var key;
- var str;
- for (var i = 0; i < keys.length; i++) {
- key = keys[i];
- if (this[key]) {
- res.push(key + '=' + this[key]);
- }
- }
- if (this.httpOnly) {
- res.push('HttpOnly');
- }
- str = res.join('; ');
- return str;
-};
-
-module.exports = cookies;
-
-App.on('request', function(Request, Response, callback) {
- Request.cookie = new cookies.CookieCollection(Request.request);
-
- callback();
-});
-
-App.on('send_response', function(Response, Request, callback) {
- App.series('cookie.send', function() {
- Response.header('Set-Cookie', Request.cookie.toArray());
-
- callback();
- }, Response, Request);
-});
View
@@ -0,0 +1,34 @@
+var Cookies = require('cookies');
+var Keygrip = require('keygrip');
+
+var conf = App.get('cookies');
+if (!conf.sign) {
+ conf.sign = {
+ keys: [],
+ hmac: 'sha1',
+ encoding: 'base64'
+ }
+}
+
+var keys = new Keygrip(conf.sign.keys || [], conf.sign.hmac || 'sha1', conf.sign.encoding || 'base64');
+
+var set = Cookies.prototype.set;
+Cookies.prototype.set = function(name, value, options) {
+ if (options) {
+ for (var key in conf) { options[key] = conf[key]; }
+ } else {
+ options = conf;
+ }
+
+ return set.call(this, name, value, options);
+}
+
+Cookies.prototype.delete = Cookies.prototype.remove = function(name) {
+ this.set(name, null);
+}
+
+App.use(function(request, response, next) {
+ request.cookies = response.cookies = new Cookies(request, response, keys);
+
+ next();
+});
Oops, something went wrong.

0 comments on commit 85e7604

Please sign in to comment.