updated app

This commit is contained in:
2012-05-30 23:00:06 -04:00
parent 6a753904b7
commit da6ad88d48
5545 changed files with 1101709 additions and 60 deletions

View File

@@ -0,0 +1,118 @@
// Generated by CoffeeScript 1.3.1
var N, app, get, ready, render, _ref;
_ref = app = require('./index'), get = _ref.get, ready = _ref.ready;
render = require('./shared').render;
N = 100;
get('/bindings-bench', function(page, model) {
var boxes, i, _i;
boxes = [];
for (i = _i = 0; 0 <= N ? _i < N : _i > N; i = 0 <= N ? ++_i : --_i) {
boxes.push({
count: 0,
top: 0,
left: 0,
color: 0,
content: 0,
i: i
});
}
model.set('_boxes', boxes);
return render(page, 'bindingsBench', {
modes: ['setProperty', 'setBox', 'setAll']
});
});
ready(function(model) {
var boxValue, boxes, fn, frames, modes, run, setAll, setBox, setProperty, start, tickBox, tickProperty, timeout;
boxes = model.at('_boxes');
tickProperty = function(box) {
var count;
count = box.incr('count');
box.set('top', Math.sin(count / 10) * 10);
box.set('left', Math.cos(count / 10) * 10);
box.set('color', count % 255);
return box.set('content', count % 100);
};
setProperty = function() {
var i, _i;
for (i = _i = 0; 0 <= N ? _i < N : _i > N; i = 0 <= N ? ++_i : --_i) {
tickProperty(boxes.at(i));
}
};
tickBox = function(box, i) {
var count;
count = box.get('count') + 1;
return box.set({
count: count,
top: Math.sin(count / 10) * 10,
left: Math.cos(count / 10) * 10,
color: count % 255,
content: count % 100,
i: i
});
};
setBox = function() {
var i, _i;
for (i = _i = 0; 0 <= N ? _i < N : _i > N; i = 0 <= N ? ++_i : --_i) {
tickBox(boxes.at(i), i);
}
};
boxValue = function(box, i) {
var count;
count = box.count + 1;
return {
count: count,
top: Math.sin(count / 10) * 10,
left: Math.cos(count / 10) * 10,
color: count % 255,
content: count % 100,
i: i
};
};
setAll = function() {
var box, i, previous, value, _i, _len;
previous = boxes.get();
value = [];
for (i = _i = 0, _len = previous.length; _i < _len; i = ++_i) {
box = previous[i];
value.push(boxValue(box, i));
}
return boxes.set(value);
};
frames = 0;
start = fn = timeout = null;
run = function() {
var fps;
fn();
if (frames++ === 20) {
fps = frames * 1000 / (new Date - start);
model.set('_fps', fps.toFixed(1));
frames = 0;
start = +(new Date);
}
return timeout = setTimeout(run, 0);
};
modes = {
setProperty: setProperty,
setBox: setBox,
setAll: setAll
};
app.start = function(e, el) {
var mode;
clearTimeout(timeout);
mode = el.innerHTML;
model.set('_bindProperties', mode === 'setProperty');
model.set('_mode', mode);
fn = modes[mode];
frames = 0;
start = +(new Date);
return run();
};
return app.stop = function() {
return clearTimeout(timeout);
};
});

62
node_modules/derby-examples/sink/lib/app/home.js generated vendored Normal file
View File

@@ -0,0 +1,62 @@
// Generated by CoffeeScript 1.3.1
var app, get, ready, render, view, _ref;
_ref = app = require('./index'), get = _ref.get, ready = _ref.ready, view = _ref.view;
render = require('./shared').render;
view.fn('unspace', function(s) {
return s && s.replace(/\s/g, '');
});
view.fn('capitalize', function(s) {
return s && s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
});
get('/', function(page, model) {
return model.subscribe('home', function(err, home) {
home.setNull('titleColor', 'black');
home.setNull('colors', [
{
name: 'black'
}, {
name: 'deep pink'
}, {
name: 'lime green'
}, {
name: 'coral'
}, {
name: 'dark turquoise'
}, {
name: 'dark orchid'
}
]);
return render(page, 'home');
});
});
ready(function(model) {
var colors, home, titleColor;
home = model.at('home');
colors = home.at('colors');
titleColor = home.at('titleColor');
titleColor.on('pre:set', function(value, previous, isLocal, e) {
var titleSelect;
titleSelect = document.getElementById('titleSelect');
if (e && e.target.id === 'titleInput') {
return colors.at(titleSelect.selectedIndex).set('name', value);
}
});
colors.on('pre:set', '*.name', function(index, value, previous, isLocal, e) {
var titleSelect;
titleSelect = document.getElementById('titleSelect');
if (e && e.target.className === 'colorInput' && parseInt(index) === titleSelect.selectedIndex) {
return titleColor.set(value);
}
});
return app.home = {
select: function(e, el) {
return titleColor.set(model.at(el).get('name'));
}
};
});

