From 94d233988ee846b3e5a63f05476640c8341620eb Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Fri, 10 Nov 2017 22:15:52 +0100 Subject: [PATCH] Add ability to include files in velocity --- common.py | 29 +++++++++++++++++++++++++---- resources/cards/card.css | 21 ++++++++++++++++++--- resources/cards/card.vm | 1 + 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/common.py b/common.py index 2e0e043..267bb80 100644 --- a/common.py +++ b/common.py @@ -48,6 +48,24 @@ class Model: ", ".join(f"{i}={getattr(self, i)!r}" for i in dir(self) if "_" not in i) __str__ = __repr__ +class VelocityFileLoader: + _cache = {}#static cache, shared between instances + def get_file(self, filename): + file = readfile(filename) + if filename[-4:] == ".svg": + pass#file = file.replace("fill:#", "")#a nasty hack + return file + def load_text(self, name): + if name[-4:] == ".svg": + filename = os.path.join(config.svgdir, name) + else: + filename = os.path.join(config.resourcedir, name) + if config.cache: + if filename not in self.memory: + self._cache[filename] = self.get_file(filename) + return self._cache[filename] + return self.get_file(filename) + #decorators with parameters: def withResource(path, binary=False): if config.cache: @@ -68,13 +86,14 @@ def withResource(path, binary=False): return decorator def withTemplate(path, isHTML=True): + filename = os.path.join(config.resourcedir, path) if config.cache: - template = airspeed.Template(readfile(os.path.join(config.resourcedir, path))) + template = airspeed.Template(readfile(filename), filename) def decorator(func): def newfunc(*args, **kwargs): if not config.cache: - t = airspeed.Template(readfile(os.path.join(config.resourcedir, path))) + t = airspeed.Template(readfile(filename), filename) else: t = template @@ -82,9 +101,11 @@ def withTemplate(path, isHTML=True): def merge(self, objects): objects.update({"escape_html":escape_html, "escape_url":escape_url}) if config.prettifyHTML and isHTML: - return HTMLBeautifier.beautify(t.merge(objects), indent=4)#.replace("/>", ">") + return HTMLBeautifier.beautify( + t.merge(objects, loader=VelocityFileLoader()), + indent=4)#.replace("/>", ">") else: - return t.merge(objects) + return t.merge(objects, loader=VelocityFileLoader()) if "template" in kwargs: kwargs["template"][os.path.basename(path)] = T() diff --git a/resources/cards/card.css b/resources/cards/card.css index 9a877a8..526d191 100644 --- a/resources/cards/card.css +++ b/resources/cards/card.css @@ -9,7 +9,8 @@ body { width: 21cm; height: 29.7cm; - margin: 1.2cm; + margin-top: 1.2cm; + margin-left: 1.2cm; } /*manual alignment ftw*/ @@ -94,7 +95,10 @@ article figure img{ margin: auto auto; } article figure img.svg{ - filter: brightness(0) invert(1) opacity(0.6); + filter: + brightness(0) + invert(1) + opacity(0.5); } article figure div.svg { display: block; @@ -103,7 +107,18 @@ article figure div.svg { background-size: contain; background-repeat: no-repeat; background-position: center; - filter: brightness(0) invert(1) opacity(0.6); + filter: + brightness(0) + invert(1) + opacity(0.5); + +} +article figure >svg { + height: 97%; + fill: #999; +} +article figure >svg * { + fill: #999; } article figure .mdi, article figure .fa, diff --git a/resources/cards/card.vm b/resources/cards/card.vm index 6ddd20b..8b6e428 100644 --- a/resources/cards/card.vm +++ b/resources/cards/card.vm @@ -25,6 +25,7 @@ + ## #include("${card.figure}.svg") ** #end #if($card.effects)