Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 9dd71eb64a4a6c48c244e0121146275eefcd7930 @Grigore147 committed Apr 17, 2012
@@ -0,0 +1,3 @@
+node_modules/
+test/
+.DS_Store
@@ -0,0 +1,4 @@
+.git*
+.DS_Store
+test/
+examples/
@@ -0,0 +1,92 @@
+#!/usr/bin/env node
+
+var mod_root = require('path').normalize(__dirname + '/../');
+var root = process.cwd() + '/';
+var eol = require('os').platform() == 'win32' ? '\r\n' : '\n';
+
+var Path = require('path');
+var mkdir = require('mkdirp');
+var copy = require('../lib/utils').copy_dir;
+
+var App = require('commander');
+
+App.version('0.1.0');
+
+var create = App.command('create [path]')
+.description('Create default application structure and base configuration')
+.action(function(path) {
+ path = path ? Path.resolve(root, path) + '/' : root;
+
+ App.confirm('Create application at: '+ path +' ? [Yes|No]: ', function(ok) {
+ if (ok) {
+ if (!Path.existsSync(path)) {
+ mkdir.sync(path, 0755);
+ }
+
+ copy(mod_root + 'template', path, function(error) {
+ console.log(error ? error : 'Done!');
+
+ var empty_paths = [path + 'application/config/production', path + 'application/models',
+ path + 'modules', path + 'temp', path + 'public/scripts', path + 'public/styles'];
+
+ empty_paths.forEach(function(p) {
+ if (!Path.existsSync(p)) {
+ mkdir.sync(p, 0777);
+ }
+ });
+
+ process.stdin.destroy();
+ });
+ } else {
+ process.stdin.destroy();
+ }
+ });
+});
+
+App.command('install <module>')
+.description('Install Katana application module')
+.action(function(module) {
+ var version = 'last';
+
+ var has_version = module.match(/^([\-\_a-z]+)\@([\.0-9]+)$/i);
+
+ if (has_version) {
+ module = has_version[1];
+ version = has_version[2];
+ }
+
+ console.log('Downloading module '+ module +' '+ version);
+});
+
+App.parse(process.argv);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -0,0 +1,85 @@
+// Rename it to something else? but what? ...
+
+/*
+ # Listen uncaughtException
+*/
+/*process.on('uncaughtException', function(error) {
+ console.log('uncaughtException ['+ process.pid +']: \n' + error);
+});*/
+
+
+/*
+ # Extend EventEmitter, add series and parallel emit methods with done handler
+*/
+var EventEmitter = require('events').EventEmitter;
+var Async = require('async');
+
+// Call all EventListener's in parallel and callback on all done
+EventEmitter.prototype.parallel = function(event, callback) {
+ emit.call(this, event, callback, Array.prototype.slice.call(arguments, 2), 'parallel');
+}
+
+// Call all EventListener's in order they are added and callback on last done
+EventEmitter.prototype.series = function(event, callback) {
+ emit.call(this, event, callback, Array.prototype.slice.call(arguments, 2), 'series');
+}
+
+// Listener wrapper
+var fn = function(listener, args) {
+ return function(callback) {
+ args = args.concat(callback);
+
+ listener.apply(listener, args);
+ }
+}
+
+// Custom Event emit which allow to run event listeners in parallel or series
+// also we could listen all event listeners complete with callback
+function emit(event, callback, args, type) {
+ // Get all listeners for this event added with standart addListener or on methods
+ var listeners = this.listeners(event);
+
+ // Prepared list of listeners
+ var list = [];
+
+ if (args.length) {
+ var n = listeners.length;
+
+ for (var i=0; i<n; i++) {
+ // Wrap listener
+ var f = fn(listeners[i], args);
+
+ list.push(f);
+ }
+ } else {
+ list = listeners;
+ }
+
+ // Parallel or Series
+ var method = type === 'parallel' ? Async.parallel : Async.series;
+
+ method(list, callback || function(error, results) {
+ if (error) { throw error; }
+ });
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -0,0 +1,80 @@
+var root = global.root;
+var env = global.env;
+
+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.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.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();
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -0,0 +1,32 @@
+var App = require('katana');
+var View = App.View;
+
+var extend = require('./utils').extend;
+
+require('joose');
+
+Class('Katana.Core.Controller', {
+ have: {
+ data: []
+ },
+
+ methods: {
+ initialize: function() {
+
+ },
+
+ set: function(name, value) {
+ if (typeof(name) === 'object') {
+ this.data = extend(this.data, name);
+ } else {
+ this.data[name] = value;
+ }
+ },
+
+ render: function(template, data) {
+ return View.render(template, extend(this.data, data));
+ }
+ }
+});
+
+module.exports = Katana.Core.Controller;
Oops, something went wrong.

0 comments on commit 9dd71eb

Please sign in to comment.