Permalink
Browse files

added ui-router option, other smaller changes/fixes

  • Loading branch information...
1 parent 653b513 commit cc7089242cb8b658c8834d9ed80dfdbe3ca33fa6 Chris Gross committed Feb 11, 2014
View
@@ -1,2 +1,3 @@
node_modules/
temp/
+.DS_Store
View
@@ -8,6 +8,7 @@ var CgangularGenerator = module.exports = function CgangularGenerator(args, opti
yeoman.generators.Base.apply(this, arguments);
this.on('end', function () {
+ this.config.save();
this.installDependencies({ skipInstall: options['skip-install'] });
});
@@ -27,7 +28,34 @@ CgangularGenerator.prototype.askFor = function askFor() {
this.prompt(prompts, function (props) {
this.appname = props.appname;
+ cb();
+ }.bind(this));
+};
+
+CgangularGenerator.prototype.askForUiRouter = function askFor() {
+ var cb = this.async();
+ var prompts = [{
+ name: 'router',
+ type:'list',
+ message: 'What router would you like to use?',
+ default: 0,
+ choices: ['Standard Angular Router','Angular UI Router']
+ }];
+
+ this.prompt(prompts, function (props) {
+ if (props.router === 'Angular UI Router') {
+ this.uirouter = true;
+ this.routerJs = 'bower_components/angular-ui-router/release/angular-ui-router.js';
+ this.routerModuleName = 'ui.router';
+ this.routerViewDirective = 'ui-view';
+ } else {
+ this.uirouter = false;
+ this.routerJs = 'bower_components/angular-route/angular-route.js';
+ this.routerModuleName = 'ngRoute';
+ this.routerViewDirective = 'ng-view';
+ }
+ this.config.set('uirouter',this.uirouter);
cb();
}.bind(this));
};
@@ -1,4 +1,5 @@
temp/
dist/
node_modules/
-_SpecRunner.html
+_SpecRunner.html
+.DS_Store
@@ -1,9 +1,4 @@
'use strict';
-var path = require('path');
-
-var folderMount = function folderMount(connect, point) {
- return connect.static(path.resolve(point));
-};
module.exports = function (grunt) {
@@ -15,10 +10,7 @@ module.exports = function (grunt) {
connect: {
main: {
options: {
- port: 9001,
- middleware: function(connect, options) {
- return [folderMount(connect, options.base)]
- }
+ port: 9001
}
}
},
@@ -79,7 +71,6 @@ module.exports = function (grunt) {
copy: {
main: {
files: [
- {src: ['index.html'], dest: 'dist/'},
{src: ['img/**'], dest: 'dist/'},
{src: ['bower_components/angular-ui-utils/ui-utils-ieshiv.min.js'], dest: 'dist/'},
{src: ['bower_components/font-awesome/fonts/**'], dest: 'dist/',filter:'isFile',expand:true}
@@ -89,43 +80,25 @@ module.exports = function (grunt) {
}
},
dom_munger:{
- readscripts: {
+ read: {
options: {
- read:{selector:'script[data-build!="exclude"]',attribute:'src',writeto:'appjs'}
+ read:[
+ {selector:'script[data-build!="exclude"]',attribute:'src',writeto:'appjs'},
+ {selector:'link[rel="stylesheet"]',attribute:'href',writeto:'appcss'}
+ ]
},
- src:'index.html'
+ src: 'index.html'
},
- readcss: {
+ update: {
options: {
- read:{selector:'link[rel="stylesheet"]',attribute:'href',writeto:'appcss'}
- },
- src:'index.html'
- },
- removescripts: {
- options:{
- remove:'script[data-remove!="exclude"]',
- append:{selector:'head',html:'<script src="app.full.min.js"></script>'}
- },
- src:'dist/index.html'
- },
- addscript: {
- options:{
- append:{selector:'body',html:'<script src="app.full.min.js"></script>'}
- },
- src:'dist/index.html'
- },
- removecss: {
- options:{
- remove:'link',
- append:{selector:'head',html:'<link rel="stylesheet" href="css/app.full.min.css">'}
- },
- src:'dist/index.html'
- },
- addcss: {
- options:{
- append:{selector:'head',html:'<link rel="stylesheet" href="css/app.full.min.css">'}
+ remove: ['script[data-remove!="exclude"]','link'],
+ append: [
+ {selector:'body',html:'<script src="app.full.min.js"></script>'},
+ {selector:'head',html:'<link rel="stylesheet" href="css/app.full.min.css">'}
+ ]
},
- src:'dist/index.html'
+ src:'index.html',
+ dest: 'dist/index.html'
}
},
cssmin: {
@@ -189,9 +162,9 @@ module.exports = function (grunt) {
}
});
- grunt.registerTask('build',['jshint','clean:before','less','dom_munger:readcss','dom_munger:readscripts','ngtemplates','cssmin','concat','ngmin','uglify','copy','dom_munger:removecss','dom_munger:addcss','dom_munger:removescripts','dom_munger:addscript','htmlmin','imagemin','clean:after']);
- grunt.registerTask('server', ['dom_munger:readscripts','jshint','connect', 'watch']);
- grunt.registerTask('test',['dom_munger:readscripts','jasmine']);
+ grunt.registerTask('build',['jshint','clean:before','less','dom_munger','ngtemplates','cssmin','concat','ngmin','uglify','copy','htmlmin','imagemin','clean:after']);
+ grunt.registerTask('server', ['dom_munger:read','jshint','connect', 'watch']);
+ grunt.registerTask('test',['dom_munger:read','jasmine']);
grunt.event.on('watch', function(action, filepath) {
@@ -219,7 +192,7 @@ module.exports = function (grunt) {
//if index.html changed, we need to reread the <script> tags so our next run of jasmine
//will have the correct environment
if (filepath === 'index.html') {
- grunt.task.run('dom_munger:readscripts');
+ grunt.task.run('dom_munger:read');
}
});
@@ -12,7 +12,7 @@
"underscore": "~1.5",
"bootstrap": "~3.0",
"angular": "~1.2",
- "angular-route": "~1.2",
+ <% if(uirouter) { print('"angular-ui-router": "~0.2",'); } else { print('"angular-route": "~1.2",'); } %>
"angular-animate": "~1.2",
"angular-resource": "~1.2",
"angular-cookies": "~1.2",
@@ -21,7 +21,7 @@
<script src="bower_components/underscore/underscore.js"></script>
<script src="bower_components/moment/moment.js"></script>
<script src="bower_components/angular/angular.js"></script>
- <script src="bower_components/angular-route/angular-route.js"></script>
+ <script src="<%= routerJs %>"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
@@ -46,7 +46,7 @@
<div>
<div id="content" class="container">
<div class="row">
- <div ng-view>
+ <div <%= routerViewDirective %>>
</div>
</div>
</div>
@@ -1,24 +1,32 @@
-angular.module('<%= _.slugify(appname) %>', ['ui.bootstrap','ui.utils','ngRoute','ngAnimate']);
-
+angular.module('<%= _.slugify(appname) %>', ['ui.bootstrap','ui.utils','<%= routerModuleName %>','ngAnimate']);
+<% if (!uirouter) { %>
angular.module('<%= _.slugify(appname) %>').config(function($routeProvider) {
$routeProvider.
/* Add New Routes Above */
otherwise({redirectTo:'/home'});
});
+<% } %><% if (uirouter) { %>
+angular.module('<%= _.slugify(appname) %>').config(function($stateProvider, $urlRouterProvider) {
+
+ $urlRouterProvider.otherwise("/home");
+ /* Add New States Above */
+
+});
+<% } %>
angular.module('<%= _.slugify(appname) %>').run(function($rootScope) {
- $rootScope.safeApply = function(fn) {
- var phase = $rootScope.$$phase;
- if (phase === '$apply' || phase === '$digest') {
- if (fn && (typeof(fn) === 'function')) {
- fn();
- }
- } else {
- this.$apply(fn);
- }
- };
+ $rootScope.safeApply = function(fn) {
+ var phase = $rootScope.$$phase;
+ if (phase === '$apply' || phase === '$digest') {
+ if (fn && (typeof(fn) === 'function')) {
+ fn();
+ }
+ } else {
+ this.$apply(fn);
+ }
+ };
});
@@ -3,7 +3,7 @@
"version": "0.0.0",
"devDependencies": {
"grunt": "~0.4",
- "grunt-dom-munger": "~3.1",
+ "grunt-dom-munger": "~3.4",
"grunt-angular-templates": "~0.5",
"grunt-ngmin": "0.0.3",
"grunt-contrib-connect": "~0.6",
@@ -17,7 +17,7 @@
"grunt-contrib-imagemin": "~0.4",
"grunt-contrib-less": "~0.8",
"grunt-contrib-watch": "~0.5",
- "grunt-contrib-jasmine": "~0.5",
+ "grunt-contrib-jasmine": "~0.6",
"load-grunt-tasks": "~0.2"
}
}
View
@@ -48,7 +48,7 @@ DirectiveGenerator.prototype.files = function files() {
this.log.writeln(chalk.green(' updating') + ' %s','index.html');
cgUtils.addToFile('css/app.less','@import "../directive/'+this.name+'/'+this.name+'.less";',cgUtils.DIRECTIVE_LESS_MARKER,'');
- this.log.writeln(chalk.green(' updating') + ' %s','app/app.less');
+ this.log.writeln(chalk.green(' updating') + ' %s','css/app.less');
} else {
this.template('directive_simple.js', 'directive/'+this.name+'.js');
this.template('spec.js', 'directive/'+this.name+'-spec.js');
View
@@ -22,9 +22,9 @@
"test": "mocha"
},
"dependencies": {
- "yeoman-generator": "~0.15",
"underscore": "~1.5",
"underscore.string": "~2.3",
+ "yeoman-generator": "~0.16",
"chalk": "~0.4.0"
},
"devDependencies": {
View
@@ -2,60 +2,79 @@
var util = require('util');
var yeoman = require('yeoman-generator');
var path = require('path');
+var fs = require('fs');
var cgUtils = require('../utils.js');
var chalk = require('chalk');
var _ = require('underscore');
+var chalk = require('chalk');
_.str = require('underscore.string');
_.mixin(_.str.exports());
var PartialGenerator = module.exports = function PartialGenerator(args, options, config) {
- yeoman.generators.NamedBase.apply(this, arguments);
+ yeoman.generators.NamedBase.apply(this, arguments);
- try {
- this.appname = require(path.join(process.cwd(), 'package.json')).name;
- } catch (e) {
- this.appname = 'Cant find name from package.json';
- }
+ try {
+ this.appname = require(path.join(process.cwd(), 'package.json')).name;
+ } catch (e) {
+ this.appname = 'Cant find name from package.json';
+ }
};
util.inherits(PartialGenerator, yeoman.generators.NamedBase);
PartialGenerator.prototype.askFor = function askFor() {
- var cb = this.async();
+ var cb = this.async();
- var prompts = [{
- name: 'route',
- message: 'Enter your route name (i.e. /mypartial/:id). If you don\'t want a route added for you, leave this empty.'
- }];
+ var prompts = [{
+ name: 'route',
+ message: 'Enter your route url (i.e. /mypartial/:id). If you don\'t want a route added for you, leave this empty.'
+ }];
- this.prompt(prompts, function (props) {
- this.route = props.route;
+ this.prompt(prompts, function (props) {
+ this.route = props.route;
- cb();
- }.bind(this));
+ cb();
+ }.bind(this));
};
PartialGenerator.prototype.files = function files() {
- this.ctrlname = _.camelize(_.classify(this.name)) + 'Ctrl';
+ this.ctrlname = _.camelize(_.classify(this.name)) + 'Ctrl';
+
+ this.template('partial.js', 'partial/'+this.name+'/'+this.name+'.js');
+ this.template('partial.html', 'partial/'+this.name+'/'+this.name+'.html');
+ this.template('partial.less', 'partial/'+this.name+'/'+this.name+'.less');
+ this.template('spec.js', 'partial/'+this.name+'/'+this.name+'-spec.js');
+
+ cgUtils.addToFile('index.html','<script src="partial/'+this.name+'/'+this.name+'.js"></script>',cgUtils.PARTIAL_JS_MARKER,' ');
+ this.log.writeln(chalk.green(' updating') + ' %s','index.html');
+
+ cgUtils.addToFile('css/app.less','@import "../partial/'+this.name+'/'+this.name+'.less";',cgUtils.PARTIAL_LESS_MARKER,'');
+ this.log.writeln(chalk.green(' updating') + ' %s','css/app.less');
- this.template('partial.js', 'partial/'+this.name+'/'+this.name+'.js');
- this.template('partial.html', 'partial/'+this.name+'/'+this.name+'.html');
- this.template('partial.less', 'partial/'+this.name+'/'+this.name+'.less');
- this.template('spec.js', 'partial/'+this.name+'/'+this.name+'-spec.js');
+ if (this.route && this.route.length > 0){
- cgUtils.addToFile('index.html','<script src="partial/'+this.name+'/'+this.name+'.js"></script>',cgUtils.PARTIAL_JS_MARKER,' ');
- this.log.writeln(chalk.green(' updating') + ' %s','index.html');
+ var configPath = path.join(process.cwd(),'.yo-rc.json');
+ var config = {};
+ if (fs.existsSync(configPath)) {
+ var c = require(configPath);
+ if (c['generator-cg-angular']) {
+ config = c['generator-cg-angular'];
+ }
+ }
- cgUtils.addToFile('css/app.less','@import "../partial/'+this.name+'/'+this.name+'.less";',cgUtils.PARTIAL_LESS_MARKER,'');
- this.log.writeln(chalk.green(' updating') + ' %s','css/app.less');
+ var partialUrl = 'partial/'+this.name+'/'+this.name+'.html';
- if (this.route && this.route.length > 0){
- cgUtils.addToFile('js/setup.js','when(\''+this.route+'\',{templateUrl: \'partial/'+this.name+'/'+this.name+'.html\'}).',cgUtils.ROUTE_MARKER,'\t');
- this.log.writeln(chalk.green(' updating') + ' %s','js/setup.js');
- }
+ if (config.uirouter) {
+ var code = '$stateProvider.state(\''+this.name+'\', {\n url: \''+this.route+'\',\n templateUrl: \''+partialUrl+'\'\n });';
+ cgUtils.addToFile('js/setup.js',code,cgUtils.STATE_MARKER,' ');
+ } else {
+ cgUtils.addToFile('js/setup.js','when(\''+this.route+'\',{templateUrl: \''+partialUrl+'\'}).',cgUtils.ROUTE_MARKER,' ');
+ }
+ this.log.writeln(chalk.green(' updating') + ' %s','js/setup.js');
+ }
};
View
@@ -16,11 +16,12 @@ exports.addToFile = function(filename,lineToAdd,beforeMarker,spacing){
}
};
-exports.DIRECTIVE_LESS_MARKER = "/* Add Directive LESS Above */";
+exports.DIRECTIVE_LESS_MARKER = "/* Add Directive LESS Above */";
exports.DIRECTIVE_JS_MARKER = "<!-- Add New Directive JS Above -->";
exports.FILTER_JS_MARKER = "<!-- Add New Filter JS Above -->";
exports.SERVICE_JS_MARKER = "<!-- Add New Service JS Above -->";
-exports.PARTIAL_LESS_MARKER = "/* Add Partial LESS Above */";
+exports.PARTIAL_LESS_MARKER = "/* Add Partial LESS Above */";
exports.PARTIAL_JS_MARKER = "<!-- Add New Partial JS Above -->";
exports.ROUTE_MARKER = "/* Add New Routes Above */";
+exports.STATE_MARKER = "/* Add New States Above */";

0 comments on commit cc70892

Please sign in to comment.