This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
md-pdf/md_pdf/build/templates.py

23 lines
611 B
Python
Raw Normal View History

2017-03-27 09:17:49 +01:00
from jinja2 import Template
2017-04-05 14:44:22 +01:00
from md_pdf.consts import TEMPLATES_DIR
2017-03-28 21:31:42 +01:00
import os
2017-04-01 16:12:03 +01:00
import logging
logger = logging.getLogger(__file__)
2017-03-27 09:17:49 +01:00
2017-03-28 21:31:42 +01:00
2017-04-05 14:44:22 +01:00
COVER_TEMPLATE = os.path.join(TEMPLATES_DIR, 'cover-template.html')
OUTPUT_COVER_FILE = os.path.join(TEMPLATES_DIR, 'cover.html')
2017-03-28 21:31:42 +01:00
2017-03-31 18:12:11 +01:00
def render_cover(config):
2017-04-04 22:04:25 +01:00
logger.debug("Rendering Cover...")
2017-03-31 18:12:11 +01:00
context = config['context'].copy()
context['title'] = config['title']
2017-03-28 21:31:42 +01:00
with open(COVER_TEMPLATE) as f:
2017-03-27 09:17:49 +01:00
template = Template(f.read())
2017-03-28 21:31:42 +01:00
with open(OUTPUT_COVER_FILE, "w") as f:
2017-03-27 09:17:49 +01:00
cover = template.render(context)
f.write(cover)
return cover