diff --git a/common.py b/common.py index 267bb80..012c03c 100644 --- a/common.py +++ b/common.py @@ -38,6 +38,9 @@ def listify_output(func):#decorator return list(func(*args, **kwargs)) return new_func +def call(func):#decorator + return func() + class Model: def __setattr__(self, name, value): if not hasattr(self, name): diff --git a/server.py b/server.py index 9659096..db558c0 100755 --- a/server.py +++ b/server.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys, os, airspeed, glob from sanic import Sanic, response -from common import withTemplate, withResource +from common import withTemplate, withResource, call import card import svg import config @@ -142,18 +142,20 @@ async def svg_add(request, template={}): return response.html(template["svg.vm"].merge(locals())) #add static resources: -for i in glob.iglob(os.path.join(config.resourcedir, "**","*"), recursive=True): - filetype = i.split('.')[-1] - if filetype in ("html", "css", "js"): - i = os.path.relpath(i, config.resourcedir) - print("Adding static resource", repr(i)) - if filetype == "js": filetype = "javascript" - - @app.get(f"/{i}") - @withResource(i) - async def card_style(request, file={}): - file = tuple(file.values())[0] - return response.text(file, headers={"Content-Type": f"text/{filetype}"}) +for j in glob.iglob(os.path.join(config.resourcedir, "**","*"), recursive=True): + @call + def temp():#namespace hack + filetype = j.split('.')[-1] + if filetype in ("html", "css", "js"): + i = os.path.relpath(j, config.resourcedir) + print("Adding static resource", repr(i)) + if filetype == "js": filetype = "javascript" + + @app.get(f"/{i}") + @withResource(i) + async def card_style(request, file={}): + file = tuple(file.values())[0] + return response.text(file, headers={"Content-Type": f"text/{filetype}"}) #add svgs: @app.get(f"/svg/.svg")