summaryrefslogtreecommitdiffstats
path: root/g2h/gen.py
diff options
context:
space:
mode:
Diffstat (limited to 'g2h/gen.py')
-rw-r--r--g2h/gen.py49
1 files changed, 0 insertions, 49 deletions
diff --git a/g2h/gen.py b/g2h/gen.py
deleted file mode 100644
index 9591d87..0000000
--- a/g2h/gen.py
+++ /dev/null
@@ -1,49 +0,0 @@
-from jinja2 import Environment, FileSystemLoader
-import os
-
-def ref_names_for_commit(refs, commit_sha):
- ref_names = []
- for ref in refs:
- if ref.commit.hexsha == commit_sha:
- ref_names.append(ref.name)
-
- return ref_names
-
-class Generator:
- def __init__(self, output_dir):
- self.output_dir = output_dir
- template_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'templates'))
- self.templates = Environment(loader=FileSystemLoader(template_dir))
-
- def _render(self, template, context, out_path):
- template = self.templates.get_template(template)
- content = template.render(context)
- out_file = os.path.join(self.output_dir, out_path)
- os.makedirs(os.path.dirname(out_file), exist_ok=True)
- with open(out_file, 'w', encoding='utf-8') as f:
- f.write(content)
-
- def render_log(self, name, commits, branches, tags):
- commits_context = []
- for commit in commits:
- refs = ref_names_for_commit(branches, commit.hexsha) + ref_names_for_commit(tags, commit.hexsha)
- commit_context = {
- 'committed_datetime': commit.committed_datetime,
- 'refs': refs,
- 'summary': commit.summary
- }
- commits_context.append(commit_context)
-
- context = {
- 'commits': commits_context,
- 'title': name + ': Log'
- }
- self._render('log.md', context, 'l.md')
-
- def render_overview(self, name, branches, tags):
- context = {
- 'branches': branches,
- 'tags': tags,
- 'title': name
- }
- self._render('overview.md', context, '_index.md')