git ssb

30+

cel / git-ssb-web



Commit 6c8bd780653136766d04f333f337b997621617ab

Merge branch 'pull-hyperscript'

Update pull-hyperscript to 0.0.4
cel committed on 10/23/2016, 11:19:31 PM
Parent: d4cca13f95088bd91dadba50a4709570eb3a6f9f
Parent: 6b20ee6afa7feaa4fb3b956b1ddfd18c164e1a2a

Files changed

.gitignorechanged
lib/repos/index.jschanged
lib/util.jschanged
package.jsonchanged
.gitignoreView
@@ -1,2 +1,2 @@
11 node_modules
2-
2 +npm-debug.log
lib/repos/index.jsView
@@ -1,6 +1,7 @@
11 var url = require('url')
22 var pull = require('pull-stream')
3 +var once = pull.once
34 var cat = require('pull-cat')
45 var paramap = require('pull-paramap')
56 var multicb = require('multicb')
67 var JsDiff = require('diff')
@@ -12,8 +13,9 @@
1213 var forms = require('../forms')
1314 var ssbRef = require('ssb-ref')
1415 var zlib = require('zlib')
1516 var toPull = require('stream-to-pull-stream')
17 +var h = require('pull-hyperscript')
1618
1719 module.exports = function (web) {
1820 return new RepoRoutes(web)
1921 }
@@ -35,25 +37,8 @@
3537 u.readObjectString(obj, cb)
3638 })
3739 }
3840
39-function table(props) {
40- return function (read) {
41- return cat([
42- pull.once('<table' + (props ? ' ' + props : '') + '>'),
43- pull(
44- read,
45- pull.map(function (row) {
46- return row ? '<tr>' + row.map(function (cell, i) {
47- return '<td>' + cell + '</td>'
48- }).join('') + '</tr>' : ''
49- })
50- ),
51- pull.once('</table>')
52- ])
53- }
54-}
55-
5641 function ul(props) {
5742 return function (read) {
5843 return cat([
5944 pull.once('<ul' + (props ? ' ' + props : '') + '>'),
@@ -504,29 +489,44 @@
504489 }).concat(last).join(' / ')
505490 }
506491
507492 function renderRepoTree(req, repo, rev, path) {
493 + var source = repo.readDir(rev,path)
508494 var pathLinks = path.length === 0 ? '' :
509495 ': ' + linkPath([repo.id, 'tree'], [rev].concat(path))
496 +
497 + var location = once('')
498 + if (path.length !== 0) {
499 + var link = linkPath([repo.id, 'tree'], [rev].concat(path))
500 + location = h('div', {class: 'fileLocation'}, `${req._t('Files')}: ${link}`)
501 + }
502 +
510503 return cat([
511- pull.once(pathLinks ? '<div class="fileLocation">' + req._t('Files') + pathLinks + '</div>' : ''),
512- pull(
513- repo.readDir(rev, path),
514- pull.map(function (file) {
515- var type = (file.mode === 040000) ? 'tree' :
516- (file.mode === 0160000) ? 'commit' : 'blob'
517- if (type == 'commit')
518- return [
519- '<span title="' + req._t('gitCommitLink') + '">🖈</span>',
520- '<span title="' + u.escape(file.id) + '">' +
521- u.escape(file.name) + '</span>']
522- var filePath = [repo.id, type, rev].concat(path, file.name)
523- return ['<i>' + (type == 'tree' ? '📁' : '📄') + '</i>',
524- u.link(filePath, file.name)]
525- }),
526- table('class="files w-100"')
527- )
504 + location,
505 + h('table', {class: "files w-100"}, u.sourceMap(source, file =>
506 + h('tr', [
507 + h('td', [
508 + h('i', fileIcon(file))
509 + ]),
510 + h('td', u.link(filePath(file), file.name))
511 + ])
512 + ))
528513 ])
514 +
515 + function fileIcon(file) {
516 + return fileType(file) === 'tree' ? '📁' : '📄'
517 + }
518 +
519 + function filePath(file) {
520 + var type = fileType(file)
521 + return [repo.id, type, rev].concat(path, file.name)
522 + }
523 +
524 + function fileType(file) {
525 + if (file.mode === 040000) return 'tree'
526 + else if (file.mode === 0160000) return 'commit'
527 + else return 'blob'
528 + }
529529 }
530530
531531 /* Repo readme */
532532
@@ -644,42 +644,46 @@
644644 var id = treeIds[0]
645645 var lastI = treeIds.length - 1
646646 var oldTree = treeIds[0]
647647 var changedFiles = []
648 + var source = GitRepo.diffTrees(repos, treeIds, true)
649 +
648650 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 + })),
649685 pull(
650- GitRepo.diffTrees(repos, treeIds, true),
651- pull.map(function (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- return ['<a href="' + fileHref + '">' + filename + '</a>', action]
678- }),
679- table()
680- ),
681- pull(
682686 pull.values(changedFiles),
683687 paramap(function (item, cb) {
684688 var extension = u.getExtension(item.filename)
685689 if (extension in u.imgMimes) {
lib/util.jsView
@@ -40,8 +40,17 @@
4040 })
4141 }
4242 }
4343
44 +u.sourceMap = function sourceMap (source, fn) {
45 + return pull(
46 + source,
47 + pull.filter(Boolean),
48 + pull.map(fn),
49 + pull.flatten()
50 + )
51 +}
52 +
4453 u.escape = function (str) {
4554 return String(str)
4655 .replace(/&/g, '&amp;')
4756 .replace(/</g, '&lt;')
package.jsonView
@@ -13,8 +13,9 @@
1313 "node-polyglot": "^1.0.0",
1414 "pull-cat": "^1.1.8",
1515 "pull-git-pack": "^0.2.0",
1616 "pull-git-repo": "^0.6.0",
17 + "pull-hyperscript": "^0.0.4",
1718 "pull-identify-filetype": "^1.1.0",
1819 "pull-many": "^1.0.6",
1920 "pull-paramap": "^1.1.6",
2021 "pull-stream": "^3.1.0",

Built with git-ssb-web