This repository has been archived by the owner on Jan 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
general cleanup, new way of loading templates in the generator intern…
…ally, and added ability to pass model path to collection
- Loading branch information
Matt Przybylski
committed
Oct 31, 2013
1 parent
560704b
commit 3354029
Showing
40 changed files
with
196 additions
and
208 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,22 @@ | ||
/*jshint latedef:false */ | ||
var path = require('path'); | ||
var util = require('util'); | ||
var yeoman = require('yeoman-generator'); | ||
var scriptBase = require('../script-base'); | ||
'use strict'; | ||
|
||
module.exports = Generator; | ||
var path = require('path'), | ||
util = require('util'), | ||
yeoman = require('yeoman-generator'), | ||
scriptBase = require('../script-base'); | ||
|
||
function Generator() { | ||
|
||
var Generator = module.exports = function Generator() { | ||
yeoman.generators.NamedBase.apply(this, arguments); | ||
scriptBase.apply(this, arguments); | ||
this.sourceRoot(path.join(__dirname, '../templates')); | ||
}; | ||
|
||
// required for collection.js template which uses `appname` | ||
} | ||
|
||
util.inherits(Generator, scriptBase); | ||
|
||
Generator.prototype.createControllerFiles = function createControllerFiles() { | ||
var ext = '.js', | ||
directory = (typeof this.dirPath !== 'undefined') ? '/' + this.dirPath : ''; | ||
util.inherits(Generator, yeoman.generators.NamedBase, scriptBase); | ||
|
||
var destFile = path.join('app/js/collections' + directory + '/', this.name + ext); | ||
var template = [ | ||
'define([', | ||
' \'underscore\',', | ||
' \'backbone\',', | ||
' \'models/' + this.name + '\'', | ||
'], function(_, Backbone, ' + this._.classify(this.name) + 'Model' + ') {', | ||
' \'use strict\';', | ||
'', | ||
' var ' + this._.classify(this.name) + 'Collection = Backbone.Collection.extend({', | ||
' ' + 'model: ' + this._.classify(this.name) + 'Model', | ||
' });', | ||
'', | ||
' return ' + this._.classify(this.name) + 'Collection;', | ||
'});' | ||
].join('\n'); | ||
Generator.prototype.createViewFiles = function createViewFiles() { | ||
this.dirPath = (typeof this.arguments[1] !== 'undefined') ? '/' + this.arguments[1] : ''; | ||
this.pathToModel = (typeof this.arguments[2] !== 'undefined') ? this.arguments[2] + '/' : ''; | ||
|
||
this.write(destFile, template); | ||
}; | ||
this.copy('js/collection.js', 'app/js/collections' + this.dirPath + '/' + this.name + '.js'); | ||
}; |
File renamed without changes.
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 |
---|---|---|
@@ -1,53 +1,21 @@ | ||
/*jshint latedef:false */ | ||
var path = require('path'); | ||
var util = require('util'); | ||
var yeoman = require('yeoman-generator'); | ||
var scriptBase = require('../script-base'); | ||
'use strict'; | ||
|
||
module.exports = Generator; | ||
var path = require('path'), | ||
util = require('util'), | ||
yeoman = require('yeoman-generator'), | ||
scriptBase = require('../script-base'); | ||
|
||
function Generator() { | ||
scriptBase.apply(this, arguments); | ||
|
||
// XXX default and banner to be implemented | ||
this.argument('attributes', { | ||
type: Array, | ||
defaults: [], | ||
banner: 'field[:type] field[:type]' | ||
}); | ||
|
||
// parse back the attributes provided, build an array of attr | ||
this.attrs = this.attributes.map(function (attr) { | ||
var parts = attr.split(':'); | ||
return { | ||
name: parts[0], | ||
type: parts[1] || 'string' | ||
}; | ||
}); | ||
|
||
} | ||
|
||
util.inherits(Generator, scriptBase); | ||
var Generator = module.exports = function Generator() { | ||
yeoman.generators.NamedBase.apply(this, arguments); | ||
scriptBase.apply(this, arguments); | ||
this.sourceRoot(path.join(__dirname, '../templates')); | ||
}; | ||
|
||
Generator.prototype.createModelFiles = function createModelFiles() { | ||
var ext = '.js', | ||
directory = (typeof this.dirPath !== 'undefined') ? '/' + this.dirPath : ''; | ||
util.inherits(Generator, yeoman.generators.NamedBase, scriptBase); | ||
|
||
var destFile = path.join('app/js/models' + directory + '/', this.name + ext); | ||
var template = [ | ||
'define([', | ||
' \'underscore\',', | ||
' \'backbone\'', | ||
'], function(_, Backbone) {', | ||
' \'use strict\';', | ||
'', | ||
' var ' + this._.classify(this.name) + 'Model = Backbone.Model.extend({', | ||
' defaults: {}', | ||
' });', | ||
'', | ||
' return ' + this._.classify(this.name) + 'Model;', | ||
'});' | ||
].join('\n'); | ||
Generator.prototype.createViewFiles = function createViewFiles() { | ||
this.dirPath = (typeof this.arguments[1] !== 'undefined') ? '/' + this.arguments[1] : ''; | ||
|
||
this.write(destFile, template); | ||
}; | ||
this.copy('js/model.js', 'app/js/models' + this.dirPath + '/' + this.name + '.js'); | ||
}; |
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 |
---|---|---|
@@ -1,41 +1,21 @@ | ||
/*jshint latedef:false */ | ||
'use strict'; | ||
|
||
var path = require('path'), | ||
util = require('util'), | ||
yeoman = require('yeoman-generator'), | ||
scriptBase = require('../script-base'); | ||
util = require('util'), | ||
yeoman = require('yeoman-generator'), | ||
scriptBase = require('../script-base'); | ||
|
||
module.exports = Generator; | ||
|
||
function Generator() { | ||
var Generator = module.exports = function Generator() { | ||
yeoman.generators.NamedBase.apply(this, arguments); | ||
scriptBase.apply(this, arguments); | ||
this.sourceRoot(path.join(__dirname, '../templates')); | ||
}; | ||
|
||
// required for router.js template which uses `appname` | ||
} | ||
|
||
util.inherits(Generator, scriptBase); | ||
|
||
Generator.prototype.createControllerFiles = function createControllerFiles() { | ||
var ext = '.js', | ||
directory = (typeof this.dirPath !== 'undefined') ? '/' + this.dirPath : ''; | ||
|
||
var destFile = path.join('app/js/router' + directory + '/', this.name + ext); | ||
var template = [ | ||
'define([', | ||
' \'jquery\',', | ||
' \'backbone\'', | ||
'], function($, Backbone) {', | ||
' \'use strict\';', | ||
'', | ||
' var ' + this._.classify(this.name) + 'Router = Backbone.Router.extend({', | ||
' routes: {', | ||
' }', | ||
' });', | ||
'', | ||
' return ' + this._.classify(this.name) + 'Router;', | ||
'});' | ||
].join('\n'); | ||
util.inherits(Generator, yeoman.generators.NamedBase, scriptBase); | ||
|
||
this.write(destFile, template); | ||
Generator.prototype.createViewFiles = function createViewFiles() { | ||
this.dirPath = (typeof this.arguments[1] !== 'undefined') ? '/' + this.arguments[1] : ''; | ||
|
||
}; | ||
this.copy('js/router-new.js', 'app/js/router' + this.dirPath + '/' + this.name + '.js'); | ||
}; |
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,13 @@ | ||
define([ | ||
'underscore', | ||
'backbone', | ||
'models/<%= pathToModel %><%= name %>' | ||
], function(_, Backbone, <%= _.classify(name) %>Model) { | ||
'use strict'; | ||
|
||
var <%= _.classify(name) %>Collection = Backbone.Collection.extend({ | ||
model: <%= _.classify(name) %>Model | ||
}); | ||
|
||
return <%= _.classify(name) %>Collection; | ||
}); |
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,12 @@ | ||
define([ | ||
'underscore', | ||
'backbone' | ||
], function(_, Backbone) { | ||
'use strict'; | ||
|
||
var <%= _.classify(name) %>Model = Backbone.Model.extend({ | ||
defaults: {} | ||
}); | ||
|
||
return <%= _.classify(name) %>Model; | ||
}); |
File renamed without changes.
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,13 @@ | ||
define([ | ||
'jquery', | ||
'backbone' | ||
], function($, Backbone) { | ||
'use strict'; | ||
|
||
var <%= _.classify(name) %>Router = Backbone.Router.extend({ | ||
routes: { | ||
} | ||
}); | ||
|
||
return <%= _.classify(name) %>Router; | ||
}); |
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 @@ | ||
<p>View <%= _.classify(name) %>View created.</p> |
Oops, something went wrong.