Skip to content

Instantly share code, notes, and snippets.

@oroce
Created January 13, 2012 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oroce/1605018 to your computer and use it in GitHub Desktop.
Save oroce/1605018 to your computer and use it in GitHub Desktop.
Controller.coffee
class Controller
constructor: ( @app ) ->
@initialize()
routes: {}
delegateRoutes: () ->
that = this
@routes.forEach ( key, callback ) ->
parts = key.split " "
method = parts[ 0 ]
route = parts[ 1 ]
@app[ method ] route, that[ callback ]
initialize: () ->
bindAll: ( that, methods... ) ->
methods.forEach ( method ) ->
that[ method ].bind that
class UserController extends Controller
routes:
"get /users": "getUsers"
initialize: () ->
@bindAll this, "getUser"
getUsers: ( req, res ) ->
# handle /users
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment