Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

comments are starting to work

  • Loading branch information...
commit 3deee46160dd71d153d9fad049b89366a56cbb54 1 parent 5322835
@pgte pgte authored
View
9 public/assets/discussions/discussion.html
@@ -0,0 +1,9 @@
+<article class="discussion" data-url="">
+ <img src="" class="avatar" />
+ <h3 class="title"></h3>
+ <p class="body"></p>
+ <div class="meta">
+ Posted at <span class="created value"></span>,
+ <a href="">Reply</a>
+ </div>
+</article>
View
15 public/assets/discussions/index.html
@@ -0,0 +1,15 @@
+<form action="" method="POST">
+ <fieldset>
+ <legend>Start a new discussion:</legend>
+ <p>
+ <input placeholder="title" type="text" id="discussiontitle" name="title" />
+ </p>
+ <p>
+ <textarea placeholder="GitHub-flavored Markdown" name="body"></textarea>
+ <input class="submit" type="submit" />
+ </p>
+ </fieldset>
+</form>
+
+<div class="discussionlist">
+</div>
View
2  public/assets/pages/article.html
@@ -38,6 +38,6 @@
<section id="discuss" class="container">
<h3>Discuss:</h3>
- TBD
+ <div id="discussions" />
</section>
</div>
View
50 public/css/index.css
@@ -3303,4 +3303,54 @@ body {
#menu li,
#menu li a {
white-space: nowrap;
+}
+
+/**** Discussions *****/
+
+#discussions {
+ padding: 2em;
+}
+#discussions fieldset legend {
+ padding-left: 0;
+}
+#discussions form input[type=text],
+#discussions form textarea {
+ width: 400px;
+}
+#discussions form textarea {
+ height: 50px;
+}
+#discussions form label {
+ width: 100px;
+ padding-right: 2em;
+}
+#discussions form input.submit {
+ vertical-align: bottom;
+}
+
+#discussions .discussionlist {
+ border-top: 1px solid #ddd;
+}
+
+#discussions article .avatar {
+ float: left;
+ margin: 1em;
+}
+#discussions article:before {
+ display: table;
+ content: "";
+ zoom: 1;
+}
+#discussions article:after {
+ clear: both;
+}
+
+#discussions article .body {
+ margin: 1em;
+}
+
+#discussions article .meta {
+ font-size: 10px;
+ text-align: left;
+ color: #222;
}
View
45 server/assets.js
@@ -55,7 +55,8 @@ module.exports = function(conf) {
"contributorlist": assets['article_contributors.html'].compose(repo),
"articleCategories": articleCategories,
"tags": assets['tags.html'].compose(repo.meta.tags),
- "suggestions": suggestionMarkup
+ "suggestions": suggestionMarkup,
+ "discussions": assets['discussions/index.html'].compose(repo.discussions)
};
var title = repo.meta.title || repo.github.title;
var nav = assets['nav/article.html'].compose(repo.github.name);
@@ -416,5 +417,47 @@ module.exports = function(conf) {
}
};
+ /*******************
+ * Discussions
+ *******************/
+
+ assets['discussions/index.html'] = {
+ raw: fs.readFileSync('./public/assets/discussions/index.html', 'utf8'),
+ compose: function(discussions) {
+ var discussions = discussions.map(function(discussion) {
+ return assets['discussions/discussion.html'].compose(discussion);
+ }).join('');
+
+ var map = new Plates.Map();
+ map.class('discussionlist').use('discussionlist');
+
+ var data = {
+ discussionlist: discussions
+ };
+
+ return Plates.bind(this.raw, data);
+ }
+ };
+
+ assets['discussions/discussion.html'] = {
+ raw: fs.readFileSync('./public/assets/discussions/discussion.html', 'utf8'),
+ compose: function(discussion) {
+ var map = new Plates.Map();
+ map.class('title').use('title');
+ map.class('body').use('body');
+ map.class('avatar').use('avatar').as('src');
+ map.class('created').use('created')
+
+ var data = {
+ title: discussion.title,
+ body: discussion.body || "Lorem Ipsum",
+ avatar: discussion.user && discussion.user.avatar_url,
+ created: discussion.created_at
+ }
+
+ return Plates.bind(this.raw, data, map);
+ }
+ }
+
return assets;
};
View
26 server/comments.js
@@ -0,0 +1,26 @@
+var Github = require('./github');
+
+module.exports = function(conf) {
+ var issues = Github(conf).issues;
+
+ function get(repo, callback) {
+ issues.get(repo, callback);
+ }
+
+ function create(repo) {
+ console.log(this.req);
+ this.res.end();
+ return;
+ issues.create(repo, title, body, callback);
+ }
+
+ function reply(repo, issue, body, callback) {
+ issues(issue).comments.create.call(this, body, callback)
+ }
+
+ return {
+ get: get,
+ create: create,
+ reply: reply
+ }
+}
View
27 server/content.js
@@ -11,11 +11,12 @@ var fs = require('fs'),
zlib = require('zlib'),
tar = require('tar'),
marked = require('github-flavored-markdown').parse,
- hl = require("highlight").Highlight,
+ hl = require('highlight').Highlight,
request = require('request'),
Plates = require('plates'),
difficulty = require('./difficulty'),
- Suggest = require('./suggest');
+ Suggest = require('./suggest'),
+ Comments = require('./comments');
var dir = __dirname + '/tmp';
@@ -144,8 +145,7 @@ Content.prototype.downloadReposGithubInfo = function (callback) {
that.repos[repo.name].github = repo;
});
- callback();
-
+ that.downloadComments(callback);
});
}
@@ -220,6 +220,25 @@ Content.prototype.download = function (repo, callback) {
});
};
+Content.prototype.downloadComments = function(callback) {
+ var that = this,
+ comments = Comments(this.conf);
+
+ async.forEach(Object.keys(this.repos), function(repoName, next) {
+ var repo = that.repos[repoName];
+
+ if (! repo.github) { return next(); }
+
+ comments.get(repo, function(err, comments) {
+ if (err) { return next(err); }
+ console.log(comments);
+ that.repos[repoName].discussions = comments;
+ next();
+ });
+
+ }, callback);
+};
+
//
// function loadRepos(callback)
View
82 server/github.js
@@ -97,7 +97,21 @@ function Github(conf) {
throw new Error('Reply to github fork was status code:' + response.statusCode);
}
- var url = githubRepoActionURL([ 'repos', conf.orgname, repo.github.name]);
+ var b = bubble(function(err) {
+ if (err) {
+ console.error(err);
+ that.res.writeHead(500);
+ that.res.end(err.message);
+ } else {
+ that.res.writeHead(201);
+ var resp = {
+ forks: repo.github.forks,
+ url: 'https://github.com/' + escape(that.req.session.user.login) + '/' + escape(repo.github.name)
+ };
+ that.res.end(JSON.stringify(resp));
+ }
+ });
+
request.get(url, b(function(resp, body) {
if (response.statusCode < 200 || response.statusCode >= 300) {
@@ -113,9 +127,73 @@ function Github(conf) {
}
+ /******************
+ * Issues
+ ******************/
+
+ var issues = (function() {
+
+ function get(repo, callback) {
+ request.get(githubRepoActionURL([ 'repos', conf.orgname, repo.github.name, 'issues']), function(err, resp, body) {
+ if (err) { return callback(err); }
+ try { body = JSON.parse(body); }
+ catch(error) { err = error; }
+ callback(err, body);
+ });
+ }
+
+ function create(repo, title, body, callback) {
+ var options = {
+ uri: githubRepoActionURL(['repos', conf.orgname, repo.github.name, 'issues'], this.req.session),
+ qs: {
+ title: title,
+ body: body
+ }
+ };
+
+ request.post(options, function(err, resp, body) {
+ if (err) { return callback(err); }
+ if (resp.statusCode !== 201) {
+ err = new Error('Github issue create returned status code ' + resp.statusCode);
+ }
+ callback(err);
+ });
+ }
+
+ function issues(issue) {
+
+ function createComment(body, callback) {
+ var url = githubRepoActionURL([ 'repos',
+ conf.orgname,
+ repo.github.name,
+ 'issues',
+ issue,
+ 'comments'],
+ this.req.session);
+
+ request.post(url, function(err, resp, body) {
+ if (err) { return callback(err); }
+ if (res.statusCode !== 201) { err = new Error('Error creating comment on github. status code: ' + resp.statusCode); }
+ callback(err);
+ });
+ }
+
+ return {
+ comments: {
+ create: createComment
+ }
+ }
+ };
+
+ issues.get = get;
+ issues.create = create;
+ return issues;
+ })();
+
return {
like: like,
- fork: fork
+ fork: fork,
+ issues: issues
}
}
View
31 server/server.js
@@ -22,6 +22,16 @@ server.createServer = function(content, conf) {
var github = Github(conf);
+ function findRepo(name) {
+ var repo = content.getRepo(name);
+ if (! repo) {
+ this.res.setHeader(404);
+ this.res.end('Not Found');
+ return false
+ }
+ return repo
+ }
+
//
// define a routing table that will contain methods
// for transforming static content or invoking services.
@@ -41,24 +51,25 @@ server.createServer = function(content, conf) {
},
'/article/:name/like': {
post: function(name) {
- var repo = content.getRepo(name);
- if (! repo) {
- this.res.setHeader(404);
- return this.res.end('Not Found');
- }
+ var repo = findRepo.call(this, name);
+ if (! repo) { return; }
github.like.call(this, repo);
}
},
'/article/:name/fork': {
post: function(name) {
- var repo = content.getRepo(name);
- if (! repo) {
- this.res.setHeader(404);
- return this.res.end('Not Found');
- }
+ var repo = findRepo.call(this, name);
+ if (! repo) { return; }
github.fork.call(this, repo);
}
},
+ '/article/:name/comment': {
+ post: function(name) {
+ var repo = findRepo.call(this, name);
+ if (! repo) { return; }
+ comments.create.call(this, repo);
+ }
+ },
'/article/:name': {
get: function(name) {
this.res.writeHead(200, { 'Content-Type': 'text/html' });
Please sign in to comment.
Something went wrong with that request. Please try again.