removed old github example
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent cc84f40 · Browse files · 5 files·+0 added−159 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+0 added−159 removed
- other:+0 added−159 removed
Provenance
- Commit
125421e- Tree
bc6eac7- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
cc84f40
5 files changed+0 added−159 removed
deleted:examples/github/public/style.css-19 removed
12345678910111213141516171819body { padding: 30px 50px; font: 12px/1.4 "Helvetica Neue", Arial, sans-serif;}a { color: #00AAFF; text-decoration: none;}a:hover { text-decoration: underline;}.user { margin: 0 10px; float: left; width: 300px;}table td:nth-child(2) { padding: 0 5px;}No newline at end of filedeleted:examples/github/views/index.jade-14 removed
1-2-extends layout3-4-block content5- each user in users6- .user7- h2= user.name8- p.summary9- | <a href="http://github.com/#{user.name}">#{user.name}</a> has10- | <strong>#{user.repos.length}</strong> repositories 11- | with a total of <strong>#{user.totalWatchers}</strong> watchers.12- table#repos13- for repo in user.repos14- include repodeleted:examples/github/views/layout.jade-8 removed
1-!!!2-html3- head4- title Github Example5- link(rel="stylesheet", href="/style.css")6- body7- #container8- block contentdeleted:examples/github/views/repo.jade-5 removed
1-tr.repo2- td.name3- a(href: repo.homepage || repo.url)= repo.name4- td.watchers5- = repo.watchersdeleted:examples/github/app.js-113 removed
1-2-/**3- * Module dependencies.4- */5-6-var express = require('../../lib/express')7- , http = require('http');8-9-var app = express();10-11-// Expose our views12-13-app.set('views', __dirname + '/views');14-app.set('view engine', 'jade');15-16-/**17- * Request github json api `path`.18- *19- * @param {String} path20- * @param {Function} fn21- * @api public22- */23-24-function request(path, fn){25- var client = http.createClient(80, 'github.com')26- , req = client.request('GET', '/api/v2/json' + path, { Host: 'github.com' });27- req.on('response', function(res){28- res.body = '';29- res.on('data', function(chunk){ res.body += chunk; });30- res.on('end', function(){31- try {32- fn(null, JSON.parse(res.body));33- } catch (err) {34- fn(err);35- }36- });37- });38- req.end();39-}40-41-/**42- * Sort repositories by watchers desc.43- *44- * @param {Array} repos45- * @api public46- */47-48-function sort(repos){49- return repos.sort(function(a, b){50- if (a.watchers == b.watchers) return 0;51- if (a.watchers > b.watchers) return -1;52- if (a.watchers < b.watchers) return 1;53- });54-}55-56-/**57- * Tally up total watchers.58- *59- * @param {Array} repos60- * @return {Number}61- * @api public62- */63-64-function totalWatchers(repos) {65- return repos.reduce(function(sum, repo){66- return sum + repo.watchers;67- }, 0);68-}69-70-/**71- * Default to my user name :)72- */73-74-app.get('/', function(req, res){75- res.redirect('/repos/visionmedia');76-});77-78-/**79- * Display repos.80- */81-82-app.get('/repos/*', function(req, res, next){83- var names = req.params[0].split('/')84- , users = [];85- (function fetchData(name){86- // We have a user name87- if (name) {88- console.log('... fetching \x1b[33m%s\x1b[0m', name);89- request('/repos/show/' + name, function(err, user){90- if (err) {91- next(err)92- } else {93- user.totalWatchers = totalWatchers(user.repositories);94- user.repos = sort(user.repositories);95- user.name = name;96- users.push(user);97- fetchData(names.shift());98- }99- });100- // No more users101- } else {102- console.log('... done');103- res.render('index', { users: users });104- }105- })(names.shift());106-});107-108-// Serve statics from ./public109-app.use(express.static(__dirname + '/public'));110-111-// Listen on port 3000112-app.listen(3000);113-console.log('Express app started on port 3000');