From 4191ec0449d314b7fa73374012194f22e3b85a2f Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 7 Apr 2017 19:43:51 -0700 Subject: Fully render generic messages --- lib/render-msg.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/render-msg.js b/lib/render-msg.js index 9aee35c..6bc2c52 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -302,9 +302,13 @@ RenderMsg.prototype.title = function (cb) { } else if (self.c.type === 'git-repo') { self.getAboutName(self.msg.key, cb) } else { - self.message(false, function (err, el) { + self.getAboutName(self.msg.key, function (err, name) { if (err) return cb(err) - cb(null, title(h('div', el).textContent)) + if (name) return cb(null, name) + self.message(false, function (err, el) { + if (err) return cb(err) + cb(null, '%' + title(h('div', el).textContent)) + }) }) } } @@ -466,7 +470,54 @@ RenderMsg.prototype.issueEdit = function (cb) { } RenderMsg.prototype.object = function (cb) { - this.wrapMini(h('pre', this.c.type), cb) + this.wrap(h('pre', this.linkify(JSON.stringify(this.c, 0, 2))), cb) +} + +RenderMsg.prototype.object = function (cb) { + var done = multicb({pluck: 1, spread: true}) + var elCb = done() + this.wrap([ + this.valueTable(this.c, done()), + ], elCb) + done(cb) +} + +RenderMsg.prototype.valueTable = function (val, cb) { + var self = this + switch (typeof val) { + case 'object': + if (val === null) return cb(), '' + var done = multicb({pluck: 1, spread: true}) + var el = Array.isArray(val) + ? h('ul', val.map(function (item) { + return h('li', self.valueTable(item, done())) + })) + : h('table.ssb-object', Object.keys(val).map(function (key) { + if (key === 'text') { + return h('tr', + h('td', h('strong', 'text')), + h('td', h('div', { + innerHTML: self.render.markdown(val.text, val.mentions) + })) + ) + } + return h('tr', + h('td', h('strong', key)), + h('td', self.valueTable(val[key], done())) + ) + })) + done(cb) + return el + case 'string': + if (u.isRef(val)) return self.link1(val, cb) + return cb(), self.linkify(val) + case 'boolean': + return cb(), h('input', { + type: 'checkbox', disabled: 'disabled', checked: val + }) + default: + return cb(), String(val) + } } RenderMsg.prototype.missing = function (cb) { -- cgit v1.2.3