jinja templating

This commit is contained in:
Yury Ignatev 2020-11-01 18:14:57 +07:00
parent 4997a49eb7
commit 1e305b3c4c
No known key found for this signature in database
GPG Key ID: 32C88B36FBCA9635
2 changed files with 14 additions and 1 deletions

2
.gitignore vendored
View File

@ -7,3 +7,5 @@ build/*
.coverage .coverage
.vscode/* .vscode/*
__pycache__/* __pycache__/*
.idea
venv

View File

@ -7,6 +7,13 @@ import re
from . import util from . import util
from .settings import CACHE_DIR, CONF_DIR, MODULE_DIR from .settings import CACHE_DIR, CONF_DIR, MODULE_DIR
from jinja2 import Template
def template_jinja(colors, input_file, output_file=None):
data = util.read_file_raw(input_file)
t = Template("".join(data))
util.save_file(t.render(**colors), output_file.replace(".jinja", ""))
def template(colors, input_file, output_file=None): def template(colors, input_file, output_file=None):
@ -123,7 +130,11 @@ def every(colors, output_dir=CACHE_DIR):
join = os.path.join # Minor optimization. join = os.path.join # Minor optimization.
for file in [*os.scandir(template_dir), for file in [*os.scandir(template_dir),
*os.scandir(template_dir_user)]: *os.scandir(template_dir_user)]:
if file.name != ".DS_Store" and not file.name.endswith(".swp"): if file.name == ".DS_Store" or file.name.endswith(".swp"):
continue
if file.name.endswith(".jinja"):
template_jinja(colors, file.path, join(output_dir, file.name))
else:
template(colors, file.path, join(output_dir, file.name)) template(colors, file.path, join(output_dir, file.name))
logging.info("Exported all files.") logging.info("Exported all files.")