Permalink
Browse files

Updated readme to reflect new generators

Completed scaffold generator and made refinements to the other generators
  • Loading branch information...
1 parent 1282075 commit a0820314edac9d5a6dce0e24a2fe974cfa3ba732 @larzconwell larzconwell committed Jul 11, 2012
Showing with 653 additions and 193 deletions.
  1. +114 −77 README.md
  2. +0 −1 examples/todo_app_mongo/app/controllers/todos.js
  3. +1 −1 examples/todo_app_mongo/config/environment.js
  4. +8 −0 lib/template/helpers/index.js
  5. +118 −31 templates/Jakefile
  6. +25 −0 templates/base/public/css/style.css
  7. +2 −2 templates/resource/controller.ejs
  8. +1 −1 templates/resource/model.ejs
  9. +52 −11 templates/scaffold/controller.ejs
  10. +1 −1 templates/scaffold/model.ejs
  11. +0 −68 templates/scaffold/old_controller.ejs
  12. +48 −0 templates/scaffold/views/ejs/add.html.ejs.ejs
  13. +49 −0 templates/scaffold/views/ejs/edit.html.ejs.ejs
  14. +17 −0 templates/scaffold/views/ejs/index.html.ejs.ejs
  15. +12 −0 templates/scaffold/views/ejs/layout.html.ejs.ejs
  16. +16 −0 templates/scaffold/views/ejs/show.html.ejs.ejs
  17. +6 −0 templates/scaffold/views/handlebars/add.html.hbs
  18. +6 −0 templates/scaffold/views/handlebars/edit.html.hbs
  19. +6 −0 templates/scaffold/views/handlebars/index.html.hbs
  20. +12 −0 templates/scaffold/views/handlebars/layout.html.hbs
  21. +6 −0 templates/scaffold/views/handlebars/show.html.hbs
  22. +38 −0 templates/scaffold/views/jade/add.html.jade.ejs
  23. +39 −0 templates/scaffold/views/jade/edit.html.jade.ejs
  24. +13 −0 templates/scaffold/views/jade/index.html.jade.ejs
  25. +8 −0 templates/scaffold/views/jade/layout.html.jade.ejs
  26. +13 −0 templates/scaffold/views/jade/show.html.jade.ejs
  27. +6 −0 templates/scaffold/views/mustache/add.html.ms
  28. +6 −0 templates/scaffold/views/mustache/edit.html.ms
  29. +6 −0 templates/scaffold/views/mustache/index.html.ms
  30. +12 −0 templates/scaffold/views/mustache/layout.html.ms
  31. +6 −0 templates/scaffold/views/mustache/show.html.hbs
  32. +6 −0 templates/scaffold/views/mustache/show.html.ms
