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
// 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); |
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
Application = Thorax.Application.create() | |
# convenience for debugging | |
window.Application = Application | |
# main view controller | |
Application.ViewController.create | |
parent: Application | |
routes: | |
'': 'index' |
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
Thorax Bind Plugin | |
================== | |
## View Helpers | |
### bind *{{#bind "methodName"}}* | |
Standalone usage: | |
new Thorax.View({ |
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() { | |
var root = this, | |
Backbone = root.Backbone, | |
Handlebars = root.Handlebars, | |
Thorax = root.Thorax, | |
_ = root._, | |
$ = root.$, | |
_configure = Thorax.View.prototype._configure, | |
_render = Thorax.View.prototype.render, |
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(){ | |
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; |
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
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'); |
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
/* | |
based on https://github.com/rickharrison/validate.js | |
*/ | |
(function(){ | |
var validationAttributeNamePrefix = 'data-validate-', | |
errorMessageAttributeName = 'data-error-message', | |
numericRegex = /^[0-9]+$/, | |
integerRegex = /^\-?[0-9]+$/, |
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
test("validations", function() { | |
var lastErrors; | |
var regexValidationViewErrorCount = 0; | |
var regexValidationView = new Application.View({ | |
events: { | |
error: function(errors) { | |
++regexValidationViewErrorCount; | |
lastErrors = errors; | |
} |
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
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"}}' |
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
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'); |
OlderNewer