<commit_before>
# Express-goose

 Express-goose adds Mongoose Query and Promise support to Express render, partial, and send methods.

## Installation

    $ npm install express-goose

### Example

    In your models:

    User.methods.getLikes = function (callback) {
      // returns a Query
      return this.model('Likes').find({ _user: this._id }, callback);
    };

    News.statics.getLatest = function (callback) {
      var promise = new Promise;
      if (callback) promise.addBack(callback);
      this.find({ datePublished: { $gt: new Date(Date.now() - 60000*60) } }, promise.resolve.bind(promise));
      return promise;
    };

    In your routes:

    app.get('/dashboard', function (req, res) {
      var News = db.model('News');

      // render support
      res.render('dashboard', {
          likes: req.user.getLikes()
        , latestNews: News.getLatest()
      });
    });

    app.get('/partial', function (req, res, next) {
      res.partial('likes', {
          likes: req.user.getLikes()
      });
    });

    app.get('/send', function (req, res) {
      // just pass a Query or Promise in and the result will be rendered as json.
      // if an error occurs, the error will be next()ed along as expected.
      var News = db.model('News');
      res.send(News.getLatest());
    });

    app.get('/promises', function (req, res) {
      var promise = new Promise(somethingAsync);
      res.send(promise);
    });

### Features

 res.render support
 res.partial support
 res.send support

### Error handling

 If a Query or Promise resolves to an error it will be forwarded on with `next(err)` as expected.

## Authors

  - [<NAME> (aheckmann)](http://github.com/aheckmann)

## More Information

## License

(The MIT License)

Copyright (c) 2011 LearnBoost &lt;<EMAIL>&gt;

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the<commit_msg>add nested locals examples<commit_after>
# Express-goose

 Express-goose adds Mongoose Query and Promise support to Express render, partial, and send methods.

## Installation

    $ npm install express-goose

### Example

    In your models:

    User.methods.getLikes = function (callback) {
      // returns a Query
      return this.model('Likes').find({ _user: this._id }, callback);
    };

    News.statics.getLatest = function (callback) {
      var promise = new Promise;
      if (callback) promise.addBack(callback);
      this.find({ datePublished: { $gt: new Date(Date.now() - 60000*60) } }, promise.resolve.bind(promise));
      return promise;
    };

    In your routes:

    app.get('/dashboard', function (req, res) {
      var News = db.model('News');

      // render support
      res.render('dashboard', {
          likes: req.user.getLikes()
        , latestNews: News.getLatest()
        , locals: {
            backwardcompatible: new Promise(somethingAsync)
          }
      });
    });

    app.get('/partial', function (req, res, next) {
      res.partial('likes', {
          likes: req.user.getLikes()
        , locals: {
            backwardcompatible: new Promise(somethingAsync)
          }
      });
    });

    app.get('/send', function (req, res) {
      // just pass a Query or Promise in and the result will be rendered as json.
      // if an error occurs, the error will be next()ed along as expected.
      var News = db.model('News');
      res.send(News.getLatest());
    });

    app.get('/promises', function (req, res) {
      var promise = new Promise(somethingAsync);
      res.send(promise);
    });

    app.get('/more', function (req, res) {
      res.send({
          promise: new Promise(somethingAsync)
        , news: req.user.getLatest()
      });
    });

### Features

 res.render support
 res.partial support
 res.send support
 nested express locals support

### Error handling

 If a Query or Promise resolves to an error it will be forwarded on with `next(err)` as expected.

## Authors

  - [<NAME> (aheckmann)](http://github.com/aheckmann)

## More Information

## License

(The MIT License)

Copyright (c) 2011 LearnBoost &lt;<EMAIL>&gt;

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
{'fraction_non_alphanumeric': 0.12882147024504084, 'fraction_numerical': 0.005134189031505251, 'mean_word_length': 2.698015530629853, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '697176', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1237, 'n_words': 394}