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
co(function *(){ | |
// the actual test that will use yield | |
// code, code, code | |
// and then, when we’re done… | |
})(done); |
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
var app = require('./app.js'); | |
var co = require('co'); | |
var should = require('should'); | |
var request = require('supertest').agent(app.listen()); | |
var posts = require('./blogRoutes.js').posts; | |
describe('Blog with mongo:', function(){ | |
var removeAll = function(done){ | |
co(function *(){ | |
yield posts.remove({}); |
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
{% extends 'layout.html' %} | |
{% block title %}Posts{% endblock %} | |
{% block content %} | |
<h1>Posts</h1> | |
<p>You have <strong>{{ posts.length }}</strong> posts!</p> | |
<p><a href="/post/new">Create a Post</a></p> | |
<ul id="posts"> | |
{% for post in posts %} |
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
// Dependencies. | |
var views = require('co-views'); | |
// setup views mapping .html | |
// to the swig template engine | |
module.exports = views(__dirname + '/views', { | |
map: { html: 'swig' } | |
}); |
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
// dependencies | |
var parse = require('co-body'); | |
var render = require('./render.js'); | |
// Set up monk | |
var monk = require('monk'); | |
var wrap = require('co-monk'); | |
var db = monk('localhost/koaMongoBlog'); | |
var posts = wrap(db.get('posts')); | |
module.exports.posts = posts; // Let's expose the posts collection for testing |
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
// Dependencies. | |
var logger = require('koa-logger'); | |
var route = require('koa-route'); | |
var koa = require('koa'); | |
var app = module.exports = koa(); | |
// middleware | |
app.use(logger()); | |
// route middleware |
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
{ | |
"name": "KoaMongoBlog", | |
"description": "A very simple blog using mongo via monk", | |
"version": "0.0.1", | |
"dependencies": { | |
"co": "^3.0.0", | |
"co-body": "0.0.1", | |
"co-views": "^0.1.0", | |
"koa": "^0.5.0", | |
"koa-logger": "^1.1.0", |
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
var elvis = theGenerator(); // get an instance of the generator | |
console.log(elvis.next().value); // outputs "One, for the money” | |
console.log(elvis.next().value); // outputs "Two, for the show" | |
console.log(elvis.next().value); // outputs "Three to get ready! Now go, cat, go" | |
/* | |
console.log(elvis.next()); // ouputs { value: undefined, done: true } | |
console.log(elvis.next()); // throws Error: Generator has already finished*/ |
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
function *theGenerator(){ | |
yield "One, for the money"; | |
yield "Two, for the show"; | |
yield "Three to get ready! Now go, cat, go"; | |
}; |
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
// Dependencies | |
var koa = require('koa'); | |
var app = koa(); | |
var logger = require('koa-logger'); | |
var route = require('koa-route'); | |
// Db access | |
var monk = require('monk'); | |
var wrap = require('co-monk'); | |
var db = monk('localhost/koaDemoUsers'); |