trim blocks in templates

This commit is contained in:
Sina Atalay 2023-09-03 19:40:02 +02:00
parent 4f1a9b8808
commit 1070259e5b
2 changed files with 10 additions and 11 deletions

View File

@ -1,6 +1,7 @@
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
from data.content import CurriculumVitae from data.content import CurriculumVitae
# from . import tinytex # https://github.com/praw-dev/praw/blob/master/praw/reddit.py # from . import tinytex # https://github.com/praw-dev/praw/blob/master/praw/reddit.py
# from . import templates, sonra mesela: classic.render() tarzi seyler olabilir # from . import templates, sonra mesela: classic.render() tarzi seyler olabilir
from tinytex.render import render from tinytex.render import render
@ -9,18 +10,19 @@ import os
import json import json
if __name__ == "__main__": if __name__ == "__main__":
workspace = os.path.dirname(os.path.dirname(__file__)) workspace = os.path.dirname(os.path.dirname(__file__))
templateName = "classic" templateName = "classic"
templatePath = os.path.join(workspace, "rendercv", "templates", templateName) templatePath = os.path.join(workspace, "rendercv", "templates", templateName)
environment = Environment(loader=FileSystemLoader(templatePath)) environment = Environment(
loader=FileSystemLoader(templatePath), trim_blocks=True, lstrip_blocks=True
)
environment.block_start_string = "((*" environment.block_start_string = "((*"
environment.block_end_string = "*))" environment.block_end_string = "*))"
environment.variable_start_string = "(((" environment.variable_start_string = "<<"
environment.variable_end_string = ")))" environment.variable_end_string = ">>"
environment.comment_start_string = "((=" environment.comment_start_string = "((#"
environment.comment_end_string = "=))" environment.comment_end_string = "#))"
template = environment.get_template(f"{templateName}.tex.j2") template = environment.get_template(f"{templateName}.tex.j2")
@ -34,11 +36,8 @@ if __name__ == "__main__":
# Create an output file and write the rendered LaTeX code to it: # Create an output file and write the rendered LaTeX code to it:
output_file_path = os.path.join(workspace, "tests", "outputs", "test.tex") output_file_path = os.path.join(workspace, "tests", "outputs", "test.tex")
os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
with open(output_file_path, "w") as file: with open(output_file_path, "w") as file:
file.write(output_latex_file) file.write(output_latex_file)
render(output_file_path) render(output_file_path)

View File

@ -16,7 +16,7 @@ def render(latexFilePath):
[ [
f"{tinytexPath}\\latexmk.exe", f"{tinytexPath}\\latexmk.exe",
"-lualatex", "-lualatex",
"-c", # "-c",
"test.tex", "test.tex",
"-synctex=1", "-synctex=1",
"-interaction=nonstopmode", "-interaction=nonstopmode",