Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgoodwin committed Oct 5, 2012
0 parents commit 120c137
Show file tree
Hide file tree
Showing 43 changed files with 26,495 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.DS_Store
/public/
/node_modules/
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node index.js
73 changes: 73 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
var childProcess = require('child_process'),
exec = childProcess.exec,
spawn = childProcess.spawn,
fs = require('fs'),
path = require('path'),
port = process.env.PORT,
execute = function(command, args, callback) {
console.log(command + ' ' + args.join(' '));
var command = spawn(command, args);
command.stdout.on('data', function (data) {
process.stdout.write(data);
});
command.stderr.on('data', function (data) {
process.stderr.write(data);
});
command.on('exit', callback || function(){});
},
startServer = function() {
var express = require('express'),
argv = require('optimist').argv,
port = process.env.PORT;

if (argv.watch) {
var lumbar = spawn('lumbar', [
'watch',
path.join(__dirname, 'lumbar.json'),
path.join(__dirname, 'public')
]);
lumbar.stdout.on('data', function(data) {
process.stdout.write(data.toString());
});
lumbar.stderr.on('data', function(data) {
process.stdout.write(data.toString());
});
}

var server = express.createServer();
server.use(express.logger());
server.use(express.bodyParser());
server.use(express.static(path.join(__dirname, 'public')));

function listen(foundPort) {
console.log('Express server listening on port ' + foundPort);
server.listen(foundPort);
}

if (!port) {
require('portscanner').findAPortNotInUse(8000, 8025, 'localhost', function(error, foundPort) {
listen(foundPort);
});
} else {
listen(port);
}

var serverPath = path.join(__dirname, 'server');

if (!path.existsSync(serverPath)) {
fs.mkdirSync(serverPath);
}

fs.readdirSync(serverPath).forEach(function(file) {
if (file.match(/\.js$/)) {
//second parameter is reserved for future use, secureServer
require(path.join(__dirname, 'server', file))(server, null, argv);
}
});
};

if (!path.existsSync(path.join(__dirname, 'node_modules'))) {
execute('npm',['install'], startServer);
} else {
startServer();
}
Binary file added js/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions js/collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Application.Collection = Thorax.Collection.extend({

});
Empty file added js/collections/.gitignore
Empty file.
41 changes: 41 additions & 0 deletions js/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//all templates are assumed to be in the templates directory
Thorax.templatePathPrefix = 'templates/';

//create the Application object, Application.setView() will
//place a view inside the {{layout}}
var Application = window.Application = module.exports = new (Thorax.ViewController.extend(_.extend(module.exports, {
//set a name so it will use the applications.handlebars template
name: 'application'
})));

//alias the special hashes for naming consitency
Application.templates = Thorax.templates;
Application.Views = Thorax.Views;
Application.Models = Thorax.Models;
Application.Collections = Thorax.Collections;
Application.Routers = Thorax.Routers;

//allows load:end and load:start events to propagate
//to the application object
Thorax.setRootObject(Application);

$(function() {
//Application and other templates included by the base
//Application may want to use the link and url helpers
//which use hasPushstate, etc. so setup history, then
//render, then dispatch
//initialize the lumbar-loader for backbone, which will
//load modules if needed when a route is matched
Application.initBackboneLoader();
Backbone.history.start({
pushState: false,
root: '/',
silent: true
}); Application.render();
$('body').append(Application.el);
//mimic when a ViewController will trigger the "ready"
//event on a view, since this is the top level object
//it needs to be triggered manually
Application.trigger('ready');
Backbone.history.loadUrl();
});
Binary file added js/lib/.DS_Store
Binary file not shown.
Loading

0 comments on commit 120c137

Please sign in to comment.