Skip to content

Instantly share code, notes, and snippets.

@alexbosworth
Created December 16, 2010 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbosworth/742867 to your computer and use it in GitHub Desktop.
Save alexbosworth/742867 to your computer and use it in GitHub Desktop.
an example of doing page classes in node.js
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