Improve properties.mako.rs file structure, take 2

This is a new attempt of #10586, after Simon Sapin's great cleanups in #10749 has landed. I have adjusted the changes to the new structure that was introduced, and also only done a few of the longhand ones. Will certainly continue on this as soon as we have a basic agreement that this style is reasonable.
This commit is contained in:
Per Lundberg 2016-04-21 00:06:25 +03:00
parent a6fc440125
commit d0489f1160
10 changed files with 358 additions and 305 deletions

View file

@ -10,6 +10,7 @@ BASE = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(BASE, "Mako-0.9.1.zip"))
from mako import exceptions
from mako.lookup import TemplateLookup
from mako.template import Template
import data
@ -43,10 +44,19 @@ def abort(message):
def render(filename, **context):
try:
# Workaround the fact that we can have a different working directory when called, and Mako includes will fail
# miserably if we don't give it proper instructions in the TemplateLookup.
if os.getcwd().endswith("components/style"):
properties_path = "properties"
else:
properties_path = "components/style/properties"
lookup = TemplateLookup(directories=[properties_path])
template = Template(open(filename, "rb").read(),
filename=filename,
input_encoding="utf8",
strict_undefined=True,
filename=filename)
lookup=lookup,
strict_undefined=True)
# Uncomment to debug generated Python code:
# write("/tmp", "mako_%s.py" % os.path.basename(filename), template.code)
return template.render(**context).encode("utf8")