diff --git a/README.md b/README.md index 1a0dad2..3adb3b4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/index.js b/app/index.js index bbd241d..9a86761 100644 --- a/app/index.js +++ b/app/index.js @@ -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'); diff --git a/app/templates/_package.json b/app/templates/_package.json index 69fa6c3..a6ed829 100644 --- a/app/templates/_package.json +++ b/app/templates/_package.json @@ -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", diff --git a/controller/index.js b/controller/index.js new file mode 100644 index 0000000..1ad5280 --- /dev/null +++ b/controller/index.js @@ -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'); +}; diff --git a/controller/templates/controller.coffee b/controller/templates/controller.coffee new file mode 100644 index 0000000..ec36ac4 --- /dev/null +++ b/controller/templates/controller.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) %>" \ No newline at end of file diff --git a/model/index.js b/model/index.js new file mode 100644 index 0000000..cc0da71 --- /dev/null +++ b/model/index.js @@ -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'); +}; diff --git a/model/templates/model.coffee b/model/templates/model.coffee new file mode 100644 index 0000000..50382f3 --- /dev/null +++ b/model/templates/model.coffee @@ -0,0 +1,3 @@ + +class <%= _.classify(modelName) %> extends Monocle.Model + @fields "<%= modelFields.join('", "') %>" \ No newline at end of file diff --git a/package.json b/package.json index 1c95196..520b359 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/view/index.js b/view/index.js new file mode 100644 index 0000000..2d97571 --- /dev/null +++ b/view/index.js @@ -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); +}; diff --git a/view/templates/view.coffee b/view/templates/view.coffee new file mode 100644 index 0000000..27b6564 --- /dev/null +++ b/view/templates/view.coffee @@ -0,0 +1,6 @@ + +class <%= _.classify(viewName) %> extends Monocle.View + + container: "div#<%= _.underscored(pluralViewName) %>" + + template_url: "templates/<%= _.underscored(viewName) %>.mustache" \ No newline at end of file diff --git a/view/templates/view.mustache b/view/templates/view.mustache new file mode 100644 index 0000000..4f51024 --- /dev/null +++ b/view/templates/view.mustache @@ -0,0 +1,7 @@ + +
+ +

Find me here:

+ <%= mustacheTemplatePath %> + +
\ No newline at end of file