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

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

@@ -0,0 +1,163 @@
// Generated by CoffeeScript 1.3.1
var app, fillDimension, get, lastLoad, parseUrl, photoDimension, photoDimensionFn, photoSrc, preCache, ready, view, _ref;
parseUrl = require('url').parse;
_ref = app = require('derby').createApp(module), get = _ref.get, view = _ref.view, ready = _ref.ready;
fillDimension = function(max, side, otherSide) {
if (side >= otherSide) {
return max;
} else {
return side * max / otherSide;
}
};
photoDimension = function(obj, source, size, type) {
var otherSide, side;
if (size == null) {
size = 's';
}
if (source === 'flickr') {
if (type === 'width') {
side = obj.o_width;
otherSide = obj.o_height;
} else {
side = obj.o_height;
otherSide = obj.o_width;
}
if (size === 's') {
return 75;
}
if (size === 'm') {
return fillDimension(240, side, otherSide);
}
}
};
photoDimensionFn = function(type) {
return function(obj, source, size, scale) {
if (scale == null) {
scale = 1;
}
if (!obj) {
return;
}
return Math.round(photoDimension(obj, source, size, type) * scale);
};
};
photoSrc = function(obj, source, size) {
if (size == null) {
size = 's';
}
if (!obj) {
return;
}
if (source === 'flickr') {
return ("http://farm" + obj.farm + ".staticflickr.com/") + ("" + obj.server + "/" + obj.id + "_" + obj.secret + "_" + size + ".jpg");
}
};
view.fn('photoWidth', photoDimensionFn('width'));
view.fn('photoHeight', photoDimensionFn('height'));
view.fn('photoSrc', photoSrc);
preCache = function(obj, source, callback) {
var cancelled, count, finish, img, src, wait;
src = photoSrc(obj, source, 'm');
img = document.createElement('img');
img.style.display = 'none';
img.src = src;
cancelled = false;
callback.cancel = function() {
return cancelled = true;
};
finish = function() {
document.body.removeChild(img);
if (!cancelled) {
return callback();
}
};
count = 2;
wait = function() {
return --count || finish();
};
img.onload = wait;
setTimeout(wait, 50);
return document.body.appendChild(img);
};
get('/:source/:type/:id/:image?', function(page, model, params, next) {
var id, image, pageIndex, query, search, source, type;
source = params.source, type = params.type, id = params.id, image = params.image, query = params.query;
search = parseUrl(params.url).search;
if (source !== 'flickr') {
next();
}
pageIndex = query.page ? query.page - 1 : 0;
return model.fetch("" + source + "." + type + ".id_" + id + ".photos.pages." + pageIndex, function(err, photos) {
model.ref('_pages', photos.parent());
model.ref('_page', '_pages', '_selectedPage');
model.set('_toggle', 0);
model.set('_fade0', 1);
model.set('_fade1', 0);
model.ref('_image0', '_page', '_selected0');
model.ref('_image1', '_page', '_selected1');
model.set('_selectedPage', pageIndex);
model.set('_selected0', image);
return page.render({
source: source,
search: search
});
});
});
lastLoad = null;
get({
from: '/:source/:type/:id/:image?',
to: '/:source/:type/:id/:image?'
}, function(model, params, next) {
var id, image, pageIndex, query, source, type;
source = params.source, type = params.type, id = params.id, image = params.image, query = params.query;
if (source !== 'flickr') {
next();
}
pageIndex = query.page ? query.page - 1 : 0;
model.set('_selectedPage', pageIndex);
if (lastLoad) {
lastLoad.cancel();
}
lastLoad = function() {
var toggleValue;
lastLoad = null;
toggleValue = +(!model.get('_toggle'));
model.set('_toggle', toggleValue);
model.set('_selected' + toggleValue, image);
return model.set('_fade' + toggleValue, 1);
};
return preCache(model.get('_page.' + image), source, lastLoad);
});
ready(function(model) {
app.select = function(e, el) {
var url;
model.set('_fade' + model.get('_toggle'), 0);
url = model.at(el).leaf() + window.location.search;
return view.history.push(url);
};
model.set('_showReconnect', true);
app.connect = function() {
model.set('_showReconnect', false);
setTimeout((function() {
return model.set('_showReconnect', true);
}), 1000);
return model.socket.socket.connect();
};
return app.reload = function() {
return window.location.reload();
};
});

View File

@@ -0,0 +1,100 @@
// Generated by CoffeeScript 1.3.1
var FLICKR_API, Flickr, request;
request = require('request');
FLICKR_API = 'http://api.flickr.com/services/rest/';
exports.setup = function(store, options) {
var flickr;
flickr = new Flickr(options);
store.route('get', 'flickr.user.id_*.photos.pages.*', function(username, page, done) {
return flickr.userPublicPhotos(username, page, done);
});
return store.route('get', 'flickr.photoset.id_*.photos.pages.*', function(id, page, done) {
return flickr.setPhotos(id, page, done);
});
};
Flickr = function(options) {
this.key = options.key;
this.userIds = {};
};
Flickr.prototype = {
get: function(qs, callback) {
qs.format = 'json';
qs.api_key = this.key;
qs.per_page = 20;
qs.extras = 'o_dims';
return request({
url: FLICKR_API,
qs: qs
}, function(err, res, body) {
var data, match;
if (err) {
return callback(err);
}
if (!((match = /jsonFlickrApi\((.*)\)/.exec(body)) && (body = match[1]))) {
return callback(new Erorr('Unknown Flickr response'));
}
data = JSON.parse(body);
if (data.stat !== 'ok') {
return callback(new Error(data.message));
}
return callback(null, data);
});
},
userId: function(username, callback) {
var id, qs,
_this = this;
if (id = this.userIds[username]) {
return callback(null, id);
}
qs = {
method: 'flickr.people.findByUsername',
username: username
};
return this.get(qs, function(err, body) {
if (err) {
return callback(err);
}
id = _this.userIds[username] = body.user.id;
return callback(null, id);
});
},
userPublicPhotos: function(username, page, callback) {
var _this = this;
return this.userId(username, function(err, user_id) {
var qs;
if (err) {
return callback(err);
}
qs = {
method: 'flickr.people.getPublicPhotos',
user_id: user_id,
page: +page + 1
};
return _this.get(qs, function(err, body) {
if (err) {
return callback(err);
}
return callback(null, body.photos.photo, -1);
});
});
},
setPhotos: function(photoset_id, page, callback) {
var qs;
qs = {
method: 'flickr.photosets.getPhotos',
photoset_id: photoset_id,
page: +page + 1
};
return this.get(qs, function(err, body) {
if (err) {
return callback(err);
}
return callback(null, body.photoset.photo, -1);
});
}
};

View File

@@ -0,0 +1,42 @@
// Generated by CoffeeScript 1.3.1
var ONE_YEAR, app, derby, express, expressApp, flickr, gzippo, http, path, publicPath, root, server, serverError, store;
http = require('http');
path = require('path');
express = require('express');
gzippo = require('gzippo');
derby = require('derby');
app = require('../app');
flickr = require('./flickr');
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(app.router()).use(expressApp.router).use(serverError(root));
module.exports = server = http.createServer(expressApp);
expressApp.all('*', function(req) {
throw "404: " + req.url;
});
store = app.createStore({
listen: server
});
flickr.setup(store, {
key: '86958e03c183fcb1b7fddfeb19f3a423'
});

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);
}
};
};