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() { | |
window.ThreadController = Backbone.Controller.extend({ | |
initialize: function() { | |
this.threadListModel = new ThreadListModel; | |
this.threadListView = new ThreadListView; | |
Backbone.history.start(); | |
}, | |
routes: { | |
"/" : "listThreads" |
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($) { | |
var app = $.sammy('#main', function() { | |
this.use('Template'); | |
this.get('#/', function(context) { | |
this.load('thread') | |
.then( function(threads) { | |
$.each(threads, function(i, thread) { | |
context.render('templates/thread.template', {thread : thread}) | |
.appendTo(context.$element()); | |
}); |
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
/* The API controller | |
Exports 3 methods: | |
* post - Creates a new thread | |
* list - Returns a list of threads | |
* show - Displays a thread and its posts | |
*/ | |
var Thread = require('../models/thread.js'); | |
var Post = require('../models/post.js'); |
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
module.exports = function(Thread, Post) { | |
return { | |
post: function(req, res) { | |
new Thread({title: req.body.title, author: req.body.author}).save(); | |
}, | |
list: function(req, res) { | |
Thread.find(function(err, threads) { | |
res.send(threads); | |
}); |
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 nodeunit = require('nodeunit'); | |
exports['API'] = nodeunit.testCase({ | |
'The show() API method returns a specific thread by title and its replies by threadid': function(test) { | |
test.expect(4); | |
// our mock data | |
var posts = [{post: 'test'}, {post: 'test2'}]; | |
var thread = {_id: '1234', title: 'my thread'}; |
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
case class Trip( | |
deviceId:String, | |
plannedDeparture: DateTime, | |
fromStation: String, | |
plannedDepartureFirstStation:DateTime, | |
viaStation: Option[String], | |
toStation: String, | |
plannedArrivalLastStation: DateTime) { | |
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 util = require("util"), | |
http = require("http"), | |
url = require("url"), | |
fileSystem = require('fs'), | |
path = require('path'); | |
var responseMap = [ | |
{pattern:/\btest\?test\=true$/, response:"test-ok.xml"}, | |
{pattern:/\btest\?test=true&henk=liev$/, response:"test-ok.xml"}, | |
// 'begins with' test |
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
/* | |
Uses latest & greatest NodeJS version (0.7.5), may cause external libraries | |
like Mu to not work because of a changed package (sys was renamed to util) | |
Fix manually by going into ./node_modules/mu and replacing all instances of | |
require('sys') with require('util'). Should just run under earlier versions | |
of Node as long as you replace the below require('util') with require('sys'). | |
Download dependencies using 'npm install' | |
Run using node mock.js <port (optional)> |
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 sync = Backbone.sync; | |
Backbone.sync = function(method, model, options) { | |
if (!options.error) { | |
options.error = function(method, model, options) { | |
// custom error handling here. | |
} | |
} | |
}; | |
sync(method, model, options); |
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
import ObjectMapper | |
struct Test: Mappable { | |
let name: String | |
init?(_ map: Map) { | |
name = map["name"].valueOrFail() | |
if !map.isValid { | |
return nil |