summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--g2h/page.py2
-rw-r--r--g2h/tree_page.py7
-rw-r--r--templates/tree.md2
-rw-r--r--test_repo/git.tgzbin22304 -> 22304 bytes
-rw-r--r--tests/tree_test.py6
-rw-r--r--workspace.josh6
7 files changed, 15 insertions, 10 deletions
diff --git a/README.md b/README.md
index 582f912..380ab80 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,7 @@ For a full list of options, their defaults and how they're changing the behavior
- [ ] Add button to download tree tarball.
- [x] Tree view.
Show the state of the tree at the current commit.
- - [ ] Folders should be traversable by clicking.
+ - [x] Folders should be traversable by clicking on their name.
- [ ] Clicking on a file should open that file's page.
- [ ] Individual file page.
File content in a codeblock with file extension based language detection.
diff --git a/g2h/page.py b/g2h/page.py
index a708f2b..b829a88 100644
--- a/g2h/page.py
+++ b/g2h/page.py
@@ -10,6 +10,8 @@ class Page:
self.template = Environment(loader=FileSystemLoader(template_dir)).get_template(template_file)
def context(self):
+ # TODO: Probably better to delegate to a method here so name and subdir don't have to be
+ # passed around as much.
raise NotImplementedError("Must override context")
def render(self):
diff --git a/g2h/tree_page.py b/g2h/tree_page.py
index 22e563a..977e981 100644
--- a/g2h/tree_page.py
+++ b/g2h/tree_page.py
@@ -2,9 +2,12 @@ import os
from .page import Page
+def tree_prefix(sha, tree):
+ return os.path.join(sha, 't', tree)
+
class TreePage(Page):
def __init__(self, out_dir, name, commit, sub_tree, repo, content_subdir):
- super(TreePage, self).__init__('tree.md', out_dir, os.path.join(commit.hexsha, 't', sub_tree, 'index.md'), name, content_subdir)
+ super(TreePage, self).__init__('tree.md', out_dir, os.path.join(tree_prefix(commit.hexsha, sub_tree), 'index.md'), name, content_subdir)
self.tree = commit.tree.join(sub_tree) if sub_tree else commit.tree
self.repo = repo
self.commit = commit
@@ -30,7 +33,9 @@ class TreePage(Page):
def context(self):
return {
+ 'content_subdir': self.content_subdir,
'entries': self._get_entries(),
+ 'subdir': '/'.join([self.content_subdir, tree_prefix(self.commit.hexsha, self.tree.path)]),
'title': self.name + ': Tree'
}
diff --git a/templates/tree.md b/templates/tree.md
index 654c9d0..7a891ab 100644
--- a/templates/tree.md
+++ b/templates/tree.md
@@ -4,7 +4,7 @@
| Name | Last modified |
|------|---------------|
{%- for entry in entries %}
-| {{ entry.name }} | {% if entry.modified %} {{ entry.modified.strftime('%Y-%m-%d %H:%M:%S') }} {% endif %} |{% endfor %}
+| [{{ entry.name }}](/{{ subdir }}/{{ entry.name}}) | {% if entry.modified %} {{ entry.modified.strftime('%Y-%m-%d %H:%M:%S') }} {% endif %} |{% endfor %}
{% else %}
No files.
{% endif %}
diff --git a/test_repo/git.tgz b/test_repo/git.tgz
index 3ea5a1a..f15b42a 100644
--- a/test_repo/git.tgz
+++ b/test_repo/git.tgz
Binary files differ
diff --git a/tests/tree_test.py b/tests/tree_test.py
index ebad5e5..e7d23a8 100644
--- a/tests/tree_test.py
+++ b/tests/tree_test.py
@@ -43,12 +43,15 @@ def add_node(parent, path):
def test_context_empty():
commit = MagicMock()
commit.hexsha = '123'
+ commit.tree.path = 'tree/path'
page = TreePage('test/tree', 'tree test', commit, '', None, '')
context = page.context()
assert(context['entries'] == [])
+ assert(context['content_subdir'] == '')
+ assert(context['subdir'] == '/123/t/tree/path')
assert(context['title'] == 'tree test: Tree')
-def test_context_filled():
+def test_context_entries():
tree = MagicMock()
tree.trees = []
tree.blobs = []
@@ -65,7 +68,6 @@ def test_context_filled():
page = TreePage('test/tree', 'tree test', commit, '', repo, '')
context = page.context()
assert(repo.iter_commits.called)
- assert(context['title'] == 'tree test: Tree')
assert(context['entries'] == [{'name': 'sub/', 'modified': 'Date Time'}, {'name': 'README', 'modified': 'Date Time'}])
def test_traversal():
diff --git a/workspace.josh b/workspace.josh
index eadbf5b..ee245b8 100644
--- a/workspace.josh
+++ b/workspace.josh
@@ -1,6 +1,2 @@
-:[
- :/licenses/2025-BSD-3:[
- ::LICENSE
- ]
-]
+:/licenses/2025-BSD-3::LICENSE
.mise-tasks = :/mise/git