forked from kieran/barista
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added inflection dependency inflecting keys like resource_id to singular when nested version bump
- Loading branch information
Showing
7 changed files
with
99 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tests |
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,36 +1,41 @@ | ||
var snakeize = require('./helpers').snakeize | ||
, mixin = require('./helpers').mixin | ||
var mixin = require('./helpers').mixin | ||
, inflection = require('inflection') | ||
|
||
var Resource = exports.Resource = function( base, controller ){ | ||
|
||
var controller_slug = this.name = snakeize(controller) | ||
var controller_slug = inflection.underscore(inflection.pluralize(controller)) | ||
|
||
this.routes = [] | ||
|
||
// set up the actual routes for the resource | ||
this.routes.push( | ||
this.collection_route = | ||
base.get('/'+controller_slug+'(.:format)', 'GET').to(controller+'.index') | ||
, base.post('/'+controller_slug+'(.:format)', 'POST').to(controller+'.create') | ||
, base.get('/'+controller_slug+'/add(.:format)', 'GET').to(controller+'.add') | ||
, this.member_route = | ||
base.get('/'+controller_slug+'/:id(.:format)', 'GET').to(controller+'.show') | ||
, base.get('/'+controller_slug+'/:id/edit(.:format)', 'GET').to(controller+'.edit') | ||
, base.post('/'+controller_slug+'(.:format)', 'POST').to(controller+'.create') | ||
, base.put('/'+controller_slug+'/:id(.:format)', 'PUT').to(controller+'.update') | ||
, base.del('/'+controller_slug+'/:id(.:format)', 'DELETE').to(controller+'.destroy') | ||
) | ||
|
||
this.collection_route.collection = true | ||
this.member_route.member = true | ||
return this | ||
} | ||
|
||
Resource.prototype.collection = function(cb){ | ||
if ( typeof cb != 'function' ) throw 'resource.collection() requires a callback function' | ||
cb.call( this.collection_route ) | ||
this.collection_route.nest(cb) | ||
return this // for chaining | ||
} | ||
|
||
Resource.prototype.member = function(cb){ | ||
if ( typeof cb != 'function' ) throw 'resource.member() requires a callback function' | ||
cb.call( this.member_route ) | ||
this.member_route.nest(cb) | ||
return this // for chaining | ||
} | ||
|
||
Resource.prototype.nest = function(cb){ | ||
this.member_route.nest(cb) | ||
this.collection_route.nest(cb) | ||
return this // for chaining | ||
} |
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,9 +1,12 @@ | ||
{ | ||
"name": "barista", | ||
"description": "URL router & generator, similar to Rails / merb", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"author": "Kieran Huggins <kieran@kieran.ca>", | ||
"repository": "git://github.com/kieran/barista", | ||
"main": "./index.js", | ||
"engines": { "node": ">= 0.3.0" } | ||
"engines": { "node": ">= 0.4.0" }, | ||
"dependencies": { | ||
"inflection": "*" | ||
} | ||
} |
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