git ssb

10+

Matt McKegg / patchwork



Commit 66eb3aded58d22467d641cb52da1353212e8219a

render git-update messages

Matt McKegg committed on 2/15/2017, 3:05:16 PM
Parent: 95058d6799fcafd88e35f991f8ffb17990ee68d6

Files changed

plugs/message/html/layout/default.jschanged
plugs/message/html/layout/mini.jsadded
plugs/message/html/render/git.jsadded
plugs/message/html/layout/default.jsView
@@ -17,9 +17,9 @@
1717 exports.create = function (api) {
1818 return nest('message.html.layout', layout)
1919
2020 function layout (msg, opts) {
21- if (!(opts.layout === undefined || opts.layout === 'default' || opts.layout === 'mini')) return
21 + if (!(opts.layout === undefined || opts.layout === 'default')) return
2222
2323 var classList = ['Message']
2424 var replyInfo = null
2525
plugs/message/html/layout/mini.jsView
@@ -1,0 +1,33 @@
1 +const h = require('mutant/h')
2 +const nest = require('depnest')
3 +
4 +exports.needs = nest({
5 + 'message.html': {
6 + backlinks: 'first',
7 + author: 'first',
8 + meta: 'map',
9 + timestamp: 'first'
10 + },
11 + 'profile.html.person': 'first'
12 +})
13 +
14 +exports.gives = nest('message.html.layout')
15 +
16 +exports.create = (api) => {
17 + return nest('message.html.layout', mini)
18 +
19 + function mini (msg, opts) {
20 + if (opts.layout !== 'mini') return
21 + return h('div', {
22 + classList: 'Message -mini'
23 + }, [
24 + h('header', [
25 + h('div.mini', [
26 + api.profile.html.person(msg.value.author), ' ',
27 + opts.content
28 + ]),
29 + h('div.meta', {}, api.message.html.timestamp(msg))
30 + ])
31 + ])
32 + }
33 +}
plugs/message/html/render/git.jsView
@@ -1,0 +1,46 @@
1 +var {h, when} = require('mutant')
2 +var nest = require('depnest')
3 +var extend = require('xtend')
4 +
5 +exports.needs = nest({
6 + 'message.html': {
7 + decorate: 'reduce',
8 + layout: 'first',
9 + link: 'first',
10 + markdown: 'first'
11 + }
12 +})
13 +
14 +exports.gives = nest('message.html.render')
15 +
16 +exports.create = function (api) {
17 + return nest('message.html.render', function renderMessage (msg, opts) {
18 + if (msg.value.content.type !== 'git-update') return
19 + var element = api.message.html.layout(msg, extend({
20 + content: messageContent(msg),
21 + layout: 'mini'
22 + }, opts))
23 +
24 + return api.message.html.decorate(element, { msg })
25 + })
26 +
27 + function messageContent (msg) {
28 + var commits = msg.value.content.commits || []
29 + return [
30 + h('a', {href: msg.key, title: commitSummary(commits)}, [
31 + 'pushed',
32 + when(commits, [' ', pluralizeCommits(commits)])
33 + ]),
34 + ' to ',
35 + api.message.html.link(msg.value.content.repo)
36 + ]
37 + }
38 +}
39 +
40 +function pluralizeCommits (commits) {
41 + return when(commits.length === 1, '1 commit', `${commits.length} commits`)
42 +}
43 +
44 +function commitSummary (commits) {
45 + return commits.map(commit => `- ${commit.title}`).join('\n')
46 +}

Built with git-ssb-web