53
node_modules/derby-examples/sink/lib/app/index.js generated vendored Normal file
View File

@@ -0,0 +1,53 @@
// Generated by CoffeeScript 1.3.1
var app, get, ready, render, _ref;
_ref = app = require('derby').createApp(module), get = _ref.get, ready = _ref.ready;
render = require('./shared').render;
require('./home');
require('./live-css');
require('./table');
require('./leaderboard');
require('./bindings-bench');
['get', 'post', 'put', 'del'].forEach(function(method) {
return app[method]('/submit', function(page, model, _arg) {
var args, body, query;
body = _arg.body, query = _arg.query;
args = JSON.stringify({
method: method,
body: body,
query: query
}, null, ' ');
return render(page, 'submit', {
args: args
});
});
});
get('/error', function() {
throw new Error(500);
});
get('/back', function(page) {
return page.redirect('back');
});
ready(function(model) {
model.set('_showReconnect', true);
exports.connect = function() {
model.set('_showReconnect', false);
setTimeout((function() {
return model.set('_showReconnect', true);
}), 1000);
return model.socket.socket.connect();
};
return exports.reload = function() {
return window.location.reload();
};
});

View File

@@ -0,0 +1,87 @@
// Generated by CoffeeScript 1.3.1
var addPlayer, app, get, randomScore, ready, render, view, _ref;
_ref = app = require('./index'), get = _ref.get, ready = _ref.ready, view = _ref.view;
render = require('./shared').render;
randomScore = function() {
return Math.floor(Math.random() * 20) * 5;
};
addPlayer = function(players, name) {
var id;
id = players.id();
return players.set(id, {
id: id,
name: name,
score: randomScore()
});
};
get('/leaderboard', function(page, model) {
return model.subscribe('leaderboard', function(err, leaderboard) {
var name, players, _i, _len, _ref1;
players = leaderboard.at('players');
if (!players.get()) {
_ref1 = ['Parker Blue', 'Kelly Green', 'Winston Fairbanks'];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
name = _ref1[_i];
addPlayer(players, name);
}
}
leaderboard.fn('_list', players, function(items) {
var id, item, out;
out = [];
for (id in items) {
item = items[id];
if (item != null ? item.id : void 0) {
out.push(item);
}
}
return out.sort(function(a, b) {
return (b.score - a.score) || (b.id > a.id);
});
});
model.ref(leaderboard.at('_selected'), players, leaderboard.at('_selectedId'));
return render(page, 'leaderboard');
});
});
ready(function(model) {
var leaderboard, newPlayer, players, selected, selectedId;
leaderboard = model.at('leaderboard');
players = leaderboard.at('players');
newPlayer = leaderboard.at('_newPlayer');
selectedId = leaderboard.at('_selectedId');
selected = leaderboard.at('_selected');
return app.leaderboard = {
add: function() {
var name;
if (!(name = newPlayer.get())) {
return;
}
addPlayer(players, name);
return newPlayer.set('');
},
remove: function() {
var id;
id = selected.get('id');
return players.del(id);
},
incr: function() {
return selected.incr('score', 5);
},
decr: function() {
return selected.incr('score', -5);
},
select: function(e, el) {
var id;
id = model.at(el).get('id');
return selectedId.set(id);
},
deselect: function() {
return selectedId.set(null);
}
};
});

72
node_modules/derby-examples/sink/lib/app/live-css.js generated vendored Normal file
View File

