Skip to content

Commit

Permalink
RT-MVC: Real time app generation and resource scaffolding is working
Browse files Browse the repository at this point in the history
  • Loading branch information
Techwraith committed Oct 27, 2012
1 parent 741bb80 commit 057bd49
Show file tree
Hide file tree
Showing 38 changed files with 803 additions and 32 deletions.
16 changes: 13 additions & 3 deletions bin/cli.js
Expand Up @@ -17,6 +17,7 @@ var cwd = process.cwd()
, usage
, cmd
, engineCmd
, rtCmd
, modelCmd
, filepath
, die
Expand All @@ -39,6 +40,7 @@ usage = [
, ' --workers, -w Number of worker processes to start (default: 1)'
, ' --debug, -d Sets the log level to output debug messages to'
, ' the console'
, ' --realtime, -r When generating or scaffolding, take realtime into account'
, ' --jade, -j When generating views this will create Jade'
, ' templates(Default: EJS)'
, ' --handle, -H When generating views this will create Handlebars'
Expand Down Expand Up @@ -92,6 +94,7 @@ optsMap = [
, { full: 'handle', abbr: 'H', args: false }
, { full: 'handlebars', abbr: 'H', args: false }
, { full: 'mustache', abbr: 'm', args: false }
, { full: 'realtime', abbr: 'r', args: false}
];

// Parse optsMap and generate options and cmd commands
Expand Down Expand Up @@ -144,7 +147,14 @@ if (cmds.length) {
engineCmd = ',' + 'handlebars';
} else if (opts.mustache) {
engineCmd = ',' + 'mustache';
} else engineCmd = '';
} else engineCmd = ',default';

if (opts.realtime) {
rtCmd = ',' + 'realtime';
}
else {
rtCmd = ',default';
}

