Permalink
Browse files

Added subgenerators: Model, Controller and View.

  • Loading branch information...
eduludi committed Oct 2, 2013
1 parent 58637fa commit 4c2e13834135984f8c5b458a053cfbf14947a286
View
@@ -1,40 +1,77 @@
generator-lqm
=============
-An Lungo-Quo-Monocle MVC app generator for [Yeoman](http://yeoman.io).
-
+An [Lungo](http://lungo.tapquo.com)-[Quo](http://quojs.tapquo.com)-[Monocle](http://monocle.tapquo.com) MVC app generator for [Yeoman](http://yeoman.io).
## Getting Started
-### What is Yeoman?
+### Requirements
+1. [node](http://nodejs.org/)
+2. [git](http://git-scm.org/)
+3. Yeoman:
+
+```
+$ npm install -g yo
+```
-Trick question. It's not a thing. It's this guy:
+### Install and Usage
-![](http://i.imgur.com/JHaAlBJ.png)
+To install generator-lqm from npm, run:
-Basically, he wears a top hat, lives in your computer, and waits for you to tell him what kind of application you wish to create.
+```
+$ npm install -g generator-lqm
+```
-Not every new computer comes with a Yeoman pre-installed. He lives in the [npm](https://npmjs.org) package repository. You only have to ask for him once, then he packs up and moves into your hard drive. *Make sure you clean up, he likes new and shiny things.*
+Finally, initiate the generator in your desired folder:
```
-$ npm install -g yo
+$ mkdir myApp
+$ cd myApp
+$ yo lqm
```
+### Subgenerators
-### Yeoman Generators
+#### Model
-Yeoman travels light. He didn't pack any generators when he moved in. You can think of a generator like a plug-in. You get to choose what type of application you wish to create, such as a Backbone application or even a Chrome extension.
+```
+$ yo lqm:model "ModelName attribute_a attribute_b attribute_x"
+```
-To install generator-lqm from npm, run:
+Example:
```
-$ npm install -g generator-lqm
+$ yo lqm:model "Task name description done"
```
-Finally, initiate the generator:
+#### View
```
-$ yo lqm
+$ yo lqm:view "ViewName"
+
+```
+
+Example:
+
+```
+$ yo lqm:view "Task"
+```
+
+#### Controller
+
```
+$ yo lqm:controller "ControllerName"
+```
+
+Example:
+
+```
+$ yo lqm:controller "Tasks"
+```
+
+#### Full Scaffold (ala Rails)
+
+Work in progress... (coming soon)
+
### Getting To Know Yeoman
View
@@ -19,9 +19,6 @@ util.inherits(LqmGenerator, yeoman.generators.Base);
LqmGenerator.prototype.askFor = function askFor() {
var cb = this.async();
- // have Yeoman greet the user.
- //console.log(this.yeoman);
-
var prompts = [{
name: 'applicationName',
message: 'What do you want to call your app?'
@@ -54,7 +51,6 @@ LqmGenerator.prototype.projectfiles = function projectfiles() {
this.copy('jshintrc', '.jshintrc');
};
-
LqmGenerator.prototype.runtime = function projectfiles() {
this.copy('bowerrc', '.bowerrc');
this.copy('gitignore', '.gitignore');
@@ -8,7 +8,7 @@
"grunt-contrib-watch": "~0.4.3",
"grunt-contrib-coffee": "~0.7.0",
"grunt-contrib-jshint": "~0.6.4",
- "grunt-contrib-uglify": "~0.2.4",
+ "grunt-contrib-uglify": "~0.2.4"
"grunt-open": "~0.2.0",
"matchdep": "~0.1.2",
"connect-livereload": "~0.1.3",
View
@@ -0,0 +1,19 @@
+'use strict';
+var util = require('util');
+var yeoman = require('yeoman-generator');
+var fleck = require('fleck');
+
+var ControllerGenerator = module.exports = function ControllerGenerator(args, options, config) {
+ // By calling `NamedBase` here, we get the argument to the subgenerator call
+ // as `this.name`.
+ yeoman.generators.NamedBase.apply(this, arguments);
+
+ this.controllerName = fleck.singularize(this.name,1);
+ this.pluralControllerName = fleck.pluralize(this.name,2);
+};
+
+util.inherits(ControllerGenerator, yeoman.generators.NamedBase);
+
+ControllerGenerator.prototype.files = function files() {
+ this.template('controller.coffee', 'app/controllers/'+this._.underscored(this.controllerName)+'.coffee');
+};
@@ -0,0 +1,16 @@
+
+class <%= _.classify(pluralControllerName) %> extends Monocle.Controller
+
+ constructor: ->
+ super
+ @routes
+ "/<%= _.underscored(pluralControllerName) %>" : @list<%= _.classify(pluralControllerName) %>
+ "/<%= _.underscored(controllerName) %>/:id" : @view<%= _.classify(controllerName) %>
+ Monocle.Route.listen()
+
+ list<%= _.classify(pluralControllerName) %>: (params) ->
+ console.log "List all tasks"
+ view<%= _.classify(controllerName) %>: (params) ->
+ console.log "You choose <%= _.humanize(controllerName) %> with id: #{params.id}"
+
+controller = new <%= _.classify(pluralControllerName) %> "section#<%= _.underscored(pluralControllerName) %>"
View
@@ -0,0 +1,20 @@
+'use strict';
+var util = require('util');
+var yeoman = require('yeoman-generator');
+var fleck = require('fleck');
+
+var ModelGenerator = module.exports = function ModelGenerator(args, options, config) {
+ // By calling `NamedBase` here, we get the argument to the subgenerator call
+ // as `this.name`.
+ yeoman.generators.NamedBase.apply(this, arguments);
+
+ var params = this.name.split(" ");
+ this.modelName = fleck.singularize(params.shift());
+ this.modelFields = params;
+};
+
+util.inherits(ModelGenerator, yeoman.generators.NamedBase);
+
+ModelGenerator.prototype.files = function files() {
+ this.template('model.coffee','app/models/'+this._.underscored(this.modelName)+'.coffee');
+};
@@ -0,0 +1,3 @@
+
+class <%= _.classify(modelName) %> extends Monocle.Model
+ @fields "<%= modelFields.join('", "') %>"
View
@@ -1,7 +1,7 @@
{
"name": "generator-lqm",
- "version": "0.1.0",
- "description": "An Lungo-Quo-Monocle MVC app generator for Yeoman",
+ "version": "0.1.1",
+ "description": "A Lungo-Quo-Monocle MVC app generator for Yeoman",
"keywords": [
"lungo quo monocle yeoman-generator mvc"
],
@@ -21,7 +21,8 @@
"test": "mocha"
},
"dependencies": {
- "yeoman-generator": "~0.13.0"
+ "yeoman-generator": "~0.13.0",
+ "fleck": "~0.5.1"
},
"devDependencies": {
"mocha": "~1.12.0"
View
@@ -0,0 +1,21 @@
+'use strict';
+var util = require('util');
+var yeoman = require('yeoman-generator');
+var fleck = require('fleck');
+
+var ViewGenerator = module.exports = function ViewGenerator(args, options, config) {
+ // By calling `NamedBase` here, we get the argument to the subgenerator call
+ // as `this.name`.
+ yeoman.generators.NamedBase.apply(this, arguments);
+
+ this.viewName = fleck.singularize(this.name);
+ this.pluralViewName = fleck.pluralize(this.name);
+ this.mustacheTemplatePath = 'app/templates/'+this._.underscored(this.viewName)+'.mustache';
+};
+
+util.inherits(ViewGenerator, yeoman.generators.NamedBase);
+
+ViewGenerator.prototype.files = function files() {
+ this.template('view.coffee', 'app/views/'+this._.underscored(this.viewName)+'.coffee');
+ this.template('view.mustache',this.mustacheTemplatePath);
+};
@@ -0,0 +1,6 @@
+
+class <%= _.classify(viewName) %> extends Monocle.View
+
+ container: "div#<%= _.underscored(pluralViewName) %>"
+
+ template_url: "templates/<%= _.underscored(viewName) %>.mustache"
@@ -0,0 +1,7 @@
+
+<div id="<%= _.underscored(pluralViewName) %>">
+ <!-- Replace: start -->
+ <h1>Find me here:</h1>
+ <code><%= mustacheTemplatePath %></code>
+ <!-- Replace: end -->
+</div>

0 comments on commit 4c2e138

Please sign in to comment.