Permalink
Browse files

update to get it working with latest version (node, mongoose, ...)

  • Loading branch information...
1 parent b8224f0 commit 900851be25a0c7a075f75e53823f9f7d7714207c @stunti committed Feb 13, 2011
Showing with 53 additions and 29 deletions.
  1. +3 −2 app.js
  2. +14 −0 app/controllers/index_controller.js
  3. +11 −17 app/models/user.js
  4. +3 −1 lib/controllers.js
  5. +8 −2 lib/models.js
  6. +11 −2 lib/routes.js
  7. +3 −5 lib/setup.js
View
5 app.js
@@ -3,16 +3,17 @@ require("./lib/underscore");
var Server = {},
express = require("express"),
path = require("path"),
+ sys = require("sys"),
application_root = __dirname;
global.Server = Server;
Server.root = application_root;
global.app = express.createServer();
Server.setup = require("./lib/setup.js").setup({
- redis: require("./lib/redis-client").createClient(),
+ //redis: require("./lib/redis-client").createClient(),
app: app,
- mongoose : require("mongoose").Mongoose,
+ mongoose : require("mongoose"),
io : require("socket.io"),
express : express,
paths : {
@@ -0,0 +1,14 @@
+var mongoose = require("mongoose");
+var actions = {};
+user = mongoose.model('User');
+actions.index = function(request,response){
+ user.find({}, function(err, docs){
+ //sys.puts(sys.inspect(users));
+ response.render('index',{
+ results : docs,
+ total : docs.length
+ })
+ });
+};
+
+module.exports = actions;
View
@@ -1,17 +1,11 @@
-module.exports.define = function(){
- return {
- properties: ['first_name', 'last_name', 'email', 'updated_at'],
- indexes: ['id'],
- getters: {
- full_name: function(){
- return this.first_name + ' ' + this.last_name;
- }
- },
- methods: {
- save: function(fn){
- this.updated_at = new Date();
- this.__super__(fn);
- }
- }
- };
-}
+var mongoose = require("mongoose");
+var sys = require("sys");
+var schema = new mongoose.Schema({
+ name : { type: String, default: 'hahaha' }
+ , age : { type: Number, min: 18, index: true }
+ , bio : { type: String, match: /[a-z]/ }
+ , date : { type: Date, default: Date.now }
+ });
+
+mongoose.model('User', schema);
+
View
@@ -5,15 +5,17 @@ module.exports = Server.controllers = {
Server.controllers.autoload = function(db){
var fs = require("fs"),
path = require("path"),
+ sys = require("sys"),
files = fs.readdirSync( Server.paths.controllers ),
util = require("./util"),
names = _.map(files,function(f){
return( path.basename(f) );
});
+
_.each(names,function(controller){
var c_id = util.camelize( controller.replace(/.js$/,'') );
Server.controllers.controller_objects[c_id] =
require( Server.paths.controllers + "/" + controller );
});
-};
+};
View
@@ -3,12 +3,18 @@ module.exports = Server.models = {};
Server.models.autoload = function(db){
var fs = require("fs"),
path = require("path"),
+ mongoose = require("mongoose"),
+ sys = require("sys"),
files = fs.readdirSync( Server.paths.models ),
names = _.map(files,function(f){
return( path.basename(f) );
});
+ //Model = mongoose.noSchema('test', db);
+ //mongoose.load(Server.paths.models);
+
_.each(names,function(model){
- require( Server.paths.models + "/" + model ).define();
+ require( Server.paths.models + "/" + model );
});
-};
+ sys.puts(sys.inspect(Server.models));
+};
View
@@ -9,14 +9,23 @@ var match = function(url,handler,method){
util = require("./util"),
controller = parts.shift(),
action = parts.shift(),
+ sys = require('sys'),
method = method || "get";
+
+ //sys.puts(sys.inspect(controller));
if(!controller.match(/_controller$/)){
- controller = controller + "_controller";
+ if (controller == 'site') {
+ controller = 'Index';
+ }
+ controller = controller + "Controller";
}
+ sys.puts(sys.inspect(Server.controllers.controller_objects));
+ sys.puts(sys.inspect(controller));
+
var controller_id = util.camelize(controller),
- action_handler = Server.controllers.controller_objects[controller_id][ action ];
+ action_handler = Server.controllers.controller_objects[controller][ action ];
//add the handler for the url
if(url && action_handler){
View
@@ -3,7 +3,7 @@
module.exports.setup = function(o){
var sys = require("sys"),
app = o.app,
- redis = o.redis,
+// redis = o.redis,
socket = o.app.socket,
mongoose = o.mongoose,
io = o.io,
@@ -17,8 +17,6 @@ module.exports.setup = function(o){
require("./controllers.js").autoload(app);
require("./routes.js").draw(app);
- console.log( sys.inspect(Server.controllers) );
-
app.configure(function(){
app.set('view engine','haml');
app.set('views', o.paths.views);
@@ -31,7 +29,7 @@ module.exports.setup = function(o){
app.listen(o.port || 3000);
app.socket = io.listen(app);
-
+/*
// redis pub/sub with socket.io
redis.subscribeTo("socket-io-broadcast:*",function(channel,message,pattern){
var payload = JSON.stringify({
@@ -41,6 +39,6 @@ module.exports.setup = function(o){
app.socket.broadcast(payload);
});
-
+*/
};

0 comments on commit 900851b

Please sign in to comment.