// Get the model properties
if (cmds.slice(2).length > 0) {
Expand All @@ -171,15 +181,15 @@ if (cmds.length) {
break;
case 'app':
// Generating application
cmd += 'gen:app[' + cmds[1] + engineCmd + ']';
cmd += 'gen:app[' + cmds[1] + engineCmd + rtCmd + ']';
break;
case 'resource':
// Generating resource
cmd += 'gen:resource[' + cmds[1] + modelCmd + ']';
break;
case 'scaffold':
// Generating application
cmd += 'gen:scaffold[' + cmds[1] + engineCmd + modelCmd + ']';
cmd += 'gen:scaffold[' + cmds[1] + rtCmd + engineCmd + modelCmd + ']';
break;
case 'controller':
// Generating controller
Expand Down
2 changes: 1 addition & 1 deletion examples/socket_io/config/environment.js
Expand Up @@ -5,7 +5,7 @@ var config = {
}
*/

socketIo: true
realtime: true

};

Expand Down
2 changes: 1 addition & 1 deletion lib/app.js
Expand Up @@ -236,7 +236,7 @@ var App = function () {
// Load socket.io if it's enabled. This gets run after
// the server starts listening for requests. Socket.io
// won't work if we start it before.
if (geddy.config.socketIo) {
if (geddy.config.realtime) {
geddy.io = utils.file.requireLocal('socket.io').listen(geddy.server, {'log level': 0});
// add event listeners to all the models
// set up socket.io emitters for each event
Expand Down
33 changes: 23 additions & 10 deletions templates/Jakefile
Expand Up @@ -282,7 +282,7 @@ namespace('gen', function () {
};

// Creates a new Geddy app scaffold
task('app', function (name, engine) {
task('app', function (name, engine, realtime) {
var mkdirs
, cps
, text
Expand All @@ -291,9 +291,13 @@ namespace('gen', function () {
if (!name) {
throw new Error('No app name specified.');
}
if (!engine) {
if (!engine || engine == 'default') {
engine = 'ejs';
}
if (realtime == 'default') {
realtime = false;
}


mkdirs = [
''
Expand All @@ -307,11 +311,11 @@ namespace('gen', function () {
, 'test'
];
cps = [
['views/' + engine, 'app/views']
(realtime) ? ['realtime/views/' + engine, 'app/views'] : ['views/' + engine, 'app/views']
, ['public', '']
, ['router.js', 'config']
, ['init.js', 'config']
, ['environment.js', 'config']
, (realtime) ? ['realtime/environment.js', 'config'] : ['environment.js', 'config']
, ['development.js', 'config']
, ['production.js', 'config']
, ['main.js', 'app/controllers']
Expand Down Expand Up @@ -357,19 +361,22 @@ namespace('gen', function () {


// Creates a full scaffold with views, a model, controller and a resource route
task('scaffold', function (name, engine, modelProperties) {
task('scaffold', function (name, realtime, engine, modelProperties) {
var modelTask = jake.Task['gen:model'];

if (!modelProperties && engine) {
/*if (!modelProperties && engine) {
modelProperties = engine;
engine = '';
}
}*/
if (!name) {
throw new Error('No scaffold name specified.');
}
if (!engine) {
if (!engine || engine == 'default') {
engine = 'ejs';
}
if (!realtime || realtime == 'default') {
realtime = false;
}

modelTask.on('complete', function () {
jake.Task['gen:test'].invoke(name,
Expand All @@ -378,7 +385,7 @@ namespace('gen', function () {
{properties: modelProperties});
jake.Task['gen:route'].invoke(name);
jake.Task['gen:viewsScaffold'].invoke(name,
{engine: engine, properties: modelProperties});
{engine: engine, properties: modelProperties, realtime: realtime});
complete();
});
modelTask.invoke(name, modelProperties, 'scaffold');
Expand Down Expand Up @@ -611,10 +618,11 @@ namespace('gen', function () {
var names = utils.string.getInflections(name)
, engine = options.engine
, appViewDir = path.join('app', 'views', names.filename.plural)
, templateViewDir = path.join(__dirname, 'scaffold', 'views', engine)
, templateViewDir
, cmds = []
, ext = '.html'
, appLayoutPath
, layoutViewPath
, actions
, addActionView
, text
Expand All @@ -637,6 +645,11 @@ namespace('gen', function () {
break;
}

templateViewDir = options.realtime ?
path.join(__dirname, 'scaffold', 'realtime', 'views', engine) :
path.join(__dirname, 'scaffold', 'views', engine);


// Set application layout path
appLayoutPath = path.join('app', 'views', 'layouts', 'application');

Expand Down
2 changes: 1 addition & 1 deletion templates/base/development.js
Expand Up @@ -19,7 +19,7 @@
var config = {
detailedErrors: true
, debug: true
, hostname: null
, hostname: 'localhost'
, port: 4000
, model: {
defaultAdapter: 'memory'
Expand Down
5 changes: 0 additions & 5 deletions templates/base/environment.js
@@ -1,9 +1,4 @@
var config = {
/*
metrics: {
port: 4001
}
*/
};

module.exports = config;
2 changes: 1 addition & 1 deletion templates/base/production.js
Expand Up @@ -20,7 +20,7 @@ var config = {
detailedErrors: false
, hostname: null
, port: 4000
/* TODO: Define a defaultAdapter. You can use postgresdb, memory, mongo or riak.
/* TODO: Define a defaultAdapter. You can use postgresdb, memory, mongo or riak.
, model: {
defaultAdapter: 'mongo'
}
Expand Down
15 changes: 10 additions & 5 deletions templates/base/public/js/core/core.js
Expand Up @@ -12649,7 +12649,7 @@ utilities.mixin(geddy, utilities);

// require socket.io-client
geddy.io = require('socket.io-client');
geddy.socket = geddy.io.connect('http://localhost');
geddy.socket = geddy.io.connect('http://localhost:4000');

geddy.io.listenForModelEvents = function (model) {
var events = [
Expand All @@ -12659,18 +12659,21 @@ geddy.io.listenForModelEvents = function (model) {
];

for (var e in events) {
geddy.socket.on(model.modelName + ':' + events[e], function (data) {
(function (event) {
(function (event) {
geddy.socket.on(model.modelName + ':' + event, function (data) {
var instance;
if (typeof data != 'string') {
instance = model.create(data);
}
else {
instance = data;
}
if (geddy.debug == true) {
console.log(event, instance);
}
model.emit(event, instance);
})(events[e]);
});
});
})(events[e]);
};
}

Expand All @@ -12683,6 +12686,8 @@ geddy.io.addListenersForModels = function (models) {
}




});
require("/templates/build/build.js");
})();
5 changes: 5 additions & 0 deletions templates/base/realtime/environment.js
@@ -0,0 +1,5 @@
var config = {
realtime: true
};

module.exports = config;
53 changes: 53 additions & 0 deletions templates/base/realtime/views/ejs/layouts/application.html.ejs
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Geddy App | This app uses Geddy.js</title>
<meta name="description" content="">
<meta name="author" content="">

<meta name="viewport" content="width=device-width" />

<!-- The HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<%- scriptLink('/js/jquery.min.js', {type:'text/javascript'}) %>
<%- scriptLink('/js/bootstrap.min.js', {type:'text/javascript'}) %>
<%- scriptLink('/js/core/core.js', {type: 'text/javascript'}) %>
<%- scriptLink('/js/core/models.js', {type: 'text/javascript'}) %>

<%- styleLink('/css/bootstrap.min.css', {rel:'stylesheet'}) %>
<%- styleLink('/css/style.css', {rel:'stylesheet'}) %>
<%- styleLink('/css/bootstrap.responsive.min.css', {rel:'stylesheet'}) %>

<!-- The fav and touch icons -->
<link rel="shortcut icon" href="/images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="i-bar"><i class="icon-chevron-down icon-white"></i></span>
</a>
<%- linkTo('Geddy App', '/', { class: 'brand' }) %>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><%- linkTo('Home', '/') %></li>
<li><%- linkTo('Tutorial', 'http://geddyjs.org/tutorial') %></li>
<li><%- linkTo('Docs', 'http://geddyjs.org/documentation') %></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<%- yield(); %>
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions templates/base/realtime/views/ejs/main/index.html.ejs
@@ -0,0 +1,6 @@
<!-- Lets talk about geddy -->
<div class="hero-unit geddy-welcome-box">
<h1>Hello, World!</h1>
<p>You've created a Geddy app and your server is running. If you already know what you're doing, feel free to jump into your app logic, if not...</p>
<p><a href="http://geddyjs.org/tutorial.html" class="btn btn-primary btn-large">Lets get you started »</a></p>
</div>
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Geddy App | This app uses Geddy.js</title>
<meta name="description" content="">
<meta name="author" content="">

<meta name="viewport" content="width=device-width" />

<!-- The HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>

<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/css/bootstrap.responsive.min.css">

<!-- The fav and touch icons -->
<link rel="shortcut icon" href="/images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="i-bar"><i class="icon-chevron-down icon-white"></i></span>
</a>
<a class="brand" href="/">Geddy App</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="/">Home</a></li>
<li><a href="http://geddyjs.org/tutorial.html">Tutorial</a></li>
<!--<li><a href="http://geddyjs.org/docs.html">Docs</a></li>-->
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
{{{yield}}}
</div>
</body>
</html>
6 changes: 6 additions & 0 deletions templates/base/realtime/views/handlebars/main/index.html.hbs
@@ -0,0 +1,6 @@
<!-- Lets talk about geddy -->
<div class="hero-unit geddy-welcome-box">
<h1>Hello, World!</h1>
<p>You've created a Geddy app and your server is running. If you already know what you're doing, feel free to jump into your app logic, if not...</p>
<p><a href="http://geddyjs.org/tutorial.html" class="btn btn-primary btn-large">Lets get you started »</a></p>
</div>

0 comments on commit 057bd49

Please sign in to comment.