<commit_before># Chungking 

Controller for Connect and Express (Node.js / Express.js /
Connect.js). Name comes from [Chungking Express](http://en.wikipedia.org/wiki/Chungking_Express).

## Install

    npm install chungking

## Usage

Set up a Users controller

```javascript
// users.js
var BaseController = require('chungking').BaseController;

var Users = BaseController.extend(function() {
  // this === Users.prototype

  // Before filters are called whenever you call an action.
  // They are asynchronous so you need to call this.next()
  // when you are done.
  this.beforeFilter(function() {
    console.log('This is called before any action is called.');
    if(this.authenticate())
      this.next();
    else
      this.res.send('Not authorized');
  });
  
  // You can also add methods that are available to all your
  // actions.
  this.authenticate = function() {
    console.log('You can put some authentication code here.');
    return true;
  }

  // Add actions below
  this.action('index', function() {
    // this.req, this.res, this.next are available anywhere in
    // your controller.
    this.res.send('Users index.');
  });

});

module.exports = Users;
```

Call the controller from your request handler:

```javascript
// app.js
var Users = require('./users');

// ...

app.get('/users', function(req, res, next) {
  var ctl = new Users(req, res, next);
  ctl.action('index');
});
```

That's it!

### Extending controllers

You can also extend controllers.

Application controller:

```javascript
// application.js
var BaseController = require('chungking').BaseController;

var Application = BaseController.extend(function() {
  // This before filter will be called whenever a controller that
  // extends Application gets an action called.
  this.beforeFilter(function() {
    if(!this.req.user) res.send('Unauthorized!');
    else this.next();
  });

  // Set up some useful aliases
  this.beforeFilter(function() {
    this.currentSection = 'Application';
  });

  // This action will be available to any controller that extends
  // the Application controller.
  this.action('whoami', function() {
    this.res.send(this.req.user);
  });
});

module.exports = Application;
```

Users controller which extends the Application controller:

```javascript
// users.js
var Application = require('./application');

var Users = Application.extend(function() {
  this.beforeFilter(function() {
    console.log('This will be called after the Application'
      + 'controller\'s before filters.');
    this.next();
  });
  
  this.action('index', function() {
    res.send('We are in the section ' + this.currentSection);
  });
});
```

# TODO #

- Limit before filters to only given actions.
- Create some useful alias for commonly used methods (i.e. this.res.send could be mapped to this.send)<commit_msg>Fixed typos in README<commit_after># Chungking 

Controller for Connect and Express (Node.js / Express.js /
Connect.js). Name comes from [Chungking Express](http://en.wikipedia.org/wiki/Chungking_Express).

## Install

    npm install chungking

## Usage

Set up a Users controller

```javascript
// users.js
var BaseController = require('chungking').BaseController;

var Users = BaseController.extend(function() {
  // this === Users.prototype

  // Before filters are called whenever you call an action.
  // They are asynchronous so you need to call this.next()
  // when you are done.
  this.beforeFilter(function() {
    console.log('This is called before any action is called.');
    if(this.authenticate())
      this.next();
    else
      this.res.send('Not authorized');
  });
  
  // You can also add methods that are available to all your
  // actions.
  this.authenticate = function() {
    console.log('You can put some authentication code here.');
    return true;
  }

  // Add actions below
  this.action('index', function() {
    // this.req, this.res, this.next are available anywhere in
    // your controller.
    this.res.send('Users index.');
  });

});

module.exports = Users;
```

Call the controller from your request handler:

```javascript
// app.js
var Users = require('./users');

// ...

app.get('/users', function(req, res, next) {
  var ctl = new Users(req, res, next);
  ctl.action('index');
});
```

That's it!

### Extending controllers

You can also extend controllers.

Application controller:

```javascript
// application.js
var BaseController = require('chungking').BaseController;

var Application = BaseController.extend(function() {
  // This before filter will be called whenever a controller that
  // extends Application gets an action called.
  this.beforeFilter(function() {
    if(!this.req.user) this.res.send('Unauthorized!');
    else this.next();
  });

  // Set up some useful aliases
  this.beforeFilter(function() {
    this.currentSection = 'Application';
  });

  // This action will be available to any controller that extends
  // the Application controller.
  this.action('whoami', function() {
    this.res.send(this.req.user);
  });
});

module.exports = Application;
```

Users controller which extends the Application controller:

```javascript
// users.js
var Application = require('./application');

var Users = Application.extend(function() {
  this.beforeFilter(function() {
    console.log('This will be called after the Application'
      + 'controller\'s before filters.');
    this.next();
  });
  
  this.action('index', function() {
    this.res.send('We are in the section ' + this.currentSection);
  });
});
```

# TODO #

- Limit before filters to only given actions.
- Create some useful alias for commonly used methods (i.e. this.res.send could be mapped to this.send)
{'fraction_non_alphanumeric': 0.13657162970784936, 'fraction_numerical': 0.0, 'mean_word_length': 3.4537617554858935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '847111', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1600, 'n_words': 520}