@@ -0,0 +1,72 @@
// Generated by CoffeeScript 1.3.1
var app, cssProperty, get, ready, render, view, _ref;
_ref = app = require('./index'), get = _ref.get, ready = _ref.ready, view = _ref.view;
render = require('./shared').render;
view.fn('cssProperty', cssProperty = function(style) {
if (style.active) {
return "" + (style.prop || '') + ": " + (style.value || '') + ";";
} else {
return '';
}
});
get('/live-css', function(page, model) {
return model.subscribe('liveCss', function(err, liveCss) {
liveCss.setNull({
styles: [
{
prop: 'color',
value: '#c00',
active: true
}, {
prop: 'font-weight',
value: 'bold',
active: true
}, {
prop: 'font-size',
value: '18px',
active: false
}
],
outputText: 'Edit this text...'
});
model.fn('_hasActiveStyles', 'liveCss.styles', function(styles) {
var style, _i, _len;
for (_i = 0, _len = styles.length; _i < _len; _i++) {
style = styles[_i];
if (style.active) {
return true;
}
}
return false;
});
model.del('_poppedOut');
return render(page, 'liveCss');
});
});
get({
from: '/live-css',
to: '/live-css/popout'
}, {
forward: function(model) {
return model.set('_poppedOut', true);
},
back: function(model) {
return model.del('_poppedOut');
}
});
ready(function(model) {
return app.liveCss = {
addStyle: function() {
return model.push('liveCss.styles', {});
},
deleteStyle: function(e, el) {
return model.at(el).remove();
}
};
});

58
node_modules/derby-examples/sink/lib/app/shared.js generated vendored Normal file
View File

@@ -0,0 +1,58 @@
// Generated by CoffeeScript 1.3.1
var pages;
pages = [
{
name: 'home',
text: 'Home',
url: '/'
}, {
name: 'liveCss',
text: 'Live CSS',
url: '/live-css'
}, {
name: 'tableEditor',
text: 'Table editor',
url: '/table'
}, {
name: 'leaderboard',
text: 'Leaderboard',
url: '/leaderboard'
}, {
name: 'bindingsBench',
text: 'Bindings benchmark',
url: '/bindings-bench'
}, {
name: 'submit',
text: 'Submit form',
url: '/submit'
}, {
name: 'back',
text: 'Back redirect',
url: '/back'
}, {
name: 'error',
text: 'Error test',
url: '/error'
}
];
exports.render = function(page, name, ctx) {
var i, item, _i, _len;
if (ctx == null) {
ctx = {};
}
ctx.currentPage = name;
ctx.pages = [];
for (i = _i = 0, _len = pages.length; _i < _len; i = ++_i) {
item = pages[i];
item = Object.create(item);
ctx.pages[i] = item;
if (item.name === name) {
item.current = true;
ctx.title = item.text;
}
}
item.isLast = true;
return page.render(name, ctx);
};

View File

