Skip to content

Commit

Permalink
Adding rewritten Backbone-Rails generator for yeoman#246
Browse files Browse the repository at this point in the history
  • Loading branch information
addyosmani committed Aug 24, 2012
1 parent 65edbf9 commit 3038aec
Show file tree
Hide file tree
Showing 22 changed files with 10,499 additions and 59 deletions.
38 changes: 6 additions & 32 deletions cli/lib/generators/backbone/all/index.js
@@ -1,7 +1,7 @@

var path = require('path'),
util = require('util'),
yeoman = require('../../../../');
util = require('util'),
yeoman = require('../../../../');

module.exports = Generator;

Expand All @@ -11,11 +11,12 @@ function Generator() {

this.dirs = 'models collections views routes helpers templates'.split(' ');

// should we figure it out automatically? and made available through an
// appname property, function of something.
this.appname = path.basename(process.cwd());

// the api to hookFor and pass arguments may vary a bit.
this.hookFor('backbone:app', {
args: [ 'application' ]
});
this.hookFor('backbone:view', {
args: [ 'application' ]
});
Expand All @@ -32,33 +33,6 @@ function Generator() {

util.inherits(Generator, yeoman.generators.Base);

Generator.prototype.injectBackbone = function injectBackbone() {

// Resolve path to index.html
var indexOut = path.resolve('index.html');

// Read in as string for further update
var indexData = this.readFileAsString(indexOut);

// Workaround until copying underscore/lodash-like scripts don't cause issues.
indexData = this.appendScripts(indexData,
'app/scripts/vendor.js',
['http://cdnjs.cloudflare.com/ajax/libs/lodash.js/0.5.2/lodash.min.js',
'http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js']);

// Wire MVC components (usemin: app/scripts/myapp.js)
indexData = this.appendScripts(indexData,
'app/scripts/myapp.js',
['app/scripts/' + this.appname +'.js',
'app/scripts/views/application-view.js',
'app/scripts/models/application-model.js',
'app/scripts/collections/application-collection.js',
'app/scripts/routes/app-router.js']);

// Write out final file
this.writeFileFromString(indexData, indexOut);

};

Generator.prototype.createDirLayout = function createDirLayout() {
var self = this;
Expand All @@ -70,6 +44,6 @@ Generator.prototype.createDirLayout = function createDirLayout() {
};

Generator.prototype.createAppFile = function createAppFile() {
this.template('app.js', 'app/scripts/' + this.appname + '.js');
this.template('app.js', 'app/scripts/main.js');
};

18 changes: 18 additions & 0 deletions cli/lib/generators/backbone/app/index.js
@@ -0,0 +1,18 @@

var util = require('util'),
path = require('path'),
yeoman = require('../../../../');

module.exports = Generator;

function Generator() {
yeoman.generators.Base.apply(this, arguments);
}

util.inherits(Generator, yeoman.generators.Base);

Generator.prototype.setupEnv = function setupEnv() {
// Copies the contents of the generator `templates`
// directory into your users new application path
this.directory('.','.', true);
};
1 change: 1 addition & 0 deletions cli/lib/generators/backbone/app/templates/.gitattributes
@@ -0,0 +1 @@
* text=auto
2 changes: 2 additions & 0 deletions cli/lib/generators/backbone/app/templates/.gitignore
@@ -0,0 +1,2 @@
intermediate/
publish/
174 changes: 174 additions & 0 deletions cli/lib/generators/backbone/app/templates/Gruntfile.js
@@ -0,0 +1,174 @@
module.exports = function( grunt ) {
'use strict';
//
// Grunt configuration:
//
// https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
//
grunt.initConfig({

// Project configuration
// ---------------------

// specify an alternate install location for Bower
bower: {
dir: 'app/scripts/vendor'
},

// Coffee to JS compilation
coffee: {
dist: {
src: 'app/scripts/**/*.coffee',
dest: 'app/scripts'
}
},

// compile .scss/.sass to .css using Compass
compass: {
dist: {
// http://compass-style.org/help/tutorials/configuration-reference/#configuration-properties
options: {
css_dir: 'styles',
sass_dir: 'styles',
images_dir: 'images',
javascripts_dir: 'scripts',
force: true
}
}
},

// generate application cache manifest
manifest:{
dest: ''
},

// headless testing through PhantomJS
mocha: {
all: ['test/**/*.html']
},

// default watch configuration
watch: {
coffee: {
files: '<config:coffee.dist.src>',
tasks: 'coffee reload'
},
compass: {
files: [
'app/styles/**/*.{scss,sass}'
],
tasks: 'compass reload'
},
reload: {
files: [
'app/*.html',
'app/styles/**/*.css',
'app/scripts/**/*.js',
'app/images/**/*'
],
tasks: 'reload'
}
},

// default lint configuration, change this to match your setup:
// https://github.com/cowboy/grunt/blob/master/docs/task_lint.md#lint-built-in-task
lint: {
files: [
'Gruntfile.js',
'app/scripts/**/*.js',
'spec/**/*.js'
]
},

// specifying JSHint options and globals
// https://github.com/cowboy/grunt/blob/master/docs/task_lint.md#specifying-jshint-options-and-globals
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true
},
globals: {
jQuery: true
}
},

// Build configuration
// -------------------

// the staging directory used during the process
staging: 'temp',
// final build output
output: 'dist',

mkdirs: {
staging: 'app/'
},

// Below, all paths are relative to the staging directory, which is a copy
// of the app/ directory. Any .gitignore, .ignore and .buildignore file
// that might appear in the app/ tree are used to ignore these values
// during the copy process.

// concat css/**/*.css files, inline @import, output a single minified css
css: {
'styles/main.css': ['styles/**/*.css']
},

// renames JS/CSS to prepend a hash of their contents for easier
// versioning
rev: {
js: 'scripts/**/*.js',
css: 'styles/**/*.css',
img: 'images/**'
},

// usemin handler should point to the file containing
// the usemin blocks to be parsed
'usemin-handler': {
html: 'index.html'
},

// update references in HTML/CSS to revved files
usemin: {
html: ['**/*.html'],
css: ['**/*.css']
},

// HTML minification
html: {
files: ['**/*.html']
},

// Optimizes JPGs and PNGs (with jpegtran & optipng)
img: {
dist: '<config:rev.img>'
},

// rjs configuration. You don't necessarily need to specify the typical
// `path` configuration, the rjs task will parse these values from your
// main module, using http://requirejs.org/docs/optimization.html#mainConfigFile
//
// name / out / mainConfig file should be used. You can let it blank if
// you're using usemin-handler to parse rjs config from markup (default
// setup)
rjs: {
// no minification, is done by the min task
optimize: 'none',
baseUrl: './scripts',
wrap: true
},
});

// Alias the `test` task to run the `mocha` task instead
grunt.registerTask('test', 'mocha');

};

0 comments on commit 3038aec

Please sign in to comment.