Skip to content
Browse files

A preliminary page with a form for posting clues

  • Loading branch information...
1 parent d20a546 commit dbe61d0181887d7639ead294e8544a5d5941957c @wscherphof committed
Showing with 74 additions and 4 deletions.
  1. +22 −0 .gitattributes
  2. +34 −4 server.js
  3. +18 −0 views/clues.jade
View
22 .gitattributes
@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+*.sln merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
View
38 server.js
@@ -1,8 +1,38 @@
var http = require('http');
+var util = require('util');
+var express = require('express');
-var server = http.createServer(function (req, res) {
- console.log(req);
- res.close();
+var app = express.createServer();
+
+app.configure(function () {
+ app.use(express.bodyParser());
+});
+
+var clues = [];
+var clueFields = [];
+app.get('/clues', function (req, res) {
+ res.render('clues.jade', {layout: false});
});
-server.listen(process.env.PORT, '0.0.0.0');
+app.post('/clues', function (req, res) {
+ var lines = req.body.clues.split('\r\n');
+ if (req.body.purge) clues = clueFields = [];
+ if (req.body.fieldNames) {
+ var firstLine = lines.shift();
+ if (clueFields.length === 0) clueFields = firstLine.split(',');
+ }
+ lines.forEach(function (line) {
+ if (line === '') return;
+ var clue = {};
+ var values = line.split(',');
+ values.forEach(function (value, i) {
+ var name = clueFields[i] || i;
+ clue[name] = value;
+ });
+ clues.push(clue);
+ });
+ res.end(util.inspect(clues));
+});
+
+
+app.listen(3000);
View
18 views/clues.jade
@@ -0,0 +1,18 @@
+doctype html
+html
+ head
+ body
+ header Clues
+ section
+ p
+ form(method='post', action='clues')
+ textarea(name='clues', placeholder='Paste in some clues as comma-separated values')
+ br
+ input(type='checkbox', name='fieldNames')
+ |First line contains field names
+ br
+ input(type='checkbox', name='purge')
+ |Purge - clear all previously defnined clues
+ br
+ input(type='submit')
+

0 comments on commit dbe61d0

Please sign in to comment.
Something went wrong with that request. Please try again.