@@ -0,0 +1,191 @@
// Generated by CoffeeScript 1.3.1
var breakLeft, breakTop, cloneCol, cloneRow, dragStart, dragging, endDragging, finishCol, finishRow, onColMove, onMove, onRowMove, setLeft, setTop, targetIndex;
dragging = null;
onRowMove = onColMove = function() {};
exports.init = function(app, exported, options) {
var addListener;
addListener = app.view.dom.addListener;
addListener(document, 'mousemove', onMove);
addListener(document, 'mouseup', function() {
return endDragging();
});
addListener(window, 'blur', function() {
return endDragging(true);
});
onRowMove = options.onRowMove, onColMove = options.onColMove;
exported.rowDown = function(e) {
return dragStart(e, cloneRow, setTop, breakTop, '.row', finishRow, e.target.parentNode);
};
return exported.colDown = function(e) {
return dragStart(e, cloneCol, setLeft, breakLeft, '.col', finishCol, e.target);
};
};
onMove = function(e) {
var breakFn, children, i, last, loc, parent, ref;
if (!dragging) {
return;
}
parent = dragging.parent, last = dragging.last, breakFn = dragging.breakFn;
loc = dragging.setFn(e);
i = 0;
children = parent.querySelectorAll(dragging.selector);
while (loc > breakFn(i < last ? children[i] : children[i + 1])) {
i++;
}
if (i !== last) {
if (!(ref = children[i < last ? i : i + 1])) {
ref = children[children.length - 1].nextSibling;
}
parent.insertBefore(dragging.clone, ref);
}
return dragging.last = i;
};
endDragging = function(cancel) {
if (!dragging) {
return;
}
dragging.finish(cancel);
document.body.removeChild(dragging.container);
return dragging = null;
};
targetIndex = function(el) {
var child, i, _i, _len, _ref;
_ref = el.parentNode.childNodes;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
child = _ref[i];
if (child === el) {
return i;
}
}
};
dragStart = function(e, cloneFn, setFn, breakFn, selector, finish, el) {
var clone, container, index, nodeOffset, offsetLeft, offsetTop, parent, rect;
if (e.button !== 0) {
return;
}
if (typeof e.preventDefault === "function") {
e.preventDefault();
}
container = document.createElement('table');
container.style.position = 'absolute';
parent = el.parentNode;
rect = el.getBoundingClientRect();
nodeOffset = targetIndex(parent.querySelector(selector));
index = targetIndex(el) - nodeOffset;
clone = cloneFn(container, el, rect, parent, nodeOffset, index);
offsetLeft = rect.left - e.clientX;
offsetTop = rect.top - e.clientY;
dragging = {
el: el,
parent: parent,
clone: clone,
nodeOffset: nodeOffset,
index: index,
last: index,
setFn: setFn,
breakFn: breakFn,
selector: selector,
offsetLeft: offsetLeft,
offsetTop: offsetTop,
finish: finish,
container: container
};
setLeft.call(dragging, e);
setTop.call(dragging, e);
return document.body.appendChild(container);
};
setLeft = function(e) {
var loc;
loc = e.clientX;
this.container.style.left = (loc + window.pageXOffset + this.offsetLeft) + 'px';
return loc;
};
setTop = function(e) {
var loc;
loc = e.clientY;
this.container.style.top = (loc + window.pageYOffset + this.offsetTop) + 'px';
return loc;
};
breakLeft = function(el) {
var rect;
return el && (rect = el.getBoundingClientRect(), rect.width / 2 + rect.left);
};
breakTop = function(el) {
var rect;
return el && (rect = el.getBoundingClientRect(), rect.height / 2 + rect.top);
};
cloneRow = function(container, el, rect, parent) {
var child, clone, spacerHtml, _i, _len, _ref;
spacerHtml = '<tr>';
_ref = el.children;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
spacerHtml += "<td style=width:" + child.offsetWidth + "px;height:0;padding:0>";
}
clone = el.cloneNode(false);
clone.removeAttribute('id');
clone.style.height = rect.height + 'px';
container.innerHTML = clone.innerHTML = spacerHtml;
parent.insertBefore(clone, el);
container.firstChild.appendChild(el);
return clone;
};
cloneCol = function(container, el, rect, parent, nodeOffset, index) {
var clone, cloneRows, i, nodeIndex, row, rows, spacerHtml, _i, _j, _len, _len1;
rows = parent.parentNode.children;
spacerHtml = '';
for (_i = 0, _len = rows.length; _i < _len; _i++) {
row = rows[_i];
spacerHtml += "<tr class=" + row.className + " style=height:" + row.offsetHeight + "px;width:0;padding:0>";
}
container.innerHTML = spacerHtml;
clone = el.cloneNode(false);
clone.removeAttribute('id');
clone.setAttribute('rowspan', rows.length);
clone.style.padding = 0;
clone.style.width = rect.width + 'px';
nodeIndex = index + nodeOffset;
parent.insertBefore(clone, parent.childNodes[nodeIndex + 1]);
cloneRows = container.firstChild.children;
for (i = _j = 0, _len1 = rows.length; _j < _len1; i = ++_j) {
row = rows[i];
cloneRows[i].appendChild(row.childNodes[nodeIndex]);
}
return clone;
};
finishRow = function(cancel) {
this.parent.removeChild(this.clone);
this.parent.insertBefore(dragging.el, this.parent.childNodes[this.index + this.nodeOffset]);
if (!cancel) {
return onRowMove(this.index, this.last);
}
};
finishCol = function(cancel) {
var cloneRows, i, nodeIndex, row, rows, _i, _len;
this.parent.removeChild(this.clone);
rows = this.parent.parentNode.children;
cloneRows = this.container.firstChild.children;
nodeIndex = this.index + this.nodeOffset;
for (i = _i = 0, _len = rows.length; _i < _len; i = ++_i) {
row = rows[i];
row.insertBefore(cloneRows[i].firstChild, row.childNodes[nodeIndex]);
}
if (!cancel) {
return onColMove(this.index, this.last);
}
};

