Permalink
Browse files

Multiple changes to angularcrud and express generator to create route…

…s that just work together when triggering generators - no additional config necessary.
  • Loading branch information...
addyosmani committed Jan 14, 2013
1 parent 7a3609f commit 2afe48b7c2c6dd1226d60353eed1a00464d19426
@@ -12,7 +12,9 @@ function Generator() {
ScriptBase.apply(this, arguments);
this.model = this.name;
+ this.verb = this.args[2];
this.name = this.filename = this.args[1];
+
}
util.inherits(Generator, ScriptBase);
@@ -22,7 +22,7 @@ function Generator() {
this.filename = this.name + this.args[1].charAt(0).toUpperCase() + this.args[1].substr(1);
this.hookFor('angularcrud:crud-controller', {
- args: [this.name, this.filename]
+ args: [this.name, this.filename, this.action]
});
this.hookFor('angularcrud:crud-view', {
args: [this.name, this.filename]
@@ -39,7 +39,7 @@ Generator.prototype.rewriteAppJs = function() {
needle: '.otherwise',
haystack: body,
splicable: [
- ".when('/" + this.name + "/" + this.action + "', {",
+ ".when('/api/" + this.name + "/" + this.action + "', {",
" templateUrl: 'views/" + this.name + "/" + this.filename + ".html',",
" controller: '" + _.classify(this.filename) + "Ctrl'",
"})"
@@ -1 +1,2 @@
<p>This is the <%= name %> view.</p>
+<p>{{<%= name %>}}</p>
@@ -1,9 +1,8 @@
+
'use strict';
-<%= _.camelize(appname) %>App.controller('<%= _.classify(name) %>Ctrl', function($scope) {
- $scope.awesomeThings = [
- 'HTML5 Boilerplate',
- 'AngularJS',
- 'Testacular'
- ];
+<%= _.camelize(appname) %>App.controller('<%= _.classify(name) %>Ctrl', function($scope, $routeParams, $http) {
+ $http.get('/api/<%= model %>/<%= verb %>').success(function(data) {
+ $scope.<%= model %> = data;
+ });
});
@@ -10,6 +10,5 @@ function Generator() {
util.inherits(Generator, yeoman.generators.Base);
Generator.prototype.createInitializerFile = function() {
- this.copy('server.js', 'server.js');
- this.copy('appRouter.js', 'appRouter.js');
+ this.template('appRouter.js', 'server/index.js');
};
@@ -1,9 +1,11 @@
-module.exports = function(app) {
- /* Required Route Files */
-
- /* Default route serves client */
- app.get("*", function(req, res) {
- res.render('index.html')
- });
-};
+var express = require('express');
+var app = express();
+
+/* Required Route Files */
+
+app.get('/hello/:name', function(req, res) {
+ res.send('yo! ' + req.params.name);
+});
+
+module.exports = app;
Oops, something went wrong.

0 comments on commit 2afe48b

Please sign in to comment.