Completely split up the templating system from the Matrix Spec template code.
The two are now linked together in build.py by specifying the input module. Updated gendoc.py to specify the right module.pull/977/head
parent
8e1d6899c2
commit
5b31c442f5
@ -0,0 +1,33 @@
|
||||
"""Parent class for writing sections."""
|
||||
import inspect
|
||||
import os
|
||||
|
||||
|
||||
class Sections(object):
|
||||
"""A class which creates sections for each method starting with "render_".
|
||||
The key for the section is the text after "render_"
|
||||
e.g. "render_room_events" has the section key "room_events"
|
||||
"""
|
||||
|
||||
def __init__(self, env, units, debug=False):
|
||||
self.env = env
|
||||
self.units = units
|
||||
self.debug = debug
|
||||
|
||||
def log(self, text):
|
||||
if self.debug:
|
||||
print text
|
||||
|
||||
def get_sections(self):
|
||||
render_list = inspect.getmembers(self, predicate=inspect.ismethod)
|
||||
section_dict = {}
|
||||
for (func_name, func) in render_list:
|
||||
if not func_name.startswith("render_"):
|
||||
continue
|
||||
section_key = func_name[len("render_"):]
|
||||
section = func()
|
||||
section_dict[section_key] = section
|
||||
self.log("Generated section '%s' : %s" % (
|
||||
section_key, section[:60].replace("\n","")
|
||||
))
|
||||
return section_dict
|
@ -0,0 +1,40 @@
|
||||
"""Parent class for writing units."""
|
||||
from . import AccessKeyStore
|
||||
import inspect
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
class Units(object):
|
||||
|
||||
@staticmethod
|
||||
def prop(obj, path):
|
||||
# Helper method to extract nested property values
|
||||
nested_keys = path.split("/")
|
||||
val = obj
|
||||
for key in nested_keys:
|
||||
val = val.get(key, {})
|
||||
return val
|
||||
|
||||
|
||||
def __init__(self, debug=False):
|
||||
self.debug = debug
|
||||
|
||||
def log(self, text):
|
||||
if self.debug:
|
||||
print text
|
||||
|
||||
def get_units(self, debug=False):
|
||||
unit_list = inspect.getmembers(self, predicate=inspect.ismethod)
|
||||
unit_dict = {}
|
||||
for (func_name, func) in unit_list:
|
||||
if not func_name.startswith("load_"):
|
||||
continue
|
||||
unit_key = func_name[len("load_"):]
|
||||
unit_dict[unit_key] = func()
|
||||
self.log("Generated unit '%s' : %s" % (
|
||||
unit_key, json.dumps(unit_dict[unit_key])[:50].replace(
|
||||
"\n",""
|
||||
)
|
||||
))
|
||||
return unit_dict
|
@ -0,0 +1,9 @@
|
||||
from sections import MatrixSections
|
||||
from units import MatrixUnits
|
||||
import os
|
||||
|
||||
exports = {
|
||||
"units": MatrixUnits,
|
||||
"sections": MatrixSections,
|
||||
"templates": os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")
|
||||
}
|
Loading…
Reference in New Issue