From c44f9d3cb765962c04777a8e1afb865b4f976c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Tue, 25 Aug 2020 01:09:25 +0200 Subject: [PATCH] Display (View|Tree)/Log/Blame/View raw as nav-tabs The colours are, essentially, inverted in regards to the usual nav-tab styling, since we're embedding them inside a nav-bar --- gitsrht/blueprints/repo.py | 16 +++++++---- gitsrht/templates/blame.html | 25 +--------------- gitsrht/templates/blob.html | 31 +------------------- gitsrht/templates/log.html | 13 ++++++++- gitsrht/templates/tree.html | 8 +----- gitsrht/templates/utils.html | 56 +++++++++++++++++++++++++++++++++++- scss/main.scss | 29 +++++++++++++++++++ 7 files changed, 110 insertions(+), 68 deletions(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index 9008902..a0fa80e 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -198,6 +198,7 @@ def tree(owner, repo, ref, path): abort(404) editorconfig = EditorConfig(git_repo, tree, path) + entry = tree path = path.split("/") for part in path: if part == "": @@ -234,7 +235,7 @@ def tree(owner, repo, ref, path): blob=blob, data=data, commit=orig_commit, highlight_file=_highlight_file, editorconfig=editorconfig, - markdown=md, force_source=force_source) + markdown=md, force_source=force_source, pygit2=pygit2) tree = git_repo.get(entry.id) if not tree: @@ -243,7 +244,8 @@ def tree(owner, repo, ref, path): tree = sorted(tree, key=lambda e: e.name) return render_template("tree.html", view="tree", owner=owner, repo=repo, - ref=ref, commit=commit, tree=tree, path=path) + ref=ref, commit=commit, entry=entry, tree=tree, path=path, + pygit2=pygit2) def resolve_blob(git_repo, ref, path): commit, ref, path = lookup_ref(git_repo, ref, path) @@ -324,7 +326,7 @@ def blame(owner, repo, ref, path): repo=repo, ref=ref, path=path, entry=entry, blob=blob, data=data, blame=blame, commit=orig_commit, highlight_file=_highlight_file, editorconfig=EditorConfig(git_repo, orig_commit.tree, path), - lookup_user=lookup_user()) + lookup_user=lookup_user(), pygit2=pygit2) @repo.route("///archive/.tar.gz") def archive(owner, repo, ref): @@ -401,9 +403,13 @@ def log(owner, repo, ref, path): commits = get_log(git_repo, commit, path) + entry = None + if path and commit.tree and path in commit.tree: + entry = commit.tree[path] + return render_template("log.html", view="log", - owner=owner, repo=repo, ref=ref, path=path, - commits=commits, refs=refs) + owner=owner, repo=repo, ref=ref, path=path.split("/"), + commits=commits, refs=refs, entry=entry, pygit2=pygit2) @repo.route("///log/rss.xml", defaults={"ref": None}) diff --git a/gitsrht/templates/blame.html b/gitsrht/templates/blame.html index 6b2dcb9..c091c22 100755 --- a/gitsrht/templates/blame.html +++ b/gitsrht/templates/blame.html @@ -18,30 +18,7 @@ pre, body {
- {{ utils.breadcrumb(ref, repo, path, path_join) }} - - - {{stat.filemode(entry.filemode)}} - - - - - {{humanize.naturalsize(blob.size, - binary=True).replace("Byte", "byte")}} - - - - - View raw - - - - - Unblame - - + {{ utils.breadcrumb(ref, repo, path, entry, view, path_join, stat, pygit2, humanize) }}
- {{ utils.breadcrumb(ref, repo, path, path_join) }} - - - {{stat.filemode(entry.filemode)}} - - - - - {{humanize.naturalsize(blob.size, - binary=True).replace("Byte", "byte")}} - - - - Log - - - - View raw - - {% if not blob.is_binary %} - - Blame - - {% endif %} + {{ utils.breadcrumb(ref, repo, path, entry, view, path_join, stat, pygit2, humanize) }} {% if commit %}
diff --git a/gitsrht/templates/log.html b/gitsrht/templates/log.html index fa618cf..b78248f 100644 --- a/gitsrht/templates/log.html +++ b/gitsrht/templates/log.html @@ -1,7 +1,7 @@ {% extends "repo.html" %} {% import "utils.html" as utils with context %} {% block title %} -{{repo.owner.canonical_name}}/{{repo.name}}: {{ref}} - {{cfg("sr.ht", "site-name")}} git +{{repo.owner.canonical_name}}/{{repo.name}}: {% if path != [''] %}{{path_join(*path)}} {% endif %}{{ref}} - {{cfg("sr.ht", "site-name")}} git {% endblock %} {% block head %} @@ -21,6 +21,17 @@ {% endblock %} {% block content %} +{% if path != [''] %} +
+
+ + {{ utils.breadcrumb(ref, repo, path, entry, view, path_join, stat, pygit2, humanize) }} + +
+
+
+{% endif %} +
diff --git a/gitsrht/templates/tree.html b/gitsrht/templates/tree.html index 7896895..78df4bf 100644 --- a/gitsrht/templates/tree.html +++ b/gitsrht/templates/tree.html @@ -7,13 +7,7 @@
- {{ utils.breadcrumb(ref, repo, path, path_join) }} - - - Log - + {{ utils.breadcrumb(ref, repo, path, entry, view, path_join, stat, pygit2, humanize) }}
ref: {{ ref }} @@ -14,6 +14,60 @@ path=path_join(*path[:loop.index]))}}" >{{part}}/{% endif %}{% endfor %} + +{% set is_blob = entry and entry.type == pygit2.GIT_OBJ_BLOB %} +{% if entry %} + {# Root tree has no filemode #} + {% set filemode = entry.filemode or stat.S_IFDIR %} + + + {{stat.filemode(filemode)}} + + + + {% if is_blob %} + + + {{humanize.naturalsize(entry.size, + binary=True).replace("Byte", "byte")}} + + + {% endif %} +{% endif %} + +{% set path = path_join(*path) %} +
+ +
{% endmacro %} {% macro commit_event(repo, c, diff --git a/scss/main.scss b/scss/main.scss index c689374..9d6241f 100644 --- a/scss/main.scss +++ b/scss/main.scss @@ -307,6 +307,35 @@ img { } } +.blob-nav { + display: inline-block; + padding-left: 0; + padding-right: 0; + + .nav-item:hover { + background: #fff; + } + + .nav-tabs { + padding-left: 0; + margin-bottom: -3px; + border-bottom: 3px transparent solid; + + .nav-link { + padding: 0 0.5rem; + + &:hover { + color: black; + } + + &.active { + border-bottom: 3px #fff solid; + background: #fff; + } + } + } +} + dl { dd { text-overflow: ellipsis; -- 2.38.4