aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-11-05 18:55:44 -0500
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-11-05 22:11:25 -0500
commitf07c034d442bc8a3610e983e0976f24ea839bb92 (patch)
tree24dda7b7c5b30da30f4fed9966c6a4c0ba68033b /lib
parentd6cace514bdf76e8846bfe8838636ac8c4d15b4e (diff)
downloadpatchfoo-f07c034d442bc8a3610e983e0976f24ea839bb92.tar.gz
patchfoo-f07c034d442bc8a3610e983e0976f24ea839bb92.zip
Render bookclub messages and ratings
Diffstat (limited to 'lib')
-rw-r--r--lib/render-msg.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 72ab73b..1fd4d83 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -262,6 +262,7 @@ RenderMsg.prototype.message = function (cb) {
case 'npm-packages': return this.npmPackages(cb)
case 'npm-prebuilds': return this.npmPrebuilds(cb)
case 'acme-challenges-http-01': return this.acmeChallengesHttp01(cb)
+ case 'bookclub': return this.bookclub(cb)
default: return this.object(cb)
}
}
@@ -383,6 +384,8 @@ RenderMsg.prototype.title1 = function (cb) {
cb(null, title(self.c.msg))
else if (self.c.type === 'chess_invite')
self.chessInviteTitle(cb)
+ else if (self.c.type === 'bookclub')
+ self.bookclubTitle(cb)
else
self.app.getAbout(self.msg.key, function (err, about) {
if (err) return cb(err)
@@ -456,6 +459,8 @@ var knownAboutProps = {
startDateTime: true,
endDateTime: true,
location: true,
+ rating: true,
+ ratingType: true,
}
RenderMsg.prototype.about = function (cb) {
@@ -519,12 +524,28 @@ RenderMsg.prototype.about = function (cb) {
src: this.render.imageUrl(img),
alt: ' ',
})) : '',
+ this.c.rating != null ? this.aboutRating() : '',
extras ? this.valueTable(extras, 1, done())
: ''
], elCb)
done(cb)
}
+RenderMsg.prototype.aboutRating = function (cb) {
+ var rating = Number(this.c.rating)
+ var type = this.c.ratingType || '★'
+ var text = rating + ' ' + type
+ if (isNaN(rating)) return 'rating: ' + text
+ if (rating > 5) rating = 5
+ var el = h('div', {title: text})
+ for (var i = 0; i < rating; i++) {
+ el.appendChild(h('span',
+ {innerHTML: unwrapP(this.render.markdown(type) + ' ')}
+ ))
+ }
+ return el
+}
+
RenderMsg.prototype.contact = function (cb) {
var self = this
self.link(self.c.contact, function (err, a) {
@@ -1287,3 +1308,33 @@ RenderMsg.prototype.acmeChallengesHttp01 = function (cb) {
}), ', ', ', and ')
), cb)
}
+
+RenderMsg.prototype.bookclub = function (cb) {
+ var self = this
+ var props = self.c.common || self.c
+ var images = u.toLinkArray(props.image || props.images)
+ self.wrap(h('table', h('tr',
+ h('td',
+ images.map(function (image) {
+ return h('a', {href: self.render.toUrl(image.link)}, h('img', {
+ src: self.render.imageUrl(image.link),
+ alt: image.name || ' ',
+ width: 180,
+ }))
+ })),
+ h('td',
+ h('h4', props.title),
+ props.authors ?
+ h('p', h('em', props.authors))
+ : '',
+ props.description
+ ? h('div', {innerHTML: self.render.markdown(props.description)})
+ : ''
+ )
+ )), cb)
+}
+
+RenderMsg.prototype.bookclubTitle = function (cb) {
+ var props = this.c.common || this.c
+ cb(null, props.title || 'book')
+}