{"_id":"chungking","_rev":"29-ca1a8ed5825ddea77b4702065aad5049","name":"chungking","description":"Controllers for Node.js and Express.","dist-tags":{"latest":"0.0.7"},"versions":{"0.0.1":{"name":"chungking","description":"Controllers for Node.js and Express.","version":"0.0.1","main":"./lib/index","dependencies":{"express":""},"repository":{"type":"git","url":"git://github.com/olalonde/chungking.git"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com","url":"http://www.syskall.com"},"readme":"# Chungking \n\nController for Connect and Express (Node.js / Express.js /\nConnect.js). Name comes from [Chungking Express](http://en.wikipedia.org/wiki/Chungking_Express).\n\n## Install\n\n    npm install chungking\n\n## Usage\n\nSet up a Users controller\n\n```javascript\n// users.js\nvar BaseController = require('chungking').BaseController;\n\nvar Users = BaseController.extend(function() {\n  // this === Users.prototype\n\n  // Before filters are called whenever you call an action.\n  // They are asynchronous so you need to call this.next()\n  // when you are done.\n  this.beforeFilter(function() {\n    console.log('This is called before any action is called.');\n    if(this.authenticate())\n      this.next();\n    else\n      this.res.send('Not authorized');\n  });\n  \n  // You can also add methods that are available to all your\n  // actions.\n  this.authenticate = function() {\n    console.log('You can put some authentication code here.');\n    return true;\n  }\n\n  // Add actions below\n  this.action('index', function() {\n    // this.req, this.res, this.next are available anywhere in\n    // your controller.\n    this.res.send('Users index.');\n  });\n\n});\n\nmodule.exports = Users;\n```\n\nCall the controller from your request handler:\n\n```javascript\n// app.js\nvar Users = require('./users');\n\n// ...\n\napp.get('/users', function(req, res, next) {\n  var ctl = new Users(req, res, next);\n  ctl.action('index');\n});\n```\n\nThat's it!\n\n### Extending controllers\n\nYou can also extend controllers.\n\nApplication controller:\n\n```javascript\n// application.js\nvar BaseController = require('chungking').BaseController;\n\nvar Application = BaseController.extend(function() {\n  // This before filter will be called whenever a controller that\n  // extends Application gets an action called.\n  this.beforeFilter(function() {\n    if(!this.req.user) this.res.send('Unauthorized!');\n    else this.next();\n  });\n\n  // Set up some useful aliases\n  this.beforeFilter(function() {\n    this.currentSection = 'Application';\n  });\n\n  // This action will be available to any controller that extends\n  // the Application controller.\n  this.action('whoami', function() {\n    this.res.send(this.req.user);\n  });\n});\n\nmodule.exports = Application;\n```\n\nUsers controller which extends the Application controller:\n\n```javascript\n// users.js\nvar Application = require('./application');\n\nvar Users = Application.extend(function() {\n  this.beforeFilter(function() {\n    console.log('This will be called after the Application'\n      + 'controller\\'s before filters.');\n    this.next();\n  });\n  \n  this.action('index', function() {\n    this.res.send('We are in the section ' + this.currentSection);\n  });\n});\n```\n\n# TODO #\n\n- Limit before filters to only given actions.\n- Create some useful alias for commonly used methods (i.e. this.res.send could be mapped to this.send)\n","_id":"chungking@0.0.1","dist":{"shasum":"9b38332db49c4c1b43588e4d8a36eaeaaa576526","tarball":"https://registry.npmjs.org/chungking/-/chungking-0.0.1.tgz","integrity":"sha512-+6vLZuqiNabhm39rvF0nOrD258WwdOxad1+u1Ec0tuCzeUFTY2mY9PgQyckozv3F5Xef1t9BVlKF8vwRfoQX7g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBSTp70kto4BjVNMoEQk5NdEMcQBKmLKiovuKQJgqNxUAiBGSoTX29BBxy7jr6ROTARNwz3LV0ywU+Tr/dUod7yEnA=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"directories":{}},"0.0.2":{"name":"chungking","description":"Controllers for Node.js and Express.","version":"0.0.2","main":"./lib/index","dependencies":{"express":""},"repository":{"type":"git","url":"git://github.com/olalonde/chungking.git"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com","url":"http://www.syskall.com"},"readme":"# Chungking \n\nController for Connect and Express (Node.js / Express.js /\nConnect.js). Name comes from [Chungking Express](http://en.wikipedia.org/wiki/Chungking_Express).\n\n## Install\n\n    npm install chungking\n\n## Usage\n\nSet up a Users controller\n\n```javascript\n// users.js\nvar BaseController = require('chungking').BaseController;\n\nvar Users = BaseController.extend(function() {\n  // this === Users.prototype\n\n  // Before filters are called whenever you call an action.\n  // They are asynchronous so you need to call this.next()\n  // when you are done.\n  this.beforeFilter(function() {\n    console.log('This is called before any action is called.');\n    if(this.authenticate())\n      this.next();\n    else\n      this.res.send('Not authorized');\n  });\n  \n  // You can also add methods that are available to all your\n  // actions.\n  this.authenticate = function() {\n    console.log('You can put some authentication code here.');\n    return true;\n  }\n\n  // Add actions below\n  this.action('index', function() {\n    // this.req, this.res, this.next are available anywhere in\n    // your controller.\n    this.res.send('Users index.');\n  });\n\n});\n\nmodule.exports = Users;\n```\n\nCall the controller from your request handler:\n\n```javascript\n// app.js\nvar Users = require('./users');\n\n// ...\n\napp.get('/users', function(req, res, next) {\n  var ctl = new Users(req, res, next);\n  ctl.action('index');\n});\n```\n\nThat's it!\n\n### Restricting beforeFilters to only specific actions\n\n```javascript\nthis.authorize = function() {\n  console.log('This is called before any action is called.');\n  //authentication code here...\n}\n\n// restrict to only some actions\nthis.beforeFilter({only: ['edit', 'update', 'create']}, function() {\n  this.authorize();\n});\n\n// execute for all actions except listed actions\nthis.beforeFilter({except: ['show']}, function() {\n  this.authorize();\n});\n```\n\n### Tired of writing this.req, this.res and this.next?\n\nYou can optionally get them as params to your beforeFilters and actions.\n\n```javascript\nthis.beforeFilter(function(req, res, next) {\n  res.send('aaahhh much better :)');\n});\n```\n\n### Extending controllers\n\nYou can also extend controllers.\n\nApplication controller:\n\n```javascript\n// application.js\nvar BaseController = require('chungking').BaseController;\n\nvar Application = BaseController.extend(function() {\n  // This before filter will be called whenever a controller that\n  // extends Application gets an action called.\n  this.beforeFilter(function() {\n    if(!this.req.user) this.res.send('Unauthorized!');\n    else this.next();\n  });\n\n  // Set up some useful aliases\n  this.beforeFilter(function() {\n    this.currentSection = 'Application';\n  });\n\n  // This action will be available to any controller that extends\n  // the Application controller.\n  this.action('whoami', function() {\n    this.res.send(this.req.user);\n  });\n});\n\nmodule.exports = Application;\n```\n\nUsers controller which extends the Application controller:\n\n```javascript\n// users.js\nvar Application = require('./application');\n\nvar Users = Application.extend(function() {\n  this.beforeFilter(function() {\n    console.log('This will be called after the Application'\n      + 'controller\\'s before filters.');\n    this.next();\n  });\n  \n  this.action('index', function() {\n    this.res.send('We are in the section ' + this.currentSection);\n  });\n});\n```\n\n# TODO\n\nRethink how inheritance works. Maybe child controllers should not\ninherit before filters and actions.\n\nRefactor the way inheritance is done. Maybe use utils.inherit from\nnode.js http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor.\n","_id":"chungking@0.0.2","dist":{"shasum":"a8aa20e2a64030f626f8f70d634cde10ed46fa52","tarball":"https://registry.npmjs.org/chungking/-/chungking-0.0.2.tgz","integrity":"sha512-ePDPjf+zuTEYtyLKkcNdyyhNZQ/pPAhDby2YX5zfSrdRWkxpocbk1bXQN6UCTNRbjTMRYzoaq2khhmluhPwqDA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC5E5IR5Z2dRmACweS8R/iz3nLFDaG2hVOvywGPuMT0nAiBOz8Ns5qBvnKwUqsIV0sTKx9Kmncw+iKeUxHPRIpwfOg=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"directories":{}},"0.0.3":{"name":"chungking","description":"Controllers for Node.js and Express.","version":"0.0.3","main":"./lib/index","dependencies":{"express":""},"repository":{"type":"git","url":"git://github.com/olalonde/chungking.git"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com","url":"http://www.syskall.com"},"readme":"# Chungking \n\nController for Connect and Express (Node.js / Express.js /\nConnect.js). Name comes from [Chungking Express](http://en.wikipedia.org/wiki/Chungking_Express).\n\n## Install\n\n    npm install chungking\n\n## Usage\n\nSet up a Users controller\n\n```javascript\n// users.js\nvar BaseController = require('chungking').BaseController;\n\nvar Users = BaseController.extend(function() {\n  // this === Users.prototype\n\n  // Before filters are called whenever you call an action.\n  // They are asynchronous so you need to call this.next()\n  // when you are done.\n  this.beforeFilter(function() {\n    console.log('This is called before any action is called.');\n    if(this.authenticate())\n      this.next();\n    else\n      this.res.send('Not authorized');\n  });\n  \n  // You can also add methods that are available to all your\n  // actions.\n  this.authenticate = function() {\n    console.log('You can put some authentication code here.');\n    return true;\n  }\n\n  // Add actions below\n  this.action('index', function() {\n    // this.req, this.res, this.next are available anywhere in\n    // your controller.\n    this.res.send('Users index.');\n  });\n\n});\n\nmodule.exports = Users;\n```\n\nCall the controller from your request handler:\n\n```javascript\n// app.js\nvar Users = require('./users');\n\n// ...\n\napp.get('/users', function(req, res, next) {\n  var ctl = new Users(req, res, next);\n  ctl.action('index');\n});\n```\n\nThat's it!\n\n### Restricting beforeFilters to only specific actions\n\n```javascript\nthis.authorize = function() {\n  console.log('This is called before any action is called.');\n  //authentication code here...\n}\n\n// restrict to only some actions\nthis.beforeFilter({only: ['edit', 'update', 'create']}, function() {\n  this.authorize();\n});\n\n// execute for all actions except listed actions\nthis.beforeFilter({except: ['show']}, function() {\n  this.authorize();\n});\n```\n\n### Tired of writing this.req, this.res and this.next?\n\nYou can optionally get them as params to your beforeFilters and actions.\n\n```javascript\nthis.beforeFilter(function(req, res, next) {\n  res.send('aaahhh much better :)');\n});\n```\n\n### Extending controllers\n\nYou can also extend controllers.\n\nApplication controller:\n\n```javascript\n// application.js\nvar BaseController = require('chungking').BaseController;\n\nvar Application = BaseController.extend(function() {\n  // This before filter will be called whenever a controller that\n  // extends Application gets an action called.\n  this.beforeFilter(function() {\n    if(!this.req.user) this.res.send('Unauthorized!');\n    else this.next();\n  });\n\n  // Set up some useful aliases\n  this.beforeFilter(function() {\n    this.currentSection = 'Application';\n  });\n\n  // This action will be available to any controller that extends\n  // the Application controller.\n  this.action('whoami', function() {\n    this.res.send(this.req.user);\n  });\n});\n\nmodule.exports = Application;\n```\n\nUsers controller which extends the Application controller:\n\n```javascript\n// users.js\nvar Application = require('./application');\n\nvar Users = Application.extend(function() {\n  this.beforeFilter(function() {\n    console.log('This will be called after the Application'\n      + 'controller\\'s before filters.');\n    this.next();\n  });\n  \n  this.action('index', function() {\n    this.res.send('We are in the section ' + this.currentSection);\n  });\n});\n```\n\n# TODO\n\nRethink how inheritance works. Maybe child controllers should not\ninherit before filters and actions.\n\nRefactor the way inheritance is done. Maybe use utils.inherit from\nnode.js http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor.\n","_id":"chungking@0.0.3","dist":{"shasum":"43ac58440e85c222a2fdda3e9ac4b02c87cf1106","tarball":"https://registry.npmjs.org/chungking/-/chungking-0.0.3.tgz","integrity":"sha512-Iso43hjy/J5XWBl3X/cIDIbKwqUrd9xcmrqyGmTDT6WaeUKF+Z9qKNsuEUU/XinxMaP24bbPDwfA9qmmpMo0oQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDxaamX5HxxJ3KqCMPjqwOYhpnu0KAFDPw8lpahJjAzlAiBTmgEtgxPdxCHXuu8D2ViX/wtPrgjsP9tJFKKA+QR5XQ=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"directories":{}},"0.0.4":{"name":"chungking","description":"Controllers for Node.js and Express.","version":"0.0.4","main":"./lib/index","dependencies":{"express":""},"repository":{"type":"git","url":"git://github.com/olalonde/chungking.git"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com","url":"http://www.syskall.com"},"readme":"# Chungking \n\nController for Connect and Express (Node.js / Express.js /\nConnect.js). Name comes from [Chungking Express](http://en.wikipedia.org/wiki/Chungking_Express).\n\n## Install\n\n    npm install chungking\n\n## Usage\n\nSet up a Users controller\n\n```javascript\n// users.js\nvar BaseController = require('chungking').BaseController;\n\nvar Users = BaseController.extend(function() {\n  // this === Users.prototype\n\n  // Before filters are called whenever you call an action.\n  // They are asynchronous so you need to call this.next()\n  // when you are done.\n  this.beforeFilter(function() {\n    console.log('This is called before any action is called.');\n    if(this.authenticate())\n      this.next();\n    else\n      this.res.send('Not authorized');\n  });\n  \n  // You can also add methods that are available to all your\n  // actions.\n  this.authenticate = function() {\n    console.log('You can put some authentication code here.');\n    return true;\n  }\n\n  // Add actions below\n  this.action('index', function() {\n    // this.req, this.res, this.next are available anywhere in\n    // your controller.\n    this.res.send('Users index.');\n  });\n\n});\n\nmodule.exports = Users;\n```\n\nCall the controller from your request handler:\n\n```javascript\n// app.js\nvar Users = require('./users');\n\n// ...\n\napp.get('/users', function(req, res, next) {\n  var ctl = new Users(req, res, next);\n  ctl.action('index');\n});\n```\n\nThat's it!\n\n### Restricting beforeFilters to only specific actions\n\n```javascript\nthis.authorize = function() {\n  console.log('This is called before any action is called.');\n  //authentication code here...\n}\n\n// restrict to only some actions\nthis.beforeFilter({only: ['edit', 'update', 'create']}, function() {\n  this.authorize();\n});\n\n// execute for all actions except listed actions\nthis.beforeFilter({except: ['show']}, function() {\n  this.authorize();\n});\n```\n\n### Tired of writing this.req, this.res and this.next?\n\nYou can optionally get them as params to your beforeFilters and actions.\n\n```javascript\nthis.beforeFilter(function(req, res, next) {\n  res.send('aaahhh much better :)');\n});\n```\n\n### Extending controllers\n\nYou can also extend controllers.\n\nApplication controller:\n\n```javascript\n// application.js\nvar BaseController = require('chungking').BaseController;\n\nvar Application = BaseController.extend(function() {\n  // This before filter will be called whenever a controller that\n  // extends Application gets an action called.\n  this.beforeFilter(function() {\n    if(!this.req.user) this.res.send('Unauthorized!');\n    else this.next();\n  });\n\n  // Set up some useful aliases\n  this.beforeFilter(function() {\n    this.currentSection = 'Application';\n  });\n\n  // This action will be available to any controller that extends\n  // the Application controller.\n  this.action('whoami', function() {\n    this.res.send(this.req.user);\n  });\n});\n\nmodule.exports = Application;\n```\n\nUsers controller which extends the Application controller:\n\n```javascript\n// users.js\nvar Application = require('./application');\n\nvar Users = Application.extend(function() {\n  this.beforeFilter(function() {\n    console.log('This will be called after the Application'\n      + 'controller\\'s before filters.');\n    this.next();\n  });\n  \n  this.action('index', function() {\n    this.res.send('We are in the section ' + this.currentSection);\n  });\n});\n```\n\n# TODO\n\nRethink how inheritance works. Maybe child controllers should not\ninherit before filters and actions.\n\nRefactor the way inheritance is done. Maybe use utils.inherit from\nnode.js http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor.\n","_id":"chungking@0.0.4","dist":{"shasum":"981862a5f483a21e9867e2bbbe806d4c2da9143f","tarball":"https://registry.npmjs.org/chungking/-/chungking-0.0.4.tgz","integrity":"sha512-krLfRwMegSpGxxK9QXRlLug6reeBnsqd4yQffA//gHNWNDeNrMsNpRwpYAfX/CJfaU2uFtxxETmhZHM2DEFPsA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDh7OI5YKzWDPiEVeLpE8AWZeBRAx+5ed3bNAtDk7DNcwIhAMMlw93U7BDs+PVeW+NrzYSVHxxJgReolaYYq+I368BK"}]},"_npmVersion":"1.1.62","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"directories":{}},"0.0.5":{"name":"chungking","description":"Controllers for Node.js and Express.","version":"0.0.5","main":"./lib/index","dependencies":{"express":""},"repository":{"type":"git","url":"git://github.com/olalonde/chungking.git"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com","url":"http://www.syskall.com"},"readme":"# Chungking \n\nController for Connect and Express (Node.js / Express.js /\nConnect.js). Name comes from [Chungking Express](http://en.wikipedia.org/wiki/Chungking_Express).\n\n## Install\n\n    npm install chungking\n\n## Usage\n\nSet up a Users controller\n\n```javascript\n// users.js\nvar BaseController = require('chungking').BaseController;\n\nvar Users = BaseController.extend(function() {\n  // this === Users.prototype\n\n  // Before filters are called whenever you call an action.\n  // They are asynchronous so you need to call this.next()\n  // when you are done.\n  this.beforeFilter(function() {\n    console.log('This is called before any action is called.');\n    if(this.authenticate())\n      this.next();\n    else\n      this.res.send('Not authorized');\n  });\n  \n  // You can also add methods that are available to all your\n  // actions.\n  this.authenticate = function() {\n    console.log('You can put some authentication code here.');\n    return true;\n  }\n\n  // Add actions below\n  this.action('index', function() {\n    // this.req, this.res, this.next are available anywhere in\n    // your controller.\n    this.res.send('Users index.');\n  });\n\n});\n\nmodule.exports = Users;\n```\n\nCall the controller from your request handler:\n\n```javascript\n// app.js\nvar Users = require('./users');\n\n// ...\n\napp.get('/users', function(req, res, next) {\n  var ctl = new Users(req, res, next);\n  ctl.action('index');\n});\n```\n\nThat's it!\n\n### Restricting beforeFilters to only specific actions\n\n```javascript\nthis.authorize = function() {\n  console.log('This is called before any action is called.');\n  //authentication code here...\n}\n\n// restrict to only some actions\nthis.beforeFilter({only: ['edit', 'update', 'create']}, function() {\n  this.authorize();\n});\n\n// execute for all actions except listed actions\nthis.beforeFilter({except: ['show']}, function() {\n  this.authorize();\n});\n```\n\n### Tired of writing this.req, this.res and this.next?\n\nYou can optionally get them as params to your beforeFilters and actions.\n\n```javascript\nthis.beforeFilter(function(req, res, next) {\n  res.send('aaahhh much better :)');\n});\n```\n\n### Extending controllers\n\nYou can also extend controllers.\n\nApplication controller:\n\n```javascript\n// application.js\nvar BaseController = require('chungking').BaseController;\n\nvar Application = BaseController.extend(function() {\n  // This before filter will be called whenever a controller that\n  // extends Application gets an action called.\n  this.beforeFilter(function() {\n    if(!this.req.user) this.res.send('Unauthorized!');\n    else this.next();\n  });\n\n  // Set up some useful aliases\n  this.beforeFilter(function() {\n    this.currentSection = 'Application';\n  });\n\n  // This action will be available to any controller that extends\n  // the Application controller.\n  this.action('whoami', function() {\n    this.res.send(this.req.user);\n  });\n});\n\nmodule.exports = Application;\n```\n\nUsers controller which extends the Application controller:\n\n```javascript\n// users.js\nvar Application = require('./application');\n\nvar Users = Application.extend(function() {\n  this.beforeFilter(function() {\n    console.log('This will be called after the Application'\n      + 'controller\\'s before filters.');\n    this.next();\n  });\n  \n  this.action('index', function() {\n    this.res.send('We are in the section ' + this.currentSection);\n  });\n});\n```\n\n# TODO\n\nRethink how inheritance works. Maybe child controllers should not\ninherit before filters and actions.\n\nRefactor the way inheritance is done. Maybe use utils.inherit from\nnode.js http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor.\n","_id":"chungking@0.0.5","dist":{"shasum":"e79606c6aff7d8160e0da391ea5a5e256e2ab6f8","tarball":"https://registry.npmjs.org/chungking/-/chungking-0.0.5.tgz","integrity":"sha512-td9pt9n8jTiSbGTVvkAFeLbPkitRC1teXZPfGVyygoynbniwngeXozA7ho/87dBFeh1aGqBeSclO5CaFjZW8Cw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGZlD0S/llaxXgbb9YmnPJ19w816HoMq4G0G2nnoKkK9AiEAjQDXE/9M/Li99gjP9s74y7AjekmH0OvemUxGLYP256o="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"directories":{}},"0.0.6":{"name":"chungking","description":"Controllers for Node.js and Express.","version":"0.0.6","main":"./lib/index","dependencies":{"express":""},"repository":{"type":"git","url":"git://github.com/olalonde/chungking.git"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com","url":"http://www.syskall.com"},"readme":"# Chungking \n\nController for Connect and Express (Node.js / Express.js /\nConnect.js). Name comes from [Chungking Express](http://en.wikipedia.org/wiki/Chungking_Express).\n\n## Install\n\n    npm install chungking\n\n## Usage\n\nSet up a Users controller\n\n```javascript\n// users.js\nvar BaseController = require('chungking').BaseController;\n\nvar Users = BaseController.extend(function() {\n  // this === Users.prototype\n\n  // Before filters are called whenever you call an action.\n  // They are asynchronous so you need to call this.next()\n  // when you are done.\n  this.beforeFilter(function() {\n    console.log('This is called before any action is called.');\n    if(this.authenticate())\n      this.next();\n    else\n      this.res.send('Not authorized');\n  });\n  \n  // You can also add methods that are available to all your\n  // actions.\n  this.authenticate = function() {\n    console.log('You can put some authentication code here.');\n    return true;\n  }\n\n  // Add actions below\n  this.action('index', function() {\n    // this.req, this.res, this.next are available anywhere in\n    // your controller.\n    this.res.send('Users index.');\n  });\n\n});\n\nmodule.exports = Users;\n```\n\nCall the controller from your request handler:\n\n```javascript\n// app.js\nvar Users = require('./users');\n\n// ...\n\napp.get('/users', function(req, res, next) {\n  var ctl = new Users(req, res, next);\n  ctl.action('index');\n});\n```\n\nThat's it!\n\n### Restricting beforeFilters to only specific actions\n\n```javascript\nthis.authorize = function() {\n  console.log('This is called before any action is called.');\n  //authentication code here...\n}\n\n// restrict to only some actions\nthis.beforeFilter({only: ['edit', 'update', 'create']}, function() {\n  this.authorize();\n});\n\n// execute for all actions except listed actions\nthis.beforeFilter({except: ['show']}, function() {\n  this.authorize();\n});\n```\n\n### Tired of writing this.req, this.res and this.next?\n\nYou can optionally get them as params to your beforeFilters and actions.\n\n```javascript\nthis.beforeFilter(function(req, res, next) {\n  res.send('aaahhh much better :)');\n});\n```\n\n### Extending controllers\n\nYou can also extend controllers.\n\nApplication controller:\n\n```javascript\n// application.js\nvar BaseController = require('chungking').BaseController;\n\nvar Application = BaseController.extend(function() {\n  // This before filter will be called whenever a controller that\n  // extends Application gets an action called.\n  this.beforeFilter(function() {\n    if(!this.req.user) this.res.send('Unauthorized!');\n    else this.next();\n  });\n\n  // Set up some useful aliases\n  this.beforeFilter(function() {\n    this.currentSection = 'Application';\n  });\n\n  // This action will be available to any controller that extends\n  // the Application controller.\n  this.action('whoami', function() {\n    this.res.send(this.req.user);\n  });\n});\n\nmodule.exports = Application;\n```\n\nUsers controller which extends the Application controller:\n\n```javascript\n// users.js\nvar Application = require('./application');\n\nvar Users = Application.extend(function() {\n  this.beforeFilter(function() {\n    console.log('This will be called after the Application'\n      + 'controller\\'s before filters.');\n    this.next();\n  });\n  \n  this.action('index', function() {\n    this.res.send('We are in the section ' + this.currentSection);\n  });\n});\n```\n\n# TODO\n\nRethink how inheritance works. Maybe child controllers should not\ninherit before filters and actions.\n\nRefactor the way inheritance is done. Maybe use utils.inherit from\nnode.js http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor.\n","_id":"chungking@0.0.6","dist":{"shasum":"98d95859a83415efa2379078fb03cc54d0c72ff5","tarball":"https://registry.npmjs.org/chungking/-/chungking-0.0.6.tgz","integrity":"sha512-0Z2kOg4eBb7MPelxr2Gii1FuAc0rM79FSFvRJ3GpBSYIiNqgdRmu/u5jAzjHG+BPH0g9zhGT4U2Qyn4vsa5lqQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAaW8FLKXOUiaUpHujIUS0RkoxDIr1oXlbEwxhSwLHdPAiB1pTB+vanydKXNG6/YI40trifiwOVD8G5iPqUfdMsV5g=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"directories":{}},"0.0.7":{"name":"chungking","description":"Controllers for Node.js and Express.","version":"0.0.7","main":"./lib/index","dependencies":{"express":""},"repository":{"type":"git","url":"git://github.com/olalonde/chungking.git"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com","url":"http://www.syskall.com"},"readme":"# Chungking \n\nController for Connect and Express (Node.js / Express.js /\nConnect.js). Name comes from [Chungking Express](http://en.wikipedia.org/wiki/Chungking_Express).\n\n## Install\n\n    npm install chungking\n\n## Usage\n\nSet up a Users controller\n\n```javascript\n// users.js\nvar BaseController = require('chungking').BaseController;\n\nvar Users = BaseController.extend(function() {\n  // this === Users.prototype\n\n  // Before filters are called whenever you call an action.\n  // They are asynchronous so you need to call this.next()\n  // when you are done.\n  this.beforeFilter(function() {\n    console.log('This is called before any action is called.');\n    if(this.authenticate())\n      this.next();\n    else\n      this.res.send('Not authorized');\n  });\n  \n  // You can also add methods that are available to all your\n  // actions.\n  this.authenticate = function() {\n    console.log('You can put some authentication code here.');\n    return true;\n  }\n\n  // Add actions below\n  this.action('index', function() {\n    // this.req, this.res, this.next are available anywhere in\n    // your controller.\n    this.res.send('Users index.');\n  });\n\n});\n\nmodule.exports = Users;\n```\n\nCall the controller from your request handler:\n\n```javascript\n// app.js\nvar Users = require('./users');\n\n// ...\n\napp.get('/users', function(req, res, next) {\n  var ctl = new Users(req, res, next);\n  ctl.action('index');\n});\n```\n\nThat's it!\n\n### Restricting beforeFilters to only specific actions\n\n```javascript\nthis.authorize = function() {\n  console.log('This is called before any action is called.');\n  //authentication code here...\n}\n\n// restrict to only some actions\nthis.beforeFilter({only: ['edit', 'update', 'create']}, function() {\n  this.authorize();\n});\n\n// execute for all actions except listed actions\nthis.beforeFilter({except: ['show']}, function() {\n  this.authorize();\n});\n```\n\n### Tired of writing this.req, this.res and this.next?\n\nYou can optionally get them as params to your beforeFilters and actions.\n\n```javascript\nthis.beforeFilter(function(req, res, next) {\n  res.send('aaahhh much better :)');\n});\n```\n\n### Extending controllers\n\nYou can also extend controllers.\n\nApplication controller:\n\n```javascript\n// application.js\nvar BaseController = require('chungking').BaseController;\n\nvar Application = BaseController.extend(function() {\n  // This before filter will be called whenever a controller that\n  // extends Application gets an action called.\n  this.beforeFilter(function() {\n    if(!this.req.user) this.res.send('Unauthorized!');\n    else this.next();\n  });\n\n  // Set up some useful aliases\n  this.beforeFilter(function() {\n    this.currentSection = 'Application';\n  });\n\n  // This action will be available to any controller that extends\n  // the Application controller.\n  this.action('whoami', function() {\n    this.res.send(this.req.user);\n  });\n});\n\nmodule.exports = Application;\n```\n\nUsers controller which extends the Application controller:\n\n```javascript\n// users.js\nvar Application = require('./application');\n\nvar Users = Application.extend(function() {\n  this.beforeFilter(function() {\n    console.log('This will be called after the Application'\n      + 'controller\\'s before filters.');\n    this.next();\n  });\n  \n  this.action('index', function() {\n    this.res.send('We are in the section ' + this.currentSection);\n  });\n});\n```\n\n# TODO\n\nRethink how inheritance works. Maybe child controllers should not\ninherit before filters and actions.\n\nRefactor the way inheritance is done. Maybe use utils.inherit from\nnode.js http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor.\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/olalonde/chungking/issues"},"_id":"chungking@0.0.7","dist":{"shasum":"611dfcfb2d5d1f7d3b3d2142133491ba0d2d700f","tarball":"https://registry.npmjs.org/chungking/-/chungking-0.0.7.tgz","integrity":"sha512-LVWCTVh3ZzC9CXddBGYsSCxpKcSZD7oQI11uvwermZGm82qmOz5fFwRGxUbZB+wESEWXt7raFw3E9XzkaNOvzA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF8gDtdiIAE94nOry+lcNMwKJfBttf3ME8eBB0FijZbZAiAMpl5Ts038RyTIM8y3IbeyK6kxbCo9KTl95YSoO92UDw=="}]},"_from":".","_npmVersion":"1.2.21","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}]}},"readme":"# Chungking \n\nController for Connect and Express (Node.js / Express.js /\nConnect.js). Name comes from [Chungking Express](http://en.wikipedia.org/wiki/Chungking_Express).\n\n## Install\n\n    npm install chungking\n\n## Usage\n\nSet up a Users controller\n\n```javascript\n// users.js\nvar BaseController = require('chungking').BaseController;\n\nvar Users = BaseController.extend(function() {\n  // this === Users.prototype\n\n  // Before filters are called whenever you call an action.\n  // They are asynchronous so you need to call this.next()\n  // when you are done.\n  this.beforeFilter(function() {\n    console.log('This is called before any action is called.');\n    if(this.authenticate())\n      this.next();\n    else\n      this.res.send('Not authorized');\n  });\n  \n  // You can also add methods that are available to all your\n  // actions.\n  this.authenticate = function() {\n    console.log('You can put some authentication code here.');\n    return true;\n  }\n\n  // Add actions below\n  this.action('index', function() {\n    // this.req, this.res, this.next are available anywhere in\n    // your controller.\n    this.res.send('Users index.');\n  });\n\n});\n\nmodule.exports = Users;\n```\n\nCall the controller from your request handler:\n\n```javascript\n// app.js\nvar Users = require('./users');\n\n// ...\n\napp.get('/users', function(req, res, next) {\n  var ctl = new Users(req, res, next);\n  ctl.action('index');\n});\n```\n\nThat's it!\n\n### Extending controllers\n\nYou can also extend controllers.\n\nApplication controller:\n\n```javascript\n// application.js\nvar BaseController = require('chungking').BaseController;\n\nvar Application = BaseController.extend(function() {\n  // This before filter will be called whenever a controller that\n  // extends Application gets an action called.\n  this.beforeFilter(function() {\n    if(!this.req.user) this.res.send('Unauthorized!');\n    else this.next();\n  });\n\n  // Set up some useful aliases\n  this.beforeFilter(function() {\n    this.currentSection = 'Application';\n  });\n\n  // This action will be available to any controller that extends\n  // the Application controller.\n  this.action('whoami', function() {\n    this.res.send(this.req.user);\n  });\n});\n\nmodule.exports = Application;\n```\n\nUsers controller which extends the Application controller:\n\n```javascript\n// users.js\nvar Application = require('./application');\n\nvar Users = Application.extend(function() {\n  this.beforeFilter(function() {\n    console.log('This will be called after the Application'\n      + 'controller\\'s before filters.');\n    this.next();\n  });\n  \n  this.action('index', function() {\n    this.res.send('We are in the section ' + this.currentSection);\n  });\n});\n```\n\n# TODO #\n\n- Limit before filters to only given actions.\n- Create some useful alias for commonly used methods (i.e. this.res.send could be mapped to this.send)\n","maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"time":{"modified":"2022-06-13T06:01:31.510Z","created":"2012-10-19T09:15:09.066Z","0.0.1":"2012-10-19T09:15:13.241Z","0.0.2":"2012-10-24T10:11:35.359Z","0.0.3":"2012-10-29T12:11:01.060Z","0.0.4":"2012-10-29T12:13:01.354Z","0.0.5":"2012-11-06T00:26:03.598Z","0.0.6":"2012-11-12T13:22:12.163Z","0.0.7":"2013-06-05T18:32:29.993Z"},"author":{"name":"Olivier Lalonde","email":"olalonde@gmail.com","url":"http://www.syskall.com"},"repository":{"type":"git","url":"git://github.com/olalonde/chungking.git"}}