Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added subgenerators: Model, Controller and View.
- Loading branch information
Showing
11 changed files
with
148 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) %>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
class <%= _.classify(modelName) %> extends Monocle.Model | ||
@fields "<%= modelFields.join('", "') %>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
class <%= _.classify(viewName) %> extends Monocle.View | ||
|
||
container: "div#<%= _.underscored(pluralViewName) %>" | ||
|
||
template_url: "templates/<%= _.underscored(viewName) %>.mustache" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
<div id="<%= _.underscored(pluralViewName) %>"> | ||
<!-- Replace: start --> | ||
<h1>Find me here:</h1> | ||
<code><%= mustacheTemplatePath %></code> | ||
<!-- Replace: end --> | ||
</div> |