Commit e5f5020f authored by Robin Sonnabend's avatar Robin Sonnabend

Add: local template path and tex-customisation

This enables to generate both AStA-style and FS-style (and in theory
other) protocols.
/close #88
parent 69841be0
......@@ -18,3 +18,4 @@ documents/
test/
*.sql
pg_to_sqlite.sh
local-templates/
......@@ -146,3 +146,17 @@ LATEX_BULLETPOINTS = [
r"\textasteriskcentered",
r"\textperiodcentered"
]
# optional: path to additional jinja-templates
#LATEX_LOCAL_TEMPLATES = "local-templates"
# optional: the template to include at the top of protocol.tex
#LATEX_LOGO_TEMPLATE = "asta-logo.tex"
# optional: custom protocol page geometry
#LATEX_GEOMETRY = "bottom=1.6cm,top=1.6cm,inner=2.5cm,outer=1.0cm,footskip=1.0cm,headsep=0.6cm"
# optional: custom protocol pagestyle
#LATEX_PAGESTYLE = "fancy"
# optional: additional latex packages
#LATEX_ADDITIONAL_PACKAGES = ["[absolute]{textpos}", "{fancyheadings}"]
# optional: include header and footer in asta-style, not just a page number on top
#LATEX_HEADER_FOOTER = True
......@@ -32,6 +32,7 @@ class RenderType(Enum):
latex = 0
wikitext = 1
plaintext = 2
html = 3
def _not_implemented(self, render_type):
return NotImplementedError("The rendertype {} has not been implemented for {}.".format(render_type.name, self.__class__.__name__))
......@@ -175,6 +176,8 @@ class Text:
return self.text
elif render_type == RenderType.plaintext:
return self.text
elif render_type == RenderType.html:
return self.text
else:
raise _not_implemented(self, render_type)
......@@ -235,6 +238,24 @@ class Tag:
return ""
return self.todo.render_wikitext(current_protocol=protocol)
return "'''{}:''' {}".format(self.name.capitalize(), ";".join(self.values))
elif render_type == RenderType.html:
if self.name == "url":
return "<a href=\"{0}\">{0}</a>".format(self.values[0])
elif self.name == "todo":
if not show_private:
return ""
if getattr(self, "todo", None) is not None:
return self.todo.render_html(current_protocol=protocol)
else:
return "<b>Todo:</b> {}".format(";".join(self.values))
elif self.name == "beschluss":
if getattr(self, "decision", None) is not None:
parts = ["<b>Beschluss:</b>", self.decision.content]
if self.decision.category is not None:
parts.append("<i>{}</i>".format(self.decision.category.name))
return " ".join(parts)
else:
return "<b>Beschluss:</b> {}".format(self.values[0])
else:
raise _not_implemented(self, render_type)
......@@ -295,6 +316,11 @@ class Remark(Element):
return "{}: {}".format(self.name, self.value)
elif render_type == RenderType.plaintext:
return "{}: {}".format(RenderType.plaintex)
elif render_type == RenderType.html:
return "<p>{}: {}</p>".format(self.name, self.value)
else:
raise _not_implemented(self, render_type)
def dump(self, level=None):
if level is None:
......@@ -399,6 +425,19 @@ class Fork(Element):
return ""
else:
return content_lines
elif render_type == RenderType.html:
title_line = "<h{depth}>{content}</h{depth}>".format(depth=level+1, content=name_line)
content_parts = []
for child in self.children:
part = child.render(render_type, show_private, level=level+1, protocol=protocol)
if len(part.strip()) == 0:
continue
content_parts.append("<p>{}</p>".format(part))
content_lines = "{}\n\n{}".format(title_line, "\n".join(content_parts))
if self.test_private(self.name) and not show_private:
return ""
else:
return content_lines
else:
raise _not_implemented(self, render_type)
......
......@@ -63,6 +63,12 @@ app.jinja_env.filters["fancy_join"] = fancy_join
app.jinja_env.tests["auth_valid"] = security_manager.check_user
app.jinja_env.tests["needs_date"] = needs_date_test
additional_templates = getattr(config, "LATEX_LOCAL_TEMPLATES", None)
if additional_templates is not None and os.path.isdir(additional_templates):
if additional_templates not in app.jinja_loader.searchpath:
app.jinja_loader.searchpath.append(additional_templates)
import tasks
app.jinja_env.globals.update(check_login=check_login)
......
......@@ -38,6 +38,26 @@ texenv.filters["datify_short"] = date_filter_short
texenv.filters["datetimify"] = datetime_filter
texenv.filters["timify"] = time_filter
texenv.filters["class"] = class_filter
logo_template = getattr(config, "LATEX_LOGO_TEMPLATE", None)
if logo_template is not None:
texenv.globals["logo_template"] = logo_template
latex_geometry = getattr(config, "LATEX_GEOMETRY", "vmargin=1.5cm,hmargin={1.5cm,1.2cm},bindingoffset=8mm")
texenv.globals["latex_geometry"] = latex_geometry
raw_additional_packages = getattr(config, "LATEX_ADDITIONAL_PACKAGES", None)
additional_packages = []
if raw_additional_packages is not None:
for package in raw_additional_packages:
if "{" not in package:
package = "{{{}}}".format(package)
additional_packages.append(package)
print(raw_additional_packages)
print(additional_packages)
texenv.globals["additional_packages"] = additional_packages
latex_pagestyle = getattr(config, "LATEX_PAGESTYLE", None)
if latex_pagestyle is not None:
texenv.globals["latex_pagestyle"] = latex_pagestyle
latex_header_footer = getattr(config, "LATEX_HEADER_FOOTER", False)
texenv.globals["latex_header_footer"] = latex_header_footer
mailenv = app.create_jinja_environment()
mailenv.trim_blocks = True
......@@ -403,11 +423,12 @@ def compile_async(content, protocol_id, show_private=False, use_decision=False,
current = os.getcwd()
protocol_source_filename = "protocol.tex"
protocol_target_filename = "protocol.pdf"
protocol_class_filename = "protokoll2.cls"
log_filename = "protocol.log"
with open(os.path.join(compile_dir, protocol_source_filename), "w") as source_file:
source_file.write(content)
protocol2_class_source = texenv.get_template("protokoll2.cls").render(fonts=config.FONTS, maxdepth=maxdepth, bulletpoints=config.LATEX_BULLETPOINTS)
with open(os.path.join(compile_dir, "protokoll2.cls"), "w") as protocol2_class_file:
protocol2_class_source = texenv.get_template(protocol_class_filename).render(fonts=config.FONTS, maxdepth=maxdepth, bulletpoints=config.LATEX_BULLETPOINTS)
with open(os.path.join(compile_dir, protocol_class_filename), "w") as protocol2_class_file:
protocol2_class_file.write(protocol2_class_source)
os.chdir(compile_dir)
command = [
......@@ -460,6 +481,10 @@ def compile_async(content, protocol_id, show_private=False, use_decision=False,
if os.path.isfile(total_source_filename):
with open(total_source_filename, "r") as source_file:
log += "\n\nSource:\n\n" + add_line_numbers(source_file.read())
total_class_filename = os.path.join(compile_dir, protocol_class_filename)
if os.path.isfile(total_class_filename):
with open(total_class_filename, "r") as class_file:
log += "\n\nClass:\n\n" + add_line_numbers(class_file.read())
error = protocol.create_error("Compiling", "Compiling LaTeX failed", log)
db.session.add(error)
db.session.commit()
......
......@@ -18,6 +18,9 @@
\begin{document}
%\thispagestyle{plain} %ggf kommentarzeichen entfernen
\ENV{if logo_template is defined}
\ENV{include logo_template}
\ENV{endif}
\Titel{
\large Protokoll: \VAR{protocol.protocoltype.name|escape_tex}
\\\normalsize \VAR{protocol.protocoltype.organization|escape_tex}
......
......@@ -18,6 +18,9 @@
\begin{document}
%\thispagestyle{plain} %ggf kommentarzeichen entfernen
\ENV{if logo_template is defined}
\ENV{include logo_template}
\ENV{endif}
\Titel{
\large \ENV{if show_private}Internes \ENV{endif} Protokoll: \VAR{protocol.protocoltype.name|escape_tex}
\\\normalsize \VAR{protocol.protocoltype.organization|escape_tex}
......
......@@ -15,7 +15,7 @@
% so ein paar sachen die wir eh immer brauchen
\RequirePackage[ngerman]{babel}
\RequirePackage[vmargin=1.5cm,hmargin={1.5cm,1.2cm},bindingoffset=8mm]{geometry}
\RequirePackage[\VAR{latex_geometry}]{geometry}
%\RequirePackage{lineno}
\RequirePackage{longtable}
\RequirePackage{framed}
......@@ -27,6 +27,9 @@
\RequirePackage{xcolor}
\RequirePackage[breakable]{tcolorbox}
\RequirePackage{linegoal}
\ENV{for package in additional_packages}
\RequirePackage\VAR{package}
\ENV{endfor}
\setlistdepth{\VAR{maxdepth}}
\renewlist{itemize}{itemize}{\VAR{maxdepth}}
......@@ -88,7 +91,19 @@
% nicht einrücken und benutzerinnendefinierte kopfzeile
\setlength{\parindent}{0cm}
\setlength{\parskip}{1ex}
\pagestyle{myheadings}
\pagestyle{\VAR{latex_pagestyle|default("myheadings")}}
\ENV{if latex_header_footer}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.5pt}
\def\footerprotocoltext{\relax}
\rfoot[]{\rmfamily\small\footerprotocoltext~~|~~\textbf{\thepage}}
\lfoot[\rmfamily\small\textbf{\thepage}~~|~~\footerprotocoltext]{}
\cfoot{}
\chead{}
\lhead[]{}
\rhead[]{}
\ENV{endif}
%\renewcommand*{\rmdefault}{phv}
%\renewcommand*{\sfdefault}{phv}
......@@ -96,9 +111,10 @@
% Titel
\newcommand{\Kopf}[1]{\markboth{#1}{#1}}
\newcommand{\Titel}[2]{
\markboth{#2}{#2}
\markright{#2}
\thispagestyle{plain}
\def\footerprotocoltext{#2}
%\markboth{#2}{#2}
%\markright{#2}
%\thispagestyle{plain}
\begin{center}
\textbf{#1}
\end{center}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment