Add ability to include files in velocity
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<!--/cards/svg-->
|
||||
<img class="svg" src="/svg/${escape_html($card.figure)}.svg">
|
||||
<!--<div class="svg" style="background-image:url('/svg/${escape_html($card.figure)}.svg');"></div>-->
|
||||
## #include("${card.figure}.svg") **
|
||||
#end
|
||||
</figure>
|
||||
#if($card.effects)
|
||||
|
||||
Reference in New Issue
Block a user