Add instant_messaging module; modify batesian section rules
Previously, all `m.room.*` events were wodged into `{{room_events}}` which isn't great when you want to pull specific ones out. Batesian had a 1:1 mapping of `render_foo()` to a section `{{foo}}`, and having to constantly add functions for new types is a PITA. Batesian now supports returning a `dict` instead of a section `string` where the keys are the `{{foo}}` and the value is what will be inserted. Also add conflicting section key checks to avoid multiple definitions of the same `{{foo}}`. Define dicts for event schemata and swagger HTTP APIs. Using this new feature, split out the instant messaging stuff from the events section, and replace `{{room_events}}` with a list of specific events e.g. `{{m_room_member_event}}`.
This commit is contained in:
parent
5b134119bd
commit
5115346297
6 changed files with 105 additions and 100 deletions
|
@ -27,12 +27,38 @@ class Sections(object):
|
|||
section_key = func_name[len("render_"):]
|
||||
self.log("Generating section '%s'" % section_key)
|
||||
section = func()
|
||||
if not isinstance(section, basestring):
|
||||
raise Exception(
|
||||
"Section function '%s' didn't return a string!" % func_name
|
||||
if isinstance(section, basestring):
|
||||
if section_key in section_dict:
|
||||
raise Exception(
|
||||
("%s : Section %s already exists. It must have been " +
|
||||
"generated dynamically. Check which render_ methods " +
|
||||
"return a dict.") %
|
||||
(func_name, section_key)
|
||||
)
|
||||
section_dict[section_key] = section
|
||||
self.log(
|
||||
" Generated. Snippet => %s" % section[:60].replace("\n","")
|
||||
)
|
||||
elif isinstance(section, dict):
|
||||
self.log(" Generated multiple sections:")
|
||||
for (k, v) in section.iteritems():
|
||||
if not isinstance(k, basestring) or not isinstance(v, basestring):
|
||||
raise Exception(
|
||||
("Method %s returned multiple sections as a dict but " +
|
||||
"expected the dict elements to be strings but they aren't.") %
|
||||
(func_name, )
|
||||
)
|
||||
if k in section_dict:
|
||||
raise Exception(
|
||||
"%s tried to produce section %s which already exists." %
|
||||
(func_name, k)
|
||||
)
|
||||
section_dict[k] = v
|
||||
self.log(
|
||||
" %s => %s" % (k, v[:60].replace("\n",""))
|
||||
)
|
||||
else:
|
||||
raise Exception(
|
||||
"Section function '%s' didn't return a string/dict!" % func_name
|
||||
)
|
||||
section_dict[section_key] = section
|
||||
self.log(
|
||||
" Generated. Snippet => %s" % section[:60].replace("\n","")
|
||||
)
|
||||
return section_dict
|
Loading…
Add table
Add a link
Reference in a new issue