git ssb

30+

cel / git-ssb-web



Commit 11e0aa57cadc394299cefe87ac30f6cdbddc63ee

add new pull-hyperscript diffTable implementation

mix irving committed on 10/22/2016, 3:25:18 AM
Parent: 4b685a1454e2107ae586ba5cb063bffc4b3a9771

Files changed

lib/repos/index.jschanged
lib/util.jschanged
lib/repos/index.jsView
@@ -1,9 +1,8 @@
11 var url = require('url')
22 var pull = require('pull-stream')
33 var once = pull.once
44 var cat = require('pull-cat')
5-var catMap = require('pull-cat-map')
65 var paramap = require('pull-paramap')
76 var multicb = require('multicb')
87 var JsDiff = require('diff')
98 var GitRepo = require('pull-git-repo')
@@ -14,9 +13,9 @@
1413 var forms = require('../forms')
1514 var ssbRef = require('ssb-ref')
1615 var zlib = require('zlib')
1716 var toPull = require('stream-to-pull-stream')
18-var h = require('pull-hyperscript') // NB currently only on git-ssb
17 +var h = require('pull-hyperscript')
1918
2019 module.exports = function (web) {
2120 return new RepoRoutes(web)
2221 }
@@ -502,9 +501,9 @@
502501 }
503502
504503 return cat([
505504 location,
506- h('table', {class: "files w-100"}, sourceMap(source, file =>
505 + h('table', {class: "files w-100"}, u.sourceMap(source, file =>
507506 h('tr', [
508507 h('td', [
509508 h('i', fileIcon(file))
510509 ]),
@@ -512,16 +511,8 @@
512511 ])
513512 ))
514513 ])
515514
516- function sourceMap (source, fn) {
517- return pull(
518- source,
519- pull.filter(Boolean),
520- catMap(fn)
521- )
522- }
523-
524515 function fileIcon(file) {
525516 return fileType(file) === 'tree' ? '📁' : '📄'
526517 }
527518
@@ -653,42 +644,46 @@
653644 var id = treeIds[0]
654645 var lastI = treeIds.length - 1
655646 var oldTree = treeIds[0]
656647 var changedFiles = []
648 + var source = GitRepo.diffTrees(repos, treeIds, true)
649 +
657650 return cat([
651 + h('table', u.sourceMap(source, item => {
652 + var filename = u.escape(item.filename = item.path.join('/'))
653 + var oldId = item.id && item.id[0]
654 + var newId = item.id && item.id[lastI]
655 + var oldMode = item.mode && item.mode[0]
656 + var newMode = item.mode && item.mode[lastI]
657 + var action =
658 + !oldId && newId ? req._t('action.added') :
659 + oldId && !newId ? req._t('action.deleted') :
660 + oldMode != newMode ? req._t('action.changedMode', {
661 + old: oldMode.toString(8),
662 + new: newMode.toString(8)
663 + }) : req._t('changed')
664 + if (item.id)
665 + changedFiles.push(item)
666 + var blobsPath = item.id[1]
667 + ? [repos[1].id, 'blob', treeIds[1]]
668 + : [repos[0].id, 'blob', treeIds[0]]
669 + var rawsPath = item.id[1]
670 + ? [repos[1].id, 'raw', treeIds[1]]
671 + : [repos[0].id, 'raw', treeIds[0]]
672 + item.blobPath = blobsPath.concat(item.path)
673 + item.rawPath = rawsPath.concat(item.path)
674 + var fileHref = item.id ?
675 + '#' + encodeURIComponent(item.path.join('/')) :
676 + u.encodeLink(item.blobPath)
677 +
678 + return h('tr', [
679 + h('td', [
680 + h('a', {href: fileHref}, filename)
681 + ]),
682 + h('td', action)
683 + ])
684 + })),
658685 pull(
659- GitRepo.diffTrees(repos, treeIds, true),
660- pull.map(function (item) {
661- var filename = u.escape(item.filename = item.path.join('/'))
662- var oldId = item.id && item.id[0]
663- var newId = item.id && item.id[lastI]
664- var oldMode = item.mode && item.mode[0]
665- var newMode = item.mode && item.mode[lastI]
666- var action =
667- !oldId && newId ? req._t('action.added') :
668- oldId && !newId ? req._t('action.deleted') :
669- oldMode != newMode ? req._t('action.changedMode', {
670- old: oldMode.toString(8),
671- new: newMode.toString(8)
672- }) : req._t('changed')
673- if (item.id)
674- changedFiles.push(item)
675- var blobsPath = item.id[1]
676- ? [repos[1].id, 'blob', treeIds[1]]
677- : [repos[0].id, 'blob', treeIds[0]]
678- var rawsPath = item.id[1]
679- ? [repos[1].id, 'raw', treeIds[1]]
680- : [repos[0].id, 'raw', treeIds[0]]
681- item.blobPath = blobsPath.concat(item.path)
682- item.rawPath = rawsPath.concat(item.path)
683- var fileHref = item.id ?
684- '#' + encodeURIComponent(item.path.join('/')) :
685- u.encodeLink(item.blobPath)
686- return ['<a href="' + fileHref + '">' + filename + '</a>', action]
687- }),
688- table()
689- ),
690- pull(
691686 pull.values(changedFiles),
692687 paramap(function (item, cb) {
693688 var extension = u.getExtension(item.filename)
694689 if (extension in u.imgMimes) {
lib/util.jsView
@@ -1,5 +1,6 @@
11 var pull = require('pull-stream')
2 +var catMap = require('pull-cat-map')
23 var Highlight = require('highlight.js')
34 var u = exports
45
56 u.imgMimes = {
@@ -38,8 +39,16 @@
3839 })
3940 }
4041 }
4142
43 +u.sourceMap = function sourceMap (source, fn) {
44 + return pull(
45 + source,
46 + pull.filter(Boolean),
47 + catMap(fn)
48 + )
49 +}
50 +
4251 u.escape = function (str) {
4352 return String(str)
4453 .replace(/&/g, '&amp;')
4554 .replace(/</g, '&lt;')

Built with git-ssb-web