summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--g2h/cli.py3
-rw-r--r--g2h/commit_page.py4
-rw-r--r--g2h/log_page.py4
-rw-r--r--g2h/overview_page.py4
-rw-r--r--g2h/page.py3
-rw-r--r--g2h/page_factory.py9
-rw-r--r--tests/commit_test.py4
-rw-r--r--tests/log_test.py26
-rw-r--r--tests/overview_test.py2
-rw-r--r--tests/page_test.py8
10 files changed, 35 insertions, 32 deletions
diff --git a/g2h/cli.py b/g2h/cli.py
index 3d7028e..b4c1c2b 100644
--- a/g2h/cli.py
+++ b/g2h/cli.py
@@ -12,6 +12,7 @@ def parse_args():
parser.add_argument('repo_path', help='Path to the root of git repository')
parser.add_argument('out_dir', help='Path to where the generated files should be stored')
parser.add_argument('--name', help='Name of the project. Default: directory name of repo')
+ parser.add_argument('--content-subdir', help='Subdir(s) where the page will be served from. Default: None', default='')
return parser.parse_args()
@@ -25,7 +26,7 @@ def main():
project_name = args.name if args.name is not None else os.path.basename(args.repo_path)
tags = sorted(git.get_tags(), key=lambda t: t.commit.committed_date, reverse=True)
- factory = PageFactory(args.out_dir, project_name)
+ factory = PageFactory(args.out_dir, project_name, args.content_subdir)
factory.new_overview(branches, tags).render()
factory.new_log(commits, branches, tags).render()
for commit in commits:
diff --git a/g2h/commit_page.py b/g2h/commit_page.py
index 325df85..716a4f8 100644
--- a/g2h/commit_page.py
+++ b/g2h/commit_page.py
@@ -3,8 +3,8 @@ import os
from .page import Page
class CommitPage(Page):
- def __init__(self, out_dir, name, commit):
- super(CommitPage, self).__init__('commit.md', out_dir, os.path.join(commit.hexsha, 'index.md'), name)
+ def __init__(self, out_dir, name, commit, content_subdir):
+ super(CommitPage, self).__init__('commit.md', out_dir, os.path.join(commit.hexsha, 'index.md'), name, content_subdir)
self.commit = commit
def context(self):
diff --git a/g2h/log_page.py b/g2h/log_page.py
index 684a758..9a3d64f 100644
--- a/g2h/log_page.py
+++ b/g2h/log_page.py
@@ -13,8 +13,8 @@ def ref_names_for_commit(refs, commit_sha):
return ref_names
class LogPage(Page):
- def __init__(self, out_dir, name, commits, branches, tags):
- super(LogPage, self).__init__('log.md', out_dir, 'l.md', name)
+ def __init__(self, out_dir, name, commits, branches, tags, content_subdir):
+ super(LogPage, self).__init__('log.md', out_dir, 'l.md', name, content_subdir)
self.commits = commits
self.branches = branches
self.tags = tags
diff --git a/g2h/overview_page.py b/g2h/overview_page.py
index 1693b9a..8c7a69c 100644
--- a/g2h/overview_page.py
+++ b/g2h/overview_page.py
@@ -1,8 +1,8 @@
from .page import Page
class OverviewPage(Page):
- def __init__(self, out_dir, name, branches, tags):
- super(OverviewPage, self).__init__('overview.md', out_dir, '_index.md', name)
+ def __init__(self, out_dir, name, branches, tags, content_subdir):
+ super(OverviewPage, self).__init__('overview.md', out_dir, '_index.md', name, content_subdir)
self.branches = branches
self.tags = tags
diff --git a/g2h/page.py b/g2h/page.py
index 44f97ee..a708f2b 100644
--- a/g2h/page.py
+++ b/g2h/page.py
@@ -2,9 +2,10 @@ from jinja2 import Environment, FileSystemLoader
import os
class Page:
- def __init__(self, template_file, out_dir, out_file, name):
+ def __init__(self, template_file, out_dir, out_file, name, content_subdir):
self.out_file_path = os.path.join(out_dir, out_file)
self.name = name
+ self.content_subdir = content_subdir
template_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'templates'))
self.template = Environment(loader=FileSystemLoader(template_dir)).get_template(template_file)
diff --git a/g2h/page_factory.py b/g2h/page_factory.py
index f946e7a..43a48ae 100644
--- a/g2h/page_factory.py
+++ b/g2h/page_factory.py
@@ -3,15 +3,16 @@ from .overview_page import OverviewPage
from .log_page import LogPage
class PageFactory:
- def __init__(self, out_dir, name):
+ def __init__(self, out_dir, name, content_subdir):
self.out_dir = out_dir
self.name = name
+ self.content_subdir = content_subdir
def new_commit(self, commit):
- return CommitPage(self.out_dir, self.name, commit)
+ return CommitPage(self.out_dir, self.name, commit, self.content_subdir)
def new_overview(self, branches, tags):
- return OverviewPage(self.out_dir, self.name, branches, tags)
+ return OverviewPage(self.out_dir, self.name, branches, tags, self.content_subdir)
def new_log(self, commits, branches, tags):
- return LogPage(self.out_dir, self.name, commits, branches, tags)
+ return LogPage(self.out_dir, self.name, commits, branches, tags, self.content_subdir)
diff --git a/tests/commit_test.py b/tests/commit_test.py
index e36f835..1d79f1e 100644
--- a/tests/commit_test.py
+++ b/tests/commit_test.py
@@ -4,7 +4,7 @@ from unittest.mock import MagicMock
def test_init():
commit = MagicMock()
commit.hexsha = '123'
- page = CommitPage('test/commit', 'commit test', commit)
+ page = CommitPage('test/commit', 'commit test', commit, '')
assert(page.name == 'commit test')
assert(page.out_file_path == 'test/commit/123/index.md')
assert(page.template.name == 'commit.md')
@@ -12,7 +12,7 @@ def test_init():
def test_context():
commit = MagicMock()
commit.hexsha = '123'
- page = CommitPage('test/commit', 'commit test', commit)
+ page = CommitPage('test/commit', 'commit test', commit, '')
context = page.context()
assert(context['title'] == 'commit test: 123')
assert(context['commit'] == commit)
diff --git a/tests/log_test.py b/tests/log_test.py
index 1efe3bd..c0619de 100644
--- a/tests/log_test.py
+++ b/tests/log_test.py
@@ -2,13 +2,13 @@ from g2h.log_page import LogPage
from unittest.mock import MagicMock
def test_init():
- page = LogPage('test/log', 'log test', None, None, None)
+ page = LogPage('test/log', 'log test', None, None, None, '')
assert(page.name == 'log test')
assert(page.out_file_path == 'test/log/l.md')
assert(page.template.name == 'log.md')
def test_context_no_commits():
- page = LogPage('test/log', 'log test', None, None, None)
+ page = LogPage('test/log', 'log test', None, None, None, '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [])
@@ -18,7 +18,7 @@ def test_context_no_branches_and_tags():
commit.summary = 'mock commit'
commit.hexsha = 1234;
commit.committed_datetime = 0
- page = LogPage('test/log', 'log test', [commit], None, None)
+ page = LogPage('test/log', 'log test', [commit], None, None, '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
@@ -31,7 +31,7 @@ def test_context_matching_branch_no_tags():
branch = MagicMock()
branch.commit.hexsha = commit.hexsha
branch.name = 'mock branch'
- page = LogPage('test/log', 'log test', [commit], [branch], None)
+ page = LogPage('test/log', 'log test', [commit], [branch], None, '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [{'committed_datetime': 0, 'refs': ['mock branch'], 'summary': 'mock commit'}])
@@ -44,7 +44,7 @@ def test_context_unmatching_branch_no_tags():
branch = MagicMock()
branch.commit.hexsha = 4321
branch.name = 'mock branch'
- page = LogPage('test/log', 'log test', [commit], [branch], None)
+ page = LogPage('test/log', 'log test', [commit], [branch], None, '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
@@ -57,7 +57,7 @@ def test_context_no_branch_matching_tag():
tag = MagicMock()
tag.commit.hexsha = commit.hexsha
tag.name = 'mock tag'
- page = LogPage('test/log', 'log test', [commit], None, [tag])
+ page = LogPage('test/log', 'log test', [commit], None, [tag], '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [{'committed_datetime': 0, 'refs': ['mock tag'], 'summary': 'mock commit'}])
@@ -70,7 +70,7 @@ def test_context_no_branch_no_matching_tag():
tag = MagicMock()
tag.commit.hexsha = 4321
tag.name = 'mock tag'
- page = LogPage('test/log', 'log test', [commit], None, [tag])
+ page = LogPage('test/log', 'log test', [commit], None, [tag], '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
@@ -86,7 +86,7 @@ def test_context_no_matching_branch_no_matching_tag():
tag = MagicMock()
tag.commit.hexsha = 4321
tag.name = 'mock tag'
- page = LogPage('test/log', 'log test', [commit], [branch], [tag])
+ page = LogPage('test/log', 'log test', [commit], [branch], [tag], '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
@@ -102,7 +102,7 @@ def test_context_matching_branch_matching_tag():
tag = MagicMock()
tag.commit.hexsha = commit.hexsha
tag.name = 'mock tag'
- page = LogPage('test/log', 'log test', [commit], [branch], [tag])
+ page = LogPage('test/log', 'log test', [commit], [branch], [tag], '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [{'committed_datetime': 0, 'refs': ['mock branch', 'mock tag'], 'summary': 'mock commit'}])
@@ -116,7 +116,7 @@ def test_multiple_commits():
commit2.summary = 'mock commit 2'
commit2.hexsha = 2;
commit2.committed_datetime = 1
- page = LogPage('test/log', 'log test', [commit1, commit2], None, None)
+ page = LogPage('test/log', 'log test', [commit1, commit2], None, None, '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [
@@ -136,7 +136,7 @@ def test_multiple_commits_branch():
branch = MagicMock()
branch.commit.hexsha = 1
branch.name = 'mock branch'
- page = LogPage('test/log', 'log test', [commit1, commit2], [branch], None)
+ page = LogPage('test/log', 'log test', [commit1, commit2], [branch], None, '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [
@@ -156,7 +156,7 @@ def test_multiple_commits_tag():
tag = MagicMock()
tag.commit.hexsha = 1
tag.name = 'mock tag'
- page = LogPage('test/log', 'log test', [commit1, commit2], None, [tag])
+ page = LogPage('test/log', 'log test', [commit1, commit2], None, [tag], '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [
@@ -179,7 +179,7 @@ def test_multiple_commits_branch_and_tag():
tag = MagicMock()
tag.commit.hexsha = 2
tag.name = 'mock tag'
- page = LogPage('test/log', 'log test', [commit1, commit2], [branch], [tag])
+ page = LogPage('test/log', 'log test', [commit1, commit2], [branch], [tag], '')
context = page.context()
assert(context['title'] == 'log test: Log')
assert(context['commits'] == [
diff --git a/tests/overview_test.py b/tests/overview_test.py
index fa51858..57d2f5d 100644
--- a/tests/overview_test.py
+++ b/tests/overview_test.py
@@ -1,7 +1,7 @@
from g2h.overview_page import OverviewPage
def test_init():
- page = OverviewPage('test/overview', 'overview test', 'test branch', 'test tag')
+ page = OverviewPage('test/overview', 'overview test', 'test branch', 'test tag', '')
context = page.context()
assert(context['title'] == 'overview test')
assert(context['branches'] == 'test branch')
diff --git a/tests/page_test.py b/tests/page_test.py
index 1008a8d..c68e435 100644
--- a/tests/page_test.py
+++ b/tests/page_test.py
@@ -3,17 +3,17 @@ from jinja2.exceptions import TemplateNotFound
import pytest
def test_init():
- page = Page('overview.md', 'dir', 'file', 'name')
+ page = Page('overview.md', 'dir', 'file', 'name', 'sub/dir')
assert(page.name == 'name')
assert(page.out_file_path == 'dir/file')
assert(page.template.name == 'overview.md')
+ assert(page.content_subdir == 'sub/dir')
def test_wrong_template():
with pytest.raises(TemplateNotFound):
- Page('not existant.md', 'dir', 'file', 'name')
+ Page('not existant.md', 'dir', 'file', 'name', '')
def test_no_context():
- page = Page('overview.md', 'dir', 'file', 'name')
+ page = Page('overview.md', 'dir', 'file', 'name', '')
with pytest.raises(NotImplementedError):
page.context()
-