Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BIG PHAT UPDATE

  • Loading branch information...
commit 5c235b56b3935e2f410e319470edb12844dd85ae 1 parent 1caf44e
@bentruyman authored
Showing with 74 additions and 56 deletions.
  1. +2 −1  .gitignore
  2. +53 −55 app.js
  3. +19 −0 package.json
View
3  .gitignore
@@ -1 +1,2 @@
-logs/*
+logs/
+node_modules/
View
108 app.js
@@ -1,82 +1,80 @@
-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
var colors = 'ff0090,ffff00,0bff00,08e3ff,ff460d'.split(',');
// Tips
-var tips = require('./tips');
+var tips = require(__dirname + '/tips');
// Make 'em sexy
tips.forEach(function (tip) {
- if (tip.example) {
- // Wrap it in script tags to trigger JavaScript highlighting...sigh
- tip.example = hl('<script>\n' + tip.example.join('\n') + '\n</script>');
- // Unwrap (hax)
- tip.example = tip.example.replace('<span class="tag">&lt;<span class="keyword">script</span>&gt;</span><span class="javascript">', '');
- tip.example = tip.example.replace('</span><span class="tag">&lt;/<span class="keyword">script</span>&gt;</span>', '');
- }
+ if (tip.example) {
+ // Wrap it in script tags to trigger JavaScript highlighting...sigh
+ tip.example = hl('<script>\n' + tip.example.join('\n') + '\n</script>');
+ // Unwrap (hax)
+ tip.example = tip.example.replace('<span class="tag">&lt;<span class="keyword">script</span>&gt;</span><span class="javascript">', '');
+ tip.example = tip.example.replace('</span><span class="tag">&lt;/<span class="keyword">script</span>&gt;</span>', '');
+ }
});
+// 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(3002);
View
19 package.json
@@ -0,0 +1,19 @@
+{
+ "author": "Ben Truyman (http://bentruyman.com/)",
+ "name": "enterprise-js",
+ "version": "0.0.0",
+ "homepage": "https://github.com/bentruyman/enterprise-js",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/bentruyman/enterprise-js.git"
+ },
+ "engines": {
+ "node": "~0.6.9"
+ },
+ "dependencies": {
+ "express": "2.5.6",
+ "highlight": "0.2.1",
+ "jade": "0.20.1",
+ "socket.io": "0.8.7"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.