Browse files

BIG PHAT UPDATE

  • Loading branch information...
1 parent eea389e commit 1f84d79fe5756bec7c087cf6b92a4b845f7a7109 @bentruyman committed Feb 2, 2012
Showing with 70 additions and 50 deletions.
  1. +2 −1 .gitignore
  2. +49 −49 app.js
  3. +19 −0 package.json
View
3 .gitignore
@@ -1 +1,2 @@
-logs/*
+logs/
+node_modules/
View
98 app.js
@@ -1,18 +1,18 @@
process.chdir(__dirname);
-require.paths.push('/usr/local/lib/node');
-var express = require('express')
- , hl = require("highlight").Highlight
- , io = require('socket.io');
+var express = require('express'),
+ hl = require("highlight").Highlight,
+ io = require('socket.io');
-var app = express.createServer()
- , socket = io.listen(app);
+var app = express.createServer(),
+ socket = io.listen(app);
app.configure(function () {
- app.use(express.methodOverride());
- app.use(express.bodyDecoder());
- app.use(app.router);
- app.use(express.staticProvider(__dirname + '/public'));
+ app.use(express.methodOverride());
+ app.use(express.bodyParser());
+ app.use(app.router);
+ app.use(express.static(__dirname + '/public'));
+ app.set('view engine', 'jade');
});
// Colors
@@ -23,56 +23,56 @@ var tips = require('./tips');
// Make 'em sexy
tips.forEach(function (tip) {
- if (tip.example) {
- tip.example = hl(tip.example.join('\n'));
- }
-});
+ if (tip.example) {
+ tip.example = hl(tip.example.join('\n'));
+ }
+});
+
+// Utilities
+function showTip (req, res, index) {
+ res.render('index.jade', {
+ locals: {
+ tip: tips[index - 1],
+ color: colors[Math.floor(Math.random() * colors.length)],
+ index: index
+ }
+ });
+}
+
+function generateTip (index) {
+ return {
+ tip: tips[index - 1],
+ color: colors[Math.floor(Math.random() * colors.length)],
+ index: index
+ };
+}
+
+function generateRandomIndex() {
+ return Math.ceil(Math.random() * tips.length);
+}
// Routes
app.get('/', function (req, res) {
- showTip(req, res, generateRandomIndex());
+ showTip(req, res, generateRandomIndex());
});
app.get('/:permalink', function (req, res) {
- var index = req.params.permalink;
+ var index = req.params.permalink;
- if (tips[index - 1]) {
- showTip(req, res, index);
- } else {
- res.redirect('/');
- }
+ if (tips[index - 1]) {
+ showTip(req, res, index);
+ } else {
+ res.redirect('/');
+ }
});
// WebSocket
socket.on('connection', function(client){
- client.on('message', function (action) {
- if (action === 'refresh') {
- client.send(JSON.stringify(generateTip(generateRandomIndex())));
- }
- });
+ client.on('message', function (action) {
+ if (action === 'refresh') {
+ client.send(JSON.stringify(generateTip(generateRandomIndex())));
+ }
+ });
});
-// Utilities
-function showTip (req, res, index) {
- res.render('index.jade', {
- locals: {
- tip: tips[index - 1],
- color: colors[Math.floor(Math.random() * colors.length)],
- index: index
- }
- });
-}
-
-function generateTip (index) {
- return {
- tip: tips[index - 1],
- color: colors[Math.floor(Math.random() * colors.length)],
- index: index
- };
-}
-
-function generateRandomIndex() {
- return Math.ceil(Math.random() * tips.length);
-}
-
app.listen(3000);
View
19 package.json
@@ -0,0 +1,19 @@
+{
+ "author": "Ben Truyman (http://bentruyman.com/)",
+ "name": "enterprise-html",
+ "version": "0.0.0",
+ "homepage": "https://github.com/bentruyman/enterprise-html",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/bentruyman/enterprise-html.git"
+ },
+ "engines": {
+ "node": "~0.6.9"
+ },
+ "dependencies": {
+ "express": "2.5.6",
+ "highlight": "0.2.1",
+ "jade": "0.20.1",
+ "socket.io": "0.8.7"
+ }
+}

0 comments on commit 1f84d79

Please sign in to comment.