Permalink
Browse files

Tiny work, but I've got to get some sleep.

  • Loading branch information...
1 parent 49e677c commit 0ba5f1b2bf7ce94b42db141756a5cc15672f81f8 @leeadkins leeadkins committed Jun 3, 2011
Showing with 40 additions and 14 deletions.
  1. +30 −11 server.js
  2. +4 −0 static/css/site.css
  3. +3 −1 templates/index.jade
  4. +1 −0 templates/layout.jade
  5. +2 −2 templates/puzzle.jade
View
@@ -6,6 +6,26 @@ var express = require('express'),
var PORT = 3000;
+
+/*
+Here's some docs in case I fall asleep before this is done.
+URLs:
+ / - Obvious.
+ /puzzle/<slug> - Individual page for aggregate info about a single puzzle.
+ not done.
+ /puzzle/<slug>?format=json - Returns data from above in JSON format, useful
+ for building/updating the root page too.
+ /play - Get the list of puzzles
+ /play/puzzle/<slug>/<twittername> - Get a new puzzle
+ POST /play/puzzle/<slug>/<twittername> - Submit a puzzle
+
+
+It all needs testing, that's for sure.
+
+*/
+
+
+
var app = express.createServer();
app.configure(function(){
app.use(express.static(__dirname + '/static'));
@@ -77,11 +97,6 @@ app.post('/play/puzzle/:puzzleslug/:twittername', function(req, res){
//Send post to question.
//Wait for validated response.
//Rock the casbah
-
- //Get the puzzle.
- //find the attempt
- //See if the twitter names match up.
- //Do the thing.
var submit_time = Date.now();
var puzzle = puzzles[req.param('puzzleslug')];
if(typeof(puzzle) == 'undefined'){
@@ -135,14 +150,18 @@ app.get('/puzzle/:puzzleslug', function(req, res){
if(typeof(puzzle) == 'undefined'){
res.send('wat', 404);
} else {
- Attempt.find({}, function(err, atts){
- if(!err){
- console.log(atts);
+ Attempt.find({$where : 'this.total_time != null'}, function(err, atts){
+ if(!err && (req.param('format') == 'json')){
+ var results = atts.map(function(item){
+ return { player: item.twitter_name, time: item.total_time}
+ });
+ res.send(results);
+ } else if(!err){
res.render('puzzle', {
- attempts: atts
- });
+ locals: {attempts: atts}
+ });
} else {
- res.render('wat', 500);
+ res.render('Not Found', 500);
}
});
}
View
@@ -0,0 +1,4 @@
+/* Doing it real big */
+body {
+ background-color: #00b0ca;
+}
View
@@ -1 +1,3 @@
-p Sup, puzzlerer.
+p Sup, puzzlerer.
+- each puzzle in puzzles
+ = puzzle.name
View
@@ -2,6 +2,7 @@
html
head
title Puzzler
+ link(rel="stylesheet", href="/css/site.css")
body
!{body}
script(type="text/javascript", src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js")
View
@@ -1,2 +1,2 @@
-#puzzle= attempts
-
+- each attempt in attempts
+ = attempt

0 comments on commit 0ba5f1b

Please sign in to comment.