108
node_modules/derby-examples/sink/lib/app/table.js generated vendored Normal file
View File

@@ -0,0 +1,108 @@
// Generated by CoffeeScript 1.3.1
var app, get, ready, render, sortableTable, _ref;
_ref = app = require('./index'), get = _ref.get, ready = _ref.ready;
render = require('./shared').render;
sortableTable = require('./sortableTable');
get('/table', function(page, model) {
return model.subscribe('table', function(err, table) {
table.setNull({
rows: [
{
name: 1,
cells: [{}, {}, {}]
}, {
name: 2,
cells: [{}, {}, {}]
}
],
lastRow: 1,
cols: [
{
name: 'A'
}, {
name: 'B'
}, {
name: 'C'
}
],
lastCol: 2
});
return render(page, 'tableEditor');
});
});
ready(function(model) {
var alpha, cols, rows;
rows = model.at('table.rows');
cols = model.at('table.cols');
app.tableEditor = {
deleteRow: function(e, el) {
return model.at(el).remove();
},
deleteCol: function(e, el) {
var i, row;
i = model.at(el).leaf();
row = rows.get('length');
while (row--) {
rows.remove("" + row + ".cells", i);
}
return cols.remove(i);
},
addRow: function() {
var cells, col, name;
name = model.incr('table.lastRow') + 1;
cells = [];
col = cols.get('length');
while (col--) {
cells.push({});
}
return rows.push({
name: name,
cells: cells
});
},
addCol: function() {
var name, row;
row = rows.get('length');
while (row--) {
rows.push("" + row + ".cells", {});
}
name = alpha(model.incr('table.lastCol'));
return cols.push({
name: name
});
}
};
alpha = function(num, out) {
var mod;
if (out == null) {
out = '';
}
mod = num % 26;
out = String.fromCharCode(65 + mod) + out;
if (num = Math.floor(num / 26)) {
return alpha(num - 1, out);
} else {
return out;
}
};
return sortableTable.init(app, app.tableEditor, {
onRowMove: function(from, to) {
return rows.move(from, to);
},
onColMove: function(from, to) {
var row, _results;
cols.move(from, to);
row = rows.get('length');
_results = [];
while (row--) {
_results.push(rows.move("" + row + ".cells", from, to));
}
return _results;
}
});
});

36
node_modules/derby-examples/sink/lib/server/index.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
// Generated by CoffeeScript 1.3.1
var ONE_YEAR, app, derby, express, expressApp, gzippo, http, path, publicPath, root, server, serverError;
http = require('http');
path = require('path');
express = require('express');
gzippo = require('gzippo');
derby = require('derby');
app = require('../app');
serverError = require('./serverError');
ONE_YEAR = 1000 * 60 * 60 * 24 * 365;
root = path.dirname(path.dirname(__dirname));
publicPath = path.join(root, 'public');
(expressApp = express()).use(express.favicon()).use(gzippo.staticGzip(publicPath, {
maxAge: ONE_YEAR
})).use(express.compress()).use(express.bodyParser()).use(express.methodOverride()).use(app.router()).use(expressApp.router).use(serverError(root));
module.exports = server = http.createServer(expressApp);
expressApp.all('*', function(req) {
throw "404: " + req.url;
});
app.createStore({
listen: server
});

View File

@@ -0,0 +1,27 @@
// Generated by CoffeeScript 1.3.1
var derby, isProduction;
derby = require('derby');
isProduction = derby.util.isProduction;
module.exports = function(root) {
var staticPages;
staticPages = derby.createStatic(root);
return function(err, req, res, next) {
var message, status;
if (err == null) {
return next();
}
console.log(err.stack ? err.stack : err);
message = err.message || err.toString();
status = parseInt(message);
if (status === 404) {
return staticPages.render('404', res, {
url: req.url
}, 404);
} else {
return res.send((400 <= status && status < 600) ? status : 500);
}
};
};