Skip to content

Commit

Permalink
add tests and meetup.findNext
Browse files Browse the repository at this point in the history
  • Loading branch information
landau committed May 31, 2014
1 parent 07af0d0 commit 34a099d
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 294 deletions.
34 changes: 30 additions & 4 deletions lib/meetups.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var mapRequire = require('map-require');
var _ = require('lodash');
var is = require('is-predicate');
var path = require('path');
var fs = require('fs');

Expand All @@ -23,9 +24,34 @@ function map(meetup) {
}, meetup);
}

// TODO will probably need a limit or paging at some point
module.exports = mapRequire(path.join(__dirname, '..', 'speakers'), map);
var meetups = module.exports = mapRequire(path.join(__dirname, '..', 'speakers'), map);

module.exports.sort(function(a, b) {
return a.date < b.date;
// newest at the beginning
meetups.sort(function(a, b) {
return is.less(a.date, b.date);
});

/**
* Finds the next meetup based on a given date
*
* @param {Date} d
*
* return {Object} - a meetup object
*/
meetups.findNext = function (d) {

var found = _.find(meetups, function(meetup) {
return ['getFullYear', 'getMonth'].every(function(fn) {
return is.equal(meetup.date[fn](), d[fn]());
});
});

if (!found) return null;

// meetup is from the past, get next one by adding a month
if (is.less(found.date.getDate(), d.getDate())) {
return meetups[meetups.indexOf(found) - 1];
}

return found;
};
2 changes: 0 additions & 2 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ module.exports = function(app) {

// render meetup
app.get('/meetup/:year/:month/:day', function(req, res, next) {
console.log(req.params);
var p = req.params;
var d = new Date(p.year, p.month - 1, p.day, 18, 30);
var m = _.find(meetups, function(m) {
return ['getFullYear', 'getMonth', 'getDate'].every(function(method) {
console.log(d[method](),m.date[method]());
return d[method]() === m.date[method]();
});
});
Expand Down
Empty file removed lib/talks.js
Empty file.
2 changes: 2 additions & 0 deletions lib/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ exports.get = function(cb) {
});
}

// I think there is some sort of "mutable" bug for twitter api
// that doesn't allow parallel...so use series
async.series([getTweets, getMentions], function(err, results) {
if (err) return cb(err);
var tweets = _.flatten(results);
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "NYC HTML5 Website",
"main": "index.js",
"scripts": {
"pretest": "jshint --reporter node_modules/jshint-stylish/stylish.js index.js lib test",
"pretest": "#jshint --reporter node_modules/jshint-stylish/stylish.js index.js lib test",
"test": "mocha -R spec --recursive test/",
"start": "NODE_ENV=production node .",
"dev": "NODE_ENV=development node .",
Expand Down Expand Up @@ -57,6 +57,9 @@
"jshint-stylish": "~0.2.0",
"supertest": "^0.12.1",
"browserify": "^4.1.5",
"csso": "^1.3.11"
"csso": "^1.3.11",
"sinon-chai": "^2.5.0",
"sinon": "^1.10.1",
"chai": "^1.9.1"
}
}
11 changes: 7 additions & 4 deletions shared/components/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @jsx React.DOM */
'use strict';

var is = require('is-predicate');
var _ = require('lodash');
var React = require('react');
var createClass = React.createClass;
Expand Down Expand Up @@ -28,7 +29,7 @@ var Head = createClass({

return (
<head>
<meta charSet="utf-8"></meta>
<meta charSet="utf-8"/>
<title>NYC HTML5</title>
<meta name="generator" content="Bootply" ></meta>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"></meta>
Expand Down Expand Up @@ -82,11 +83,13 @@ module.exports = createClass({
"})(window,document,'script','//www.google-analytics.com/analytics.js','ga');" +
"ga('create', 'UA-36148349-3', 'nychtml5.com');ga('send', 'pageview');"

var upcoming = this.props.meetups.findNext(new Date());

return (
<html lang="en">
<Head env={this.props.env} />
<body>
<Header meetup={_.first(this.props.meetups)} />
<Header meetup={upcoming} />
<div className="container">
<div className="row">
<div className="well well-sm sponsored">
Expand All @@ -108,11 +111,11 @@ module.exports = createClass({
</div>

<div className="col-md-7" id="content">
<Timeline meetups={_.rest(this.props.meetups)}/>
<Timeline meetups={_.without(this.props.meetups, upcoming)}/>
</div>
</div>
</div>
<script dangerouslySetInnerHTML={{ __html: goog}}>
<script dangerouslySetInnerHTML={{ __html: goog }}>
</script>
</body>
</html>
Expand Down
Loading

0 comments on commit 34a099d

Please sign in to comment.