Permalink
Browse files

Closes #215 Added a geddy routes command that takes an optional route

query.

Included a `routes()` function for the console functioning similar to
the routes command.

Added CoffeeScript support for helpers.
  • Loading branch information...
1 parent 12a07fd commit 3900a2bddd22f278386f4180749b5fc00ff80c7e @larzconwell larzconwell committed Dec 18, 2012
Showing with 73 additions and 4 deletions.
  1. +10 −1 bin/cli.js
  2. +9 −2 lib/init/helpers.js
  3. +0 −1 lib/template/helpers/index.js
  4. +54 −0 templates/Jakefile
View
@@ -62,6 +62,8 @@ usage = [
, ' controller <name> Generate a new controller including an index view'
, ' and and a route'
, ' model <name> [attrs] Generate a new model'
+ , ' routes [query] Shows routes for a given resource route or all '
+ , ' routes if empty'
, ''
, 'Examples:'
, ' geddy Start Geddy on localhost:4000 in development mode'
@@ -76,6 +78,8 @@ usage = [
, ' geddy scaffold user name:string:default'
, ' Generate a users scaffolding user name as the default'
, ' value to display data with'
+ , ' geddy routes user Show all routes for the user resource'
+ , ' geddy routes user.index Show the index route for the user resource'
, ''
].join('\n');
@@ -137,7 +141,8 @@ if (cmds.length) {
cmds[0] == 'db:init' ||
cmds[0] == 'auth' ||
cmds[0] == 'auth:update' ||
- cmds[0] == 'console')
+ cmds[0] == 'console' ||
+ cmds[0] == 'routes')
&& !cmds[1]) {
throw new Error(cmds[0] + ' command requires another argument.');
}
@@ -213,6 +218,10 @@ if (cmds.length) {
// Generating new app secret
cmd += 'gen:secret';
break;
+ case 'routes':
+ // Show routes(Optionally empty)
+ cmd += 'routes:show[' + (cmds[1] || '') + ']';
+ break;
default:
die(cmds[0] + ' is not a Geddy command.');
}
View
@@ -2,10 +2,11 @@ var fs = require('fs')
, path = require('path')
, utils = require('utilities')
, helpers = require('../template/helpers')
- , actionHelpers = require('../template/helpers/action');
+ , actionHelpers = require('../template/helpers/action')
+ , usingCoffee;
module.exports = new (function () {
- var PAT = /\.js$/;
+ var PAT = /\.(js|coffee)$/;
this.init = function (app, callback) {
var helper
@@ -34,10 +35,16 @@ module.exports = new (function () {
// Load local app-helpers, make them available to the view
if (utils.file.existsSync(helperDir)) {
dirList = fs.readdirSync(helperDir);
+
for (var i = 0, ii = dirList.length; i < ii; i++) {
helperPath = path.join(helperDir, dirList[i]);
+
if (PAT.test(helperPath)) {
+ if (helperPath.match('.coffee')) {
+ usingCoffee = usingCoffee || utils.file.requireLocal('coffee-script')
+ }
appHelpers = require(helperPath);
+
for (var p in appHelpers) {
app.viewHelpers[p] = appHelpers[p];
}
@@ -237,6 +237,5 @@ exports.truncate = {
// Docs at utils.string.truncateHTML
exports.truncateHTML = {
name: 'truncateHTML',
- //altName: 'truncate_HTML',
action: utils.string.truncateHTML
};
View
@@ -10,6 +10,7 @@ var cwd = process.cwd()
, utils = require('../lib/utils')
, Adapter = require('../lib/template/adapters')
, getRouterPath
+ , getRoutes
, addRoute
, mixinJSONData;
@@ -38,6 +39,46 @@ getRouterPath = function () {
return routerPath;
};
+getRoutes = function (resource) {
+ if (!resource) {
+ return geddy.router.toString();
+ }
+
+ var rts = []
+ , _rt
+ , i;
+
+ // If a full route name was given add it to the list(e,g,. users.index)
+ if (resource.match(/.+\..+/)) {
+ var res = resource.split('.')
+ , cont = res[0]
+ , action = res[1];
+
+ for (i in geddy.router.routes) {
+ _rt = geddy.router.routes[i];
+
+ if (_rt.params.controller.match(cont) &&
+ _rt.params.action.match(action)) {
+ rts.push(_rt);
+ }
+ }
+ }
+ else {
+ for (i in geddy.router.routes) {
+ _rt = geddy.router.routes[i];
+
+ if (_rt.params.controller.match(resource) ||
+ _rt.params.action.match(resource)) {
+ rts.push(_rt);
+ }
+ }
+ }
+
+ return rts.map(function (rt) {
+ return rt.toString();
+ }).join('\n');
+};
+
addRoute = function (routerPath, newRoute) {
var text = fs.readFileSync(routerPath, 'utf8')
, routerArr;
@@ -159,12 +200,25 @@ namespace('console', function () {
console.log('No data');
}
};
+
+ rl.context.routes = function (resource) {
+ console.log(getRoutes(resource));
+ };
});
t.invoke(env);
});
});
+namespace('routes', function () {
+
+ task('show', ['env:init'], {async: true}, function (resource) {
+ console.log('Showing route results for "' + resource + '"');
+ console.log(getRoutes(resource));
+ });
+
+});
+
namespace('db', function () {
task('createTable', ['env:init'], function (name) {

0 comments on commit 3900a2b

Please sign in to comment.