Created
December 16, 2010 01:05
-
-
Save alexbosworth/742867 to your computer and use it in GitHub Desktop.
an example of doing page classes in node.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
function echo(string) { console.log(string); } | |
process.on('uncaughtException', function (err) { | |
echo(err.stack); | |
echo('uncaught Exception: ' + err); | |
}); | |
var KEYS = require('keychain'), | |
$ = require('node-jquery'), | |
S3 = require('amazon-s3').S3; | |
var storage = function() { | |
return new S3(KEYS.AWS_KEY, KEYS.AWS_PASS); | |
}; | |
function BuzzPage(in_list) { | |
this.list = in_list; | |
this.steps = [ | |
this.htmlHeaders, | |
this.checkListExists, | |
this.htmlFooters | |
] | |
this.step(); | |
} | |
BuzzPage.prototype.step = function() { | |
$.proxy(this.steps.shift(), this)(); | |
}; | |
BuzzPage.prototype.htmlHeaders = function() { | |
echo('<h1>' + this.list + '</h1>'); | |
return this.step(); | |
}; | |
BuzzPage.prototype.htmlFooters = function() { | |
echo('<footer>Thank you, come again</footer>'); | |
}; | |
BuzzPage.prototype.checkListExists = function() { | |
var self = this; | |
storage().info(this.list + '/recent.json'). | |
on('failure', function() { | |
echo ('this list does not exist'); | |
return self.htmlFooters(); | |
}). | |
on('success', function(info) { | |
return self.step(); | |
}); | |
} | |
new BuzzPage(process.argv[2]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment