diff options
Diffstat (limited to 'src/g2h/page.py')
| -rw-r--r-- | src/g2h/page.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/g2h/page.py b/src/g2h/page.py new file mode 100644 index 0000000..afe6ac2 --- /dev/null +++ b/src/g2h/page.py @@ -0,0 +1,21 @@ +from jinja2 import Environment, FileSystemLoader +import os + +class Page: + 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) + + 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): + content = self.template.render(self.context()) + os.makedirs(os.path.dirname(self.out_file_path), exist_ok=True) + with open(self.out_file_path, 'w', encoding='utf-8') as f: + f.write(content) |