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 bogart = require('bogart') | |
, jade = require('jade') | |
, when = bogart.q.when; | |
require('bogart').viewEngine.addEngine('jade', function(read, cache, opts) { | |
return when(read(), function(tpl) { | |
var fn; | |
if(typeof tpl === "function") { | |
fn = tpl; |
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 q = require('q'); | |
var a = q.defer(); | |
var b = q.defer(); | |
q.when(a, function() { | |
console.log('calling b'); | |
return q.when(b, function() { | |
console.log('throwing'); | |
throw new Error('Hello World'); |
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 ForEachStream(forEachable) { | |
if (!(this instanceof ForEachStream)) return new ForEachStream(forEachable); | |
Stream.call(this); | |
var self = this; | |
this.fd = null; | |
this.readable = true; |
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 bogart = require('bogart'); | |
var Q = require('promised-io/lib/promise'); | |
var mongoose = require('mongoose'); | |
var PostSchema = new mongoose.Schema({ | |
title: String, | |
body: String, | |
comments: [ CommentSchema ] | |
}); |
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
jsContext.Execute(@" | |
validateOptions = { | |
fields: { | |
'first_name': { | |
validations: [ | |
{ isValid: 'required', message: 'First Name is required' } | |
] | |
} | |
} | |
}; |
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
return when(this.httpClient.request(opts), function success(resp) { | |
var body = ""; | |
return when(resp.body.forEach(function(chunk) { body += chunk; }), function() { | |
var val = JSON.parse(body); | |
if (resp.status >= 400) { | |
try { | |
val = JSON.parse(body); | |
} catch (err) { | |
val = { error: 'ParseError', reason: body } |
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
exports.CookieJar = function(nextApp) { | |
var domainToCookies = {}; | |
return function(req) { | |
var querystring = require("./querystring"); | |
if (req.url) { | |
throw new Error("CookieJar does not support 'url' shortcut yet"); | |
} | |
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 | |
Q = require('promised-io/promise'), | |
when = Q.when, | |
HttpClient = require('promised-io/http-client').Client, | |
sys = require('sys'); | |
exports.proxy = function(from, to, nextApp) { | |
var | |
client = new HttpClient(); | |