View
191 README.md
@@ -14,10 +14,11 @@ but still let you get under the hood and tinker if you want.
* Powerful, flexible router
* Easy resource-based routing
- * App and resource generators
+ * App, resource and scaffold generators
* Content-negotiation
* Session support (in-memory, cookie)
- * Templating (EJS), partials support
+ * Multiple template engine support(EJS, Jade, Mustache, Handlebars)
+ * View helpers([Docs](https://github.com/mde/geddy/wiki/View-Helpers))
* Fully non-blocking
### License
@@ -26,119 +27,157 @@ Apache License, Version 2
### Prerequisites
-Geddy requires version 0.4.x of Node.js or higher, and the
+Geddy requires version 0.6.x of Node.js or higher, and the
[Jake](https://github.com/mde/jake) JavaScript build-tool.
-### Installing
+### Installing from Github
-To get Geddy from GitHub and install it:
+To get Geddy from Github and install it do:
- git clone git://github.com/mde/geddy.git
- cd geddy
- make && sudo make install
+```
+git clone git@github.com:mde/geddy.git
+cd geddy
+make && sudo make install
+```
By default Geddy is installed in "/usr/local." To install it into a
different directory (e.g., one that doesn't require super-user
privilege), pass the PREFIX variable to the `make install` command.
For example, to install it into a "geddy" directory in your home
directory, you could use this:
- make && make install PREFIX=~/geddy
+```
+make && make install PREFIX=~/geddy
+```
If you do install Geddy somewhere special, you'll need to add the
"bin" directory in the install target to your PATH to get access
to the `geddy` executable.
### Installing with [NPM](http://npmjs.org/)
- npm install -g geddy
+```
+[sudo] npm -g install geddy
+```
-Note that Geddy (specifically, the generators) is a system-level
+Note: Geddy (specifically, the generators) is a system-level
tool, and wants to be installed globally.
-### Routes
+### Creating a Geddy application
-Routes are similar to Merb or Rails routes.
+To create Geddy applications simply run `geddy app <name>`.
+Then you can run `geddy` inside the application to start the server.
-**Basic routes**
+```
+mde@localhost:~/work$ geddy app bytor
+Created app bytor.
+mde@localhost:~/work$ cd bytor
+mde@localhost:~/work/bytor$ geddy
+Server running at http://127.0.0.1:4000/
+```
-```javascript
-router.match('/moving/pictures/:id').to(
- {controller: 'Moving', action: 'pictures'});
+Go to http://localhost:4000/, and you should see the introduction page.
-router.match('/farewells/:farewelltype/kings/:kingid').to(
- {controller: 'Farewells', action: 'kings'});
+### Generating resources
-//Can also match specific HTTP methods only
-router.match('/xandadu', 'get').to(
- {controller: 'Xandadu', action: 'specialHandler'});
+Use `geddy resource <name> [model properties]` to generate a resource in your application.
+Resources do not generate views, but creates a view directory. A resource route will be
+created for you.
+
+````
+mde@localhost:~/work$ geddy resource snow_dog breed:string name:string color:string
+[Added] app/models/snow_dog.js
+[Added] app/controllers/snow_dogs.js
+[Added] Resource snow_dogs route added to config/router.js
+[Added] snow_dogs view directory
```
-**Resource-based routes**
+Now start your Geddy server and your new route will work. Trying this for example
+will return the params for the index action in JSON:
- router.resource('hemispheres');
+```
+$ curl localhost:4000/snow_dogs.json
+{"params":{"method":"GET","controller":"SnowDogs","action":"index","format":"json"}}
+```
-### Creating a Geddy app
+Geddy generators handle plural inflections for model and controller names. ex: 'person' to 'people'
+To read about the model properties argument jump to [Model properties](#model-properties)
-You can use Geddy to create an app. Run `geddy app [app-name]` to
-create an app. Then Run `geddy` inside the app-directory to start
-the server.
+### Generating scaffolding
- mde@localhost:~/work$ geddy app bytor
- Created app bytor.
- mde@localhost:~/work$ cd bytor
- mde@localhost:~/work/bytor$ geddy
- Server running at http://127.0.0.1:4000/
+Use `geddy scaffold <name> [model properties]` to generate scaffoling in your application.
+Scaffolding creates full CRUD actions includes views, and will default your configuration to use
+[Mongodb](http://www.mongodb.org/) Resource routes will be created for you.
-Go to http://localhost:4000/, and you should see:
+````
+mde@localhost:~/work$ geddy resource snow_dog breed:string name:string color:string
+[Added] app/models/snow_dog.js
+[Added] app/controllers/snow_dogs.js
+[Added] Resource snow_dogs route added to config/router.js
+[Added] View templates
+[Added] Database configuration to config/environment.js
+```
-Attention all planets of the Solar Federation
+Now start your Geddy server and you'll have new views created from scaffolding. Trying this for example
+will return the content for the index action in HTML:
-### Adding resources
+```
+$ curl localhost:4000/snow_dogs
+<!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]-->
+
+.....
+```
+
+Geddy generators handle plural inflections for model and controller names. ex: 'person' to 'people'
+To read about the model properties argument jump to [Model properties](#model-properties)
+
+### Model properties
+
+Some Geddy generators (resource, scaffold and model) have a argument that takes a list of model
+properties. Here's an example of a resource with some properties:
-Use `geddy resource` in your app directory to add a
-resource. The route will be set up automatically for you.
+```
+geddy resource user name admin:boolean lastLogin:datetime
+```
- mde@localhost:~/work/bytor$ geddy resource snow_dog
- [ADDED] app/models/snow_dog.js
- [ADDED] app/controllers/snow_dogs.js
- Resource snow_dogs route added to config/router.js
- Created view templates.
+Each of these items include a name and an optional type, if there's no type given it'll default
+to string. The list of supported types are listed in the [model](https://github.com/mde/geddy/wiki/Models) documentation.
+If no id property is given then a default id property will be created with the type of string.
-Restart Geddy, and you'll see the new route working. Hit your
-new route -- for example, http://localhost:4000/snow_dogs.json,
-and you should see something like this:
+### Routes
- {"method":"index","params":{"extension":"json"}}
+Routes are created in a similar fashion to Merb or Rails.
-The geddy generator utility also handles fancy pluralization
-between model and controller. Specify your resource-name as a
-singular naun, and the generator will do the right thing --
-changing 'person' to 'people,' etc.
+***Basic routes***
+```
+router.match('/moving/pictures/:id').to(
+ {controller: 'Moving', action: 'pictures'});
-### App layout
+router.match('/farewells/:farewelltype/kings/:kingid').to(
+ {controller: 'Farewells', action: 'kings'});
-After adding a resource, a Geddy app is laid out like this:
+//Can also match specific HTTP methods only
+router.match('/xandadu', 'get').to(
+ {controller: 'Xandadu', action: 'specialHandler'});
+```
- mde@localhost:~/work/bytor$ find .
- .
- ./config
- ./config/config.js
- ./config/router.js
- ./app
- ./app/models
- ./app/models/snow_dog.js
- ./app/controllers
- ./app/controllers/snow_dogs.js
- ./app/controllers/main.js
- ./app/controllers/application.js
- ./app/views
- ./app/views/snow_dogs
- ./app/views/snow_dogs/edit.html.ejs
- ./app/views/snow_dogs/show.html.ejs
- ./app/views/snow_dogs/index.html.ejs
- ./app/views/snow_dogs/add.html.ejs
- ./public
+***Resource routes***
+```
+router.resource('hemispheres');
+```
### Resources and controllers
@@ -216,16 +255,14 @@ return in JSON format, pass your JavaScript object to the
this.respondsWith = ['text', 'json'];
this.show = function (params) {
- // (Fetch some item by params.id)
item = {foo: 'FOO', bar: 1, baz: false};
this.respond(item);
};
```
-
## Models and validations
Geddy has a simple way of defining models, with a full-featured
-set of data validations. The syntax is very similar to models in
+set of data validations. The syntax is similar to models in
Ruby's ActiveRecord or DataMapper.
Here is an example of a model with some validations:
@@ -299,9 +336,9 @@ var params = {
var user = User.create(params);
// Prints 'false'
-sys.puts(user.valid());
+util.puts(user.valid());
// Prints 'Field "password" is required'
-sys.puts(user.errors.password);
+util.puts(user.errors.password);
```
## Running the tests
View
1 examples/todo_app_mongo/app/controllers/todos.js
@@ -80,4 +80,3 @@ var Todos = function () {
};
exports.Todos = Todos;
-
View
2 examples/todo_app_mongo/config/environment.js
@@ -11,4 +11,4 @@ var config = {
*/
};
-module.exports = config;
+module.exports = config;
View
8 lib/template/helpers/index.js
@@ -349,3 +349,11 @@ exports.truncateHTML = {
//altName: 'truncate_HTML',
action: utils.string.truncateHTML
};
+
+exports.ಠ_ಠ = {
+ names: 'ಠ_ಠ',
+ altName: 'ಠ_ಠ',
+ action: function() {
+ return 'ಠ_ಠ';
+ }
+}
View
149 templates/Jakefile
@@ -23,14 +23,14 @@ namespace('gen', function () {
, filePath;
// Render with the right model name
- templ = new adapter({ data: {ext: '.ejs'}, text: text, templato: templato });
+ templ = new adapter({data: {ext: '.ejs'}, text: text, templato: templato});
templ.process({names: names, bare: bare, properties: options.properties});
// Write file
filePath = path.join('app', dirname, names.filename[options.inflection] + '.js');
fs.writeFileSync(filePath, templ.markup, 'utf8');
- console.log('[ADDED] ' + filePath);
+ console.log('[Added] ' + filePath);
};
var _getInflections = function (nameParam) {
@@ -72,22 +72,20 @@ namespace('gen', function () {
// Set defaults and alias's
if(!type) type = 'string';
- if(type === 'integer') type = 'number';
+ if(type === 'integer') type = 'int';
properties[name] = type;
}
// Check to see if a `id` property exists if not, add it
// Note: reverseMerge moves the default(or changed default) objects to the beginning
// of the object. Which is useful for our forEach hack in the model template
- properties = utils.object.reverseMerge(properties, { 'id': 'string' });
-
- return properties;
+ return utils.object.reverseMerge(properties, { 'id': 'string' });
};
// Creates a new Geddy app scaffold
task('app', [], function(name, engine) {
- if(!name) throw new Error('No app-name specified.');
+ if(!name) throw new Error('No app name specified.');
if(!engine) engine = 'ejs';
var mkdirs = [
@@ -124,18 +122,28 @@ namespace('gen', function () {
// Creates a resource with a model, controller and a resource route
task('resource', function(name, modelProperties) {
+ if(!name) throw new Error('No resource name specified.');
+ var names = _getInflections(name);
+
jake.Task['gen:model'].invoke(name, modelProperties);
jake.Task['gen:controller'].invoke(name);
jake.Task['gen:route'].invoke(name);
// Create views folder but not actions
- var names = _getInflections(name)
jake.mkdirP(path.join('app', 'views', names.filename.plural));
- console.log('Created ' + names.filename.plural + ' view folder.');
+
+ console.log('[Added] ' + names.filename.plural + ' view directory');
});
// Creates a full scaffold with views, a model, controller and a resource route
task('scaffold', function(name, engine, modelProperties) {
+ if(!modelProperties && engine) {
+ modelProperties = engine;
+ engine = '';
+ }
+ if(!name) throw new Error('No scaffold name specified.');
+ if(!engine) engine = 'ejs';
+
var jsEnvironment = path.normalize('config/environment.js')
, coffeeEnvironment = path.normalize('config/environment.coffee')
, environmentPath
@@ -152,9 +160,9 @@ namespace('gen', function () {
}
jake.Task['gen:modelScaffold'].invoke(name, modelProperties);
- jake.Task['gen:controllerScaffold'].invoke(name);
+ jake.Task['gen:controllerScaffold'].invoke(name, {properties: modelProperties});
jake.Task['gen:route'].invoke(name);
- jake.Task['gen:views'].invoke(name, {engine: engine });
+ jake.Task['gen:viewsScaffold'].invoke(name, {engine: engine, properties: modelProperties});
// Add the following line to `config/environment.js/.coffee`
if(environmentPath) {
@@ -180,41 +188,64 @@ namespace('gen', function () {
}
// Don't add the db config over and over
- if(text.indexOf(dbContent) == -1) {
+ if(text.indexOf('db:') == -1) {
environmentArr = text.split(splitText);
environmentArr[0] += splitText + '\n' + dbContent + '\n';
text = environmentArr.join('');
fs.writeFileSync(environmentPath, text, 'utf8');
- console.log('Database configuration added to ' + environmentPath);
- } else console.log('(Database configuration already set in ' + environmentPath + ')');
+ console.log('[Added] Database configuration to ' + environmentPath);
+ } else console.log('Database configuration already set in ' + environmentPath);
}
});
task('model', [], function(name, properties) {
+ if(!name) throw new Error('No model name specified.');
+
_writeTemplate(name, 'resource/model', 'models', {
inflection: 'singular'
, properties: _formatModelProperties(properties)
});
});
task('modelScaffold', [], function(name, properties) {
+ if(!name) throw new Error('No model name specified.');
+
_writeTemplate(name, 'scaffold/model', 'models', {
inflection: 'singular'
, properties: _formatModelProperties(properties)
});
});
task('controller', [], function(name) {
- _writeTemplate(name, 'resource/controller', 'controllers', { inflection: 'plural', bare: false });
+ if(!name) throw new Error('No controller name specified.');
+
+ _writeTemplate(name, 'resource/controller', 'controllers', {inflection: 'plural', bare: false});
+ });
+
+ task('controllerScaffold', [], function(name, options) {
+ if(!name) throw new Error('No controller name specified.');
+ options = options || {};
+
+ _writeTemplate(name, 'scaffold/controller', 'controllers', {
+ inflection: 'plural'
+ , bare: false
+ , properties: _formatModelProperties(options.properties)
+ });
});
- task('controllerScaffold', [], function(name) {
- _writeTemplate(name, 'scaffold/controller', 'controllers', { inflection: 'plural', bare: false });
+ task('bareController', [], function(name, engine) {
+ if(!name) throw new Error('No controller name specified.');
+ if(!engine) engine = 'ejs';
+
+ _writeTemplate(name, 'resource/controller', 'controllers', {inflection: 'plural', bare: true});
+ jake.Task['gen:route'].invoke(name, {bare: true});
+ jake.Task['gen:views'].invoke(name, {bare: true, engine: engine});
});
task('route', [], function(name, options) {
+ if(!name) throw new Error('No route name specified.');
options = options || {};
var names = _getInflections(name)
@@ -260,22 +291,24 @@ namespace('gen', function () {
text = routerArr.join('exports.router');
fs.writeFileSync(routerPath, text, 'utf8');
- console.log(routeType + ' ' + names.filename.plural +
+ console.log('[Added] ' + routeType + ' ' + names.filename.plural +
' route added to ' + routerPath);
}
else {
- console.log('(' + routeType + ' ' + names.filename.plural +
- ' route already defined in ' + routerPath + ')');
+ console.log(routeType + ' ' + names.filename.plural + ' route already defined in ' +
+ routerPath);
}
- } else console.log('There is no router file to add routes too.');
+ } else console.log('There is no router file to add routes too');
});
task('views', [], function(name, options) {
+ if(!name) throw new Error('No view name specified.');
+
options = options || {};
- // If `engine` option isn't set then default to EJS
- if(!options.engine) options.engine = 'ejs';
+ // Option defaults
+ options.engine = options.engine || 'ejs';
var names = _getInflections(name)
, engine = options.engine
@@ -319,18 +352,72 @@ namespace('gen', function () {
jake.cpR(path.join(templateViewDir, 'layout' + ext), appLayoutPath + ext);
}
- console.log('Created view templates.');
+ console.log('[Added] View templates');
});
- task('bareController', [], function(name, engine) {
- _writeTemplate(name, 'resource/controller', 'controllers', { inflection: 'plural', bare: true });
+ task('viewsScaffold', function(name, options) {
+ if(!name) throw new Error('No view name specified.');
+
+ options = options || {};
+
+ // Option defaults
+ options.engine = options.engine || 'ejs';
+
+ var names = _getInflections(name)
+ , engine = options.engine
+ , appViewDir = path.join('app', 'views', names.filename.plural)
+ , templateViewDir = path.join(__dirname, 'scaffold', 'views', engine)
+ , cmds = []
+ , ext = '.html'
+ , appLayoutPath
+ , actions
+ , addActionView
+ , text
+ , templ;
+
+ // Set extension based on engine option
+ if(engine === 'ejs') ext += '.ejs';
+ if(engine === 'jade') ext += '.jade';
+ if(engine === 'handlebars') ext += '.hbs';
+ if(engine === 'mustache') ext += '.ms';
+
+ // Set application layout path
+ appLayoutPath = path.join('app', 'views', 'layouts', 'application');
+
+ // Function to compile the template
+ addActionView = function(action) {
+ text = fs.readFileSync(path.join(templateViewDir, action + ext + '.ejs')).toString();
+
+ // Compile template text
+ templ = new adapter({data: {ext: '.ejs'}, text: text, templato: templato});
+ templ.process({names: names, properties: _formatModelProperties(options.properties)});
+
+ // Write file
+ fs.writeFileSync(path.join(appViewDir, action + ext),
+ templ.markup.replace(/<@/g, '<%').replace(/@>/g, '%>'), 'utf8');
+ };
+
+ jake.mkdirP(appViewDir);
+ jake.mkdirP('app/views/layouts');
+
+ // Add views for the other CRUD actions when doing a full-on resource
+ ['index', 'add', 'show', 'edit'].forEach(function(action) {
+ addActionView(action);
+ });
+
+ // Create default layout if one doesn't exist
+ // Hack: There should be a better way to detect if a application layout exists
+ if(!existsSync(appLayoutPath + '.html.ejs') && !existsSync(appLayoutPath + '.html.jade') &&
+ !existsSync(appLayoutPath + '.html.hbs') && !existsSync(appLayoutPath + '.html.ms')) {
+ // Copy template layout file to apps application layout file
+ jake.cpR(path.join(templateViewDir, 'layout' + ext), appLayoutPath + ext);
+ }
- jake.Task['gen:route'].invoke(name, { bare: true });
- jake.Task['gen:views'].invoke(name, { bare: true, engine: engine });
+ console.log('[Added] View templates');
});
// Generate a new application secret in environment.js
- task('secret', [], function(name) {
+ task('secret', [], function() {
var jsEnvironment = path.normalize('config/environment.js')
, coffeeEnvironment = path.normalize('config/environment.coffee')
, secret = utils.string.uuid(128)
@@ -362,8 +449,8 @@ namespace('gen', function () {
text = environmentArr.join(splitText);
fs.writeFileSync(environmentPath, text, 'utf8');
- console.log('app-secret added to ' + environmentPath + '.');
- } else console.log('There is no environment config to add the secret too.');
+ console.log('[Added] Application secret to \'' + environmentPath + '\'');
+ } else console.log('There is no environment config to add the secret too');
});
});
View
25 templates/base/public/css/style.css
@@ -29,3 +29,28 @@ body {
.geddy-welcome-box .btn-large {
margin-top: 20px;
}
+
+.list-item {
+ margin-bottom: 20px;
+}
+
+.list-item div {
+ background: white;
+ border-bottom: 2px solid #ccc;
+}
+
+.list-item div > * {
+ padding: 20px;
+}
+
+.list-item div h3 i {
+ margin: 5px;
+}
+
+@media (max-width:480px) {
+ .hero-unit .pull-right {
+ float: none;
+ margin-top: 10px;
+ }
+}
+
View
4 templates/resource/controller.ejs
@@ -4,7 +4,7 @@ var <%= names.constructor.plural %> = function () {
this.index = function (req, resp, params) {
this.respond({params: params});
};
-<% if(!bare) { -%>
+<% if(!bare) { %>
this.add = function (req, resp, params) {
this.respond({params: params});
};
@@ -30,7 +30,7 @@ var <%= names.constructor.plural %> = function () {
this.remove = function (req, resp, params) {
this.respond({params: params});
};
-<% } -%>
+<% } %>
};
exports.<%= names.constructor.plural %> = <%= names.constructor.plural %>;
View
2 templates/resource/model.ejs
@@ -5,7 +5,7 @@ var <%= names.constructor.singular %> = function () {
<%# Hack: ID property will always be first so we will manually take care of not inserting -%>
<%# A leading comma -%>
<% if(i === 'id') { -%>
- <%= i %>: {type: '<%= properties[i] %>'}
+ <%= i %>: {type: '<%= properties[i] %>', required: true}
<% } else { -%>
, <%= i %>: {type: '<%= properties[i] %>'}
<% } -%>
View
63 templates/scaffold/controller.ejs
@@ -1,37 +1,78 @@
var <%= names.constructor.plural %> = function () {
+ var <%= names.constructor.singular %> = geddy.model.adapter.<%= names.constructor.singular %>;
this.respondsWith = ['html', 'json', 'xml', 'js', 'txt'];
this.index = function (req, resp, params) {
- this.respond({params: params});
+ var self = this;
+
+ <%= names.constructor.singular %>.all(function(err, <%= names.property.plural %>) {
+ self.respond({params: params, <%= names.property.plural %>: <%= names.property.plural %>});
+ });
};
-<% if(!bare) { -%>
+<% if(!bare) { %>
this.add = function (req, resp, params) {
this.respond({params: params});
};
this.create = function (req, resp, params) {
- // Save the resource, then display index page
- this.redirect({controller: this.name});
+ params.id = params.id || geddy.string.uuid(10);
+ var self = this
+ , <%= names.property.singular %> = geddy.model.<%= names.constructor.singular %>.create(params);
+
+ <%= names.property.singular %>.save(function(err, data) {
+ if(err) {
+ params.errors = err;
+ self.transfer('add');
+ } else self.redirect({controller: self.name});
+ });
};
this.show = function (req, resp, params) {
- this.respond({params: params});
+ var self = this;
+
+ <%= names.constructor.singular %>.load(params.id, function(err, <%= names.property.singular %>) {
+ self.respond({params: params, <%= names.property.singular %>: <%= names.property.singular %>});
+ });
};
this.edit = function (req, resp, params) {
- this.respond({params: params});
+ var self = this;
+
+ <%= names.constructor.singular %>.load(params.id, function(err, <%= names.property.singular %>) {
+ self.respond({params: params, <%= names.property.singular %>: <%= names.property.singular %>});
+ });
};
this.update = function (req, resp, params) {
- // Save the resource, then display the item page
- this.redirect({controller: this.name, id: params.id});
+ var self = this;
+
+ <%= names.constructor.singular %>.load(params.id, function(err, <%= names.property.singular %>) {
+ <%= names.constructor.singular %>.save(function(err, data) {
+<% for(var prop in properties) { -%>
+<% if(prop !== 'id') { -%>
+ <%= names.property.singular %>.<%= prop %> = params.<%= prop %>;
+<% } -%>
+<% } -%>
+
+ if(err) {
+ params.errors = err;
+ self.transfer('edit');
+ } else self.redirect({controller: self.name});
+ });
+ });
};
this.remove = function (req, resp, params) {
- this.respond({params: params});
+ var self = this;
+
+ <%= names.constructor.singular %>.remove(params.id, function(err) {
+ if(err) {
+ params.errors = err;
+ self.transfer('edit');
+ } else self.redirect({controller: self.name});
+ });
};
-<% } -%>
+<% } %>
};
exports.<%= names.constructor.plural %> = <%= names.constructor.plural %>;
-
View
2 templates/scaffold/model.ejs
@@ -5,7 +5,7 @@ var <%= names.constructor.singular %> = function () {
<%# Hack: ID property will always be first so we will manually take care of not inserting -%>
<%# A leading comma -%>
<% if(i === 'id') { -%>
- <%= i %>: {type: '<%= properties[i] %>'}
+ <%= i %>: {type: '<%= properties[i] %>', required: true}
<% } else { -%>
, <%= i %>: {type: '<%= properties[i] %>'}
<% } -%>
View
68 templates/scaffold/old_controller.ejs
@@ -1,68 +0,0 @@
-var <%= names.constructor.plural %> = function () {
- var self = this;
- this.respondsWith = ['html', 'json', 'js', 'txt'];
-
- this.index = function (params) {
- <%= names.constructor.singular %>.all(function (err, items) {
- if (err) throw err;
- params.items = items;
- self.respond({params: params});
- });
- };
-
- this.add = function (params) {
- this.respond({params: params});
- };
-
- this.create = function (params) {
- var item = <%= names.constructor.singular %>.create(params);
- item.save(function (err, res) {
- if (err) {
- params.errors = err;
- self.transfer('add');
- }
- else {
- self.redirect({controller: self.name});
- }
- });
- };
-
- this.show = function (params) {
- <%= names.constructor.singular %>.find(params.id, function (err, items) {
- if (err) throw err;
- params.item = items[0];
- self.respond({params: params});
- });
- };
-
- this.edit = function (params) {
- <%= names.constructor.singular %>.find(params.id, function (err, items) {
- if (err) throw err;
- geddy.util.meta.mixin(params, items[0]);
- self.respond({params: params});
- });
- };
-
- this.update = function (params) {
- <%= names.constructor.singular %>.update(params.id, params, function (err, res) {
- if (err) {
- params.errors = err;
- self.transfer('edit');
- }
- else {
- self.redirect({controller: self.name});
- }
- });
- };
-
- this.remove = function (params) {
- <%= names.constructor.singular %>.remove(params.id, function (err, items) {
- if (err) throw err;
- self.redirect({controller: self.name});
- });
- };
-
-};
-
-exports.<%= names.constructor.plural %> = <%= names.constructor.plural %>;
-
View
48 templates/scaffold/views/ejs/add.html.ejs.ejs
@@ -0,0 +1,48 @@
+<div class="hero-unit">
+ <form id="<%= names.property.singular %>-form" class="form-horizontal" action="/<%= names.property.plural %>" method="POST">
+ <fieldset>
+ <legend>Create a new <%= names.constructor.singular %></legend>
+ <@ if(params.errors) { @>
+ <div class="control-group">
+ <ul>
+ <@ for(var err in params.errors) { @>
+ <li><@= params.errors[err]; @></li>
+ <%% } %>
+ </ul>
+ </div>
+ <%% } %>
+<% for(var i in properties) { -%>
+<% if(i !== 'id') { -%>
+ <div class="control-group">
+ <label for="<%= i %>"><%= i %></label>
+ <div class="controls">
+<% if(properties[i] === 'string') { -%>
+<% if(i === 'password') { -%>
+ <@- contentTag('input', '', {type:'password', class:'span6', placeholder:'enter <%= i %>', name:'<%= i %>'}) @>
+<% } else { -%>
+ <@- contentTag('input', '', {type:'text', class:'span6', placeholder:'enter <%= i %>', name:'<%= i %>'}) @>
+<% } -%>
+<% } else if(properties[i] === 'number' || properties[i] === 'int') { -%>
+ <@- contentTag('input', '', {type:'number', class:'span2', placeholder:'enter <%= i %>', name:'<%= i %>'}) @>
+<% } else if(properties[i] === 'boolean') { -%>
+ <select name="<%= i %>", class="span1">
+ <option selected>false</option>
+ <option>true</option>
+ </select>
+<% } else if(properties[i] === 'datetime') { -%>
+ <@- contentTag('input', '', {type:'datetime', class:'span3', name:'<%= i %>'}) @>
+<% } else if(properties[i] === 'date') { -%>
+ <@- contentTag('input', '', {type:'date', class:'span2', name:'<%= i %>'}) @>
+<% } else { -%>
+ <%= properties[i] %>
+<% } -%>
+ </div>
+ </div>
+<% } -%>
+<% } -%>
+ <div class="form-actions">
+ <@- contentTag('input', 'Add', {type: 'submit', class: 'btn btn-primary'}) @>
+ </div>
+ </fieldset>
+ </form>
+</div>
View
49 templates/scaffold/views/ejs/edit.html.ejs.ejs
@@ -0,0 +1,49 @@
+<div class="hero-unit">
+ <form id="<%= names.property.singular %>-form" class="form-horizontal" action="/<%= names.property.plural %>/<@= params.id @>?_method=PUT" method="POST">
+ <fieldset>
+ <legend>Update this <%= names.constructor.singular %></legend>
+ <@ if(params.errors) { @>
+ <div class="control-group">
+ <ul>
+ <@ for(var err in params.errors) { @>
+ <li><@= params.errors[err]; @></li>
+ <%% } %>
+ </ul>
+ </div>
+ <%% } %>
+<% for(var i in properties) { -%>
+<% if(i !== 'id') { -%>
+ <div class="control-group">
+ <label for="<%= i %>"><%= i %></label>
+ <div class="controls">
+<% if(properties[i] === 'string') { -%>
+<% if(i === 'password') { -%>
+ <@- contentTag('input', '', {type:'password', class:'span6', placeholder:'enter <%= i %>', name:'<%= i %>'}) @>
+<% } else { -%>
+ <@- contentTag('input', '', {type:'text', class:'span6', placeholder:'enter <%= i %>', name:'<%= i %>'}) @>
+<% } -%>
+<% } else if(properties[i] === 'number' || properties[i] === 'int') { -%>
+ <@- contentTag('input', '', {type:'number', class:'span2', placeholder:'enter <%= i %>', name:'<%= i %>'}) @>
+<% } else if(properties[i] === 'boolean') { -%>
+ <select name="<%= i %>", class="span1">
+ <option selected>false</option>
+ <option>true</option>
+ </select>
+<% } else if(properties[i] === 'datetime') { -%>
+ <@- contentTag('input', '', {type:'datetime', class:'span3', name:'<%= i %>'}) @>
+<% } else if(properties[i] === 'date') { -%>
+ <@- contentTag('input', '', {type:'date', class:'span2', name:'<%= i %>'}) @>
+<% } else { -%>
+ <%= properties[i] %>
+<% } -%>
+ </div>
+ </div>
+<% } -%>
+<% } -%>
+ <div class="form-actions">
+ <@- contentTag('input', 'Save', {type: 'submit', class: 'btn btn-primary'}) @>
+ <@- contentTag('button', 'Remove', {type: 'submit', formaction: '/<%= names.property.plural %>/' + params.id + '?_method=DELETE', formmethod: 'POST', class: 'btn btn-danger'}) @>
+ </div>
+ </fieldset>
+ </form>
+</div>
View
17 templates/scaffold/views/ejs/index.html.ejs.ejs
@@ -0,0 +1,17 @@
+<div class="hero-unit">
+ <h2>All <%= names.constructor.plural %></h2>
+ <@- linkTo('Create a new <%= names.constructor.singular %>', {controller: '<%= names.property.plural %>', action: 'add'}, {class: 'btn pull-right'}); @>
+</div>
+
+<@ if(<%= names.property.plural %>) { @>
+<@ for(var i in <%= names.property.plural %>) { @>
+<div class="row list-item">
+ <div class="span8">
+ <h3><@- linkTo(<%= names.property.plural %>[i].id, {controller: '<%= names.property.plural %>', id: <%= names.property.plural %>[i].id, action: 'show'}); @></h3>
+ </div>
+ <div class="span4">
+ <h3><i class="icon-list-alt"></i><@= <%= names.property.plural %>[i].id; @></h3>
+ </div>
+</div>
+<%% } %>
+<%% } %>
View
12 templates/scaffold/views/ejs/layout.html.ejs.ejs
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>Geddy App | This app uses Geddy.js</title>
+ </head>
+ <body>
+ <div class="container">
+ <%- yield(); %>
+ </div>
+ </body>
+</html>
View
16 templates/scaffold/views/ejs/show.html.ejs.ejs
@@ -0,0 +1,16 @@
+<div class="hero-unit">
+ <h2><@= <%= names.property.singular %>.id @></h2>
+ <@- linkTo('Edit this <%= names.property.singular %>', {controller: '<%= names.property.plural %>', action: 'edit', id: params.id}, {class: 'btn pull-right'}); @>
+</div>
+
+<h2><%= names.constructor.singular %> Properties</h2>
+<@ for(var i in <%= names.property.singular %>) { -@>
+<div class="row list-item">
+ <div class="span8">
+ <h3><@= i @></h3>
+ </div>
+ <div class="span4">
+ <h3><i class="icon-list-alt"></i><@= <%= names.property.singular %>[i] @></h3>
+ </div>
+</div>
+<%% } -%>
View
6 templates/scaffold/views/handlebars/add.html.hbs
@@ -0,0 +1,6 @@
+<div class="hero-unit">
+ <h3>Params</h3>
+ {{#params}}
+ <p>{{action}} action on {{controller}} controller.</p>
+ {{/params}}
+</div>
View
6 templates/scaffold/views/handlebars/edit.html.hbs
@@ -0,0 +1,6 @@
+<div class="hero-unit">
+ <h3>Params</h3>
+ {{#params}}
+ <p>{{action}} action on {{controller}} controller.</p>
+ {{/params}}
+</div>
View
6 templates/scaffold/views/handlebars/index.html.hbs
@@ -0,0 +1,6 @@
+<div class="hero-unit">
+ <h3>Params</h3>
+ {{#params}}
+ <p>{{action}} action on {{controller}} controller.</p>
+ {{/params}}
+</div>
View
12 templates/scaffold/views/handlebars/layout.html.hbs
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>Geddy App | This app uses Geddy.js</title>
+ </head>
+ <body>
+ <div class="container">
+ {{{yield}}}
+ </div>
+ </body>
+</html>
View
6 templates/scaffold/views/handlebars/show.html.hbs
@@ -0,0 +1,6 @@
+<div class="hero-unit">
+ <h3>Params</h3>
+ {{#params}}
+ <p>{{action}} action on {{controller}} controller.</p>
+ {{/params}}
+</div>
View
38 templates/scaffold/views/jade/add.html.jade.ejs
@@ -0,0 +1,38 @@
+.hero-unit
+ form#<%= names.property.singular %>-form.form-horizontal(action="/<%= names.property.plural %>", method="POST")
+ fieldset
+ legend Create a new <%= names.constructor.singular %>
+ if params.errors
+ .control-group
+ ul
+ for err in params.errors
+ li= err
+
+<% for(var i in properties) { -%>
+ .control-group
+ label(for="<%= i %>") <%= i %>
+ .controls
+<% if(properties[i] === 'string') { -%>
+<% if(i === 'password') { -%>
+ != contentTag('input', '', {type:'password', class:'span6', placeholder:'enter <%= i %>', name:'<%= i %>'})
+<% } else { -%>
+ != contentTag('input', '', {type:'text', class:'span6', placeholder:'enter <%= i %>', name:'<%= i %>'})
+<% } -%>
+<% } else if(properties[i] === 'number' || properties[i] === 'int') { -%>
+ != contentTag('input', '', {type:'number', class:'span2', placeholder:'enter <%= i %>', name:'<%= i %>'})
+<% } else if(properties[i] === 'boolean') { -%>
+ select.span1(name="<%= i %>")
+ option(selected) false
+ option true
+<% } else if(properties[i] === 'datetime') { -%>
+ != contentTag('input', '', {type:'datetime', class:'span3', name:'<%= i %>'})
+<% } else if(properties[i] === 'date') { -%>
+ != contentTag('input', '', {type:'date', class:'span2', name:'<%= i %>'})
+<% } else { -%>
+ = properties[i]
+<% } -%>
+<% if(i !== 'id') { -%>
+<% } -%>
+<% } -%>
+ .form-actions
+ != contentTag('input', 'Add', {type: 'submit', class: 'btn btn-primary'})
View
39 templates/scaffold/views/jade/edit.html.jade.ejs
@@ -0,0 +1,39 @@
+.hero-unit
+ form#<%= names.property.singular %>-form.form-horizontal(action="/<%= names.property.plural %>/<@= params.id @>?_method=PUT", method="POST")
+ fieldset
+ legend Update this <%= names.constructor.singular %>
+ if params.errors
+ .control-group
+ ul
+ for err in params.errors
+ li= err
+
+<% for(var i in properties) { -%>
+ .control-group
+ label(for="<%= i %>") <%= i %>
+ .controls
+<% if(properties[i] === 'string') { -%>
+<% if(i === 'password') { -%>
+ != contentTag('input', '', {type:'password', class:'span6', placeholder:'enter <%= i %>', name:'<%= i %>'})
+<% } else { -%>
+ != contentTag('input', '', {type:'text', class:'span6', placeholder:'enter <%= i %>', name:'<%= i %>'})
+<% } -%>
+<% } else if(properties[i] === 'number' || properties[i] === 'int') { -%>
+ != contentTag('input', '', {type:'number', class:'span2', placeholder:'enter <%= i %>', name:'<%= i %>'})
+<% } else if(properties[i] === 'boolean') { -%>
+ select.span1(name="<%= i %>")
+ option(selected) false
+ option true
+<% } else if(properties[i] === 'datetime') { -%>
+ != contentTag('input', '', {type:'datetime', class:'span3', name:'<%= i %>'})
+<% } else if(properties[i] === 'date') { -%>
+ != contentTag('input', '', {type:'date', class:'span2', name:'<%= i %>'})
+<% } else { -%>
+ = properties[i]
+<% } -%>
+<% if(i !== 'id') { -%>
+<% } -%>
+<% } -%>
+ .form-actions
+ != contentTag('input', 'Save', {type: 'submit', class: 'btn btn-primary'})
+ != contentTag('button', 'Remove', {type: 'submit', formaction: '/<%= names.property.plural %>/' + params.id + '?_method=DELETE', formmethod: 'POST', class: 'btn btn-danger'})
View
13 templates/scaffold/views/jade/index.html.jade.ejs
@@ -0,0 +1,13 @@
+.hero-unit
+ h2 All <%= names.constructor.plural %>
+ != linkTo('Create a new <%= names.constructor.singular %>', {controller: '<%= names.property.plural %>', action: 'add'}, {class: 'btn pull-right'})
+
+if <%= names.property.plural %>
+ each <%= names.property.singular %> in <%= names.property.plural %>
+ .row.list-item
+ .span8
+ h3!= linkTo(<%= names.property.singular %>.id, {controller: '<%= names.property.plural %>', id: <%= names.property.singular %>.id, action: 'show'})
+ .span4
+ h3
+ i.icon-list-alt
+ = <%= names.property.singular %>.id
View
8 templates/scaffold/views/jade/layout.html.jade.ejs
@@ -0,0 +1,8 @@
+!!! html
+html(lang="en")
+ head
+ meta(charset="utf-8")
+ title Geddy App | This app uses Geddy.js
+ body
+ .container
+ != yield()
View
13 templates/scaffold/views/jade/show.html.jade.ejs
@@ -0,0 +1,13 @@
+.hero-unit
+ h2= <%= names.property.singular %>.id
+ != linkTo('Edit this <%= names.property.singular %>', {controller: '<%= names.property.plural %>', action: 'edit', id: params.id}, {class: 'btn pull-right'})
+
+h2 <%= names.constructor.singular %> Properties
+each property in <%= names.property.singular %>
+ .row.list-item
+ .span8
+ h3= property
+ .span4
+ h3
+ i.icon-list-alt
+ = <%= names.property.singular %>[i]
View
6 templates/scaffold/views/mustache/add.html.ms
@@ -0,0 +1,6 @@
+<div class="hero-unit">
+ <h3>Params</h3>
+ {{#params}}
+ <p>{{action}} action on {{controller}} controller.</p>
+ {{/params}}
+</div>
View
6 templates/scaffold/views/mustache/edit.html.ms
@@ -0,0 +1,6 @@
+<div class="hero-unit">
+ <h3>Params</h3>
+ {{#params}}
+ <p>{{action}} action on {{controller}} controller.</p>
+ {{/params}}
+</div>
View
6 templates/scaffold/views/mustache/index.html.ms
@@ -0,0 +1,6 @@
+<div class="hero-unit">
+ <h3>Params</h3>
+ {{#params}}
+ <p>{{action}} action on {{controller}} controller.</p>
+ {{/params}}
+</div>
View
12 templates/scaffold/views/mustache/layout.html.ms
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>Geddy App | This app uses Geddy.js</title>
+ </head>
+ <body>
+ <div class="container">
+ {{{yield}}}
+ </div>
+ </body>
+</html>
View
6 templates/scaffold/views/mustache/show.html.hbs
@@ -0,0 +1,6 @@
+<div class="hero-unit">
+ <h3>Params</h3>
+ {{#params}}
+ <p>{{action}} action on {{controller}} controller.</p>
+ {{/params}}
+</div>
View
6 templates/scaffold/views/mustache/show.html.ms
@@ -0,0 +1,6 @@
+<div class="hero-unit">
+ <h3>Params</h3>
+ {{#params}}
+ <p>{{action}} action on {{controller}} controller.</p>
+ {{/params}}
+</div>

0 comments on commit a082031

Please sign in to comment.