Skip to content

Commit

Permalink
Add latest update time.
Browse files Browse the repository at this point in the history
Partially addresses #9.
  • Loading branch information
tobie committed Nov 23, 2017
1 parent 79441ae commit 2ad1a6d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/views/body.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

var dateFormat = require('dateformat');

const COMMENT_INTRO = `<!--
This comment and the below content is programatically generated.`;
const COMMENT_BODY = ` You may add a comma-separated list of anchors you'd like a
Expand All @@ -24,7 +26,12 @@ class ViewComment {

render(pr) {
let body = pr.body.split(COMMENT_INTRO)[0].trim();
return `${body}\n\n\n${ COMMENT_INTRO }\n${ COMMENT_BODY }\n${ this.getAnchors(pr).join(", ")}\n${ COMMENT_OUTRO }\n***\n${ this.content(pr) }`
return `${body}\n\n\n${ COMMENT_INTRO }\n${ COMMENT_BODY }\n${ this.getAnchors(pr).join(", ") }\n${ COMMENT_OUTRO }\n***\n${ this.content(pr) }`
}

getDate(date) {
date = dateFormat(date, "UTC:mmm d, yyyy, h:MM TT");
return `Last updated on ${ date } GMT`;
}

getAnchors(pr) {
Expand All @@ -39,9 +46,17 @@ class ViewComment {
let anchors = this.getAnchors(pr);
let anchor = anchors.length == 1 ? anchors[0] : "";
let size = Math.floor(40 / anchors.length);
return `[Preview](${ this.preview_url(pr) }${anchor}) ${ this.displayAnchors(this.preview_url(pr), anchors, size) }| [Diff](${ pr.diff.cache_url })`;

let title = this.getDate(new Date());
let preview = this.displayLink("Preview", this.preview_url(pr) + anchor, title);
let diff = this.displayLink("Diff", pr.diff.cache_url, title);
return `${ preview } ${ this.displayAnchors(this.preview_url(pr), anchors, size) }| ${ diff }`;
}

displayLink(content, href, title) {
return `<a href="${ href }" title="${title}">${ content }</a>`;
}

displayAnchors(url, anchors, size) {
if (!anchors || anchors.length < 2) return "";
if (typeof size == "number") {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"aws-sdk": "^2.9.0",
"body-parser": "1.16.1",
"dateformat": "^3.0.2",
"emu-algify": "^2.2.0",
"entities": "1.1.1",
"express": "4.14.0",
Expand Down
9 changes: 9 additions & 0 deletions test/views/body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";
const assert = require("assert"),
BodyView = require("../../lib/views/body");
suite("Body view", function() {
test("Test getDate", function() {
let v = new BodyView();
assert.equal(v.getDate(new Date(0)), "Last updated on Jan 1, 1970, 12:00 AM GMT");
});
});

0 comments on commit 2ad1a6d

Please sign in to comment.