Skip to content

Instantly share code, notes, and snippets.

// SERVER HERE
var http = require('http'),
io = require('socket.io'), // for npm, otherwise use require('./path/to/socket.io')
server = http.createServer(function(req, res){
// your normal server code
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<h1>Hello world</h1>');
});
server.listen(80);
Application = Thorax.Application.create()
# convenience for debugging
window.Application = Application
# main view controller
Application.ViewController.create
parent: Application
routes:
'': 'index'
@eastridge
eastridge / gist:3351794
Created August 14, 2012 19:07
Thorax bind docs
Thorax Bind Plugin
==================
## View Helpers
### bind *{{#bind "methodName"}}*
Standalone usage:
new Thorax.View({
@eastridge
eastridge / gist:3351803
Created August 14, 2012 19:08
Thorax bind implementation
(function() {
var root = this,
Backbone = root.Backbone,
Handlebars = root.Handlebars,
Thorax = root.Thorax,
_ = root._,
$ = root.$,
_configure = Thorax.View.prototype._configure,
_render = Thorax.View.prototype.render,
@eastridge
eastridge / gist:3351815
Created August 14, 2012 19:09
Thorax bind tests
$(function(){
QUnit.module('Thorax bind');
test("bind helper", function() {
var callCount = 0;
var view = new Thorax.View({
i: 0,
template: '<ul>{{bind "counter" tag="li"}}{{bind "counter" tagName="li"}}</ul>',
counter: function(i) {
++callCount;
@eastridge
eastridge / gist:3351915
Created August 14, 2012 19:17
Thorax form helpers
var errorClassName = 'error',
errorAttributeName = 'data-view-error',
inputErrorAttributeName = 'data-input-error-id';
Thorax.View.registerPartialHelper('error', function(partial) {
if (!partial.el.className || partial.el.className === '') {
partial.$el.addClass('alert alert-error');
}
partial.$el.attr(errorAttributeName, 'true');
@eastridge
eastridge / gist:3351920
Created August 14, 2012 19:18
Thorax form validations
/*
based on https://github.com/rickharrison/validate.js
*/
(function(){
var validationAttributeNamePrefix = 'data-validate-',
errorMessageAttributeName = 'data-error-message',
numericRegex = /^[0-9]+$/,
integerRegex = /^\-?[0-9]+$/,
@eastridge
eastridge / gist:3351929
Created August 14, 2012 19:19
Thorax validation tests
test("validations", function() {
var lastErrors;
var regexValidationViewErrorCount = 0;
var regexValidationView = new Application.View({
events: {
error: function(errors) {
++regexValidationViewErrorCount;
lastErrors = errors;
}
@eastridge
eastridge / gist:3351939
Created August 14, 2012 19:19
Thorax helper tests
test("input helper", function(){
var textInputView = new Application.View({
key: 'value',
template: '{{input type="text" class="test" value="{{key}}"}}'
});
textInputView.render();
equal(textInputView.$('.test').val(), 'value');
var textareaInputView = new Application.View({
template: '{{input type="textarea" value="value"}}'
@eastridge
eastridge / gist:3352149
Created August 14, 2012 19:43
Thorax admin backend
module.exports = function(server, secureServer, argv) {
if (argv.admin) {
var path = require('path'),
_ = require('underscore'),
fs = require('fs'),
exec = require('child_process').exec,
pathPrefix = '/admin',
io = require('socket.io'),
mkdirp = require('mkdirp');