From 9abadaf7af6173be715a12639ecd8cd4e39f59d3 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 28 May 2015 10:36:02 +0100 Subject: [PATCH] Add {{presence_events}} template. --- event-schemas/schema/v1/m.presence | 2 ++ templating/matrix_templates/sections.py | 19 +++++++++++++++++++ templating/matrix_templates/units.py | 2 ++ 3 files changed, 23 insertions(+) diff --git a/event-schemas/schema/v1/m.presence b/event-schemas/schema/v1/m.presence index f7cc6048..bb69ce40 100644 --- a/event-schemas/schema/v1/m.presence +++ b/event-schemas/schema/v1/m.presence @@ -1,6 +1,8 @@ { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", + "title": "Presence Event", + "description": "Informs the client of a user's presence state change.", "properties": { "content": { "type": "object", diff --git a/templating/matrix_templates/sections.py b/templating/matrix_templates/sections.py index 6cb0ad5d..983b78bc 100644 --- a/templating/matrix_templates/sections.py +++ b/templating/matrix_templates/sections.py @@ -14,6 +14,20 @@ class MatrixSections(Sections): def render_spec_version(self): return "0.1.0" + def _render_events(self, filterFn, sortFn): + template = self.env.get_template("events.tmpl") + examples = self.units.get("event_examples") + schemas = self.units.get("event_schemas") + sections = [] + for event_name in sortFn(schemas): + if not filterFn(event_name): + continue + sections.append(template.render( + example=examples[event_name], + event=schemas[event_name] + )) + return "\n\n".join(sections) + def render_room_events(self): template = self.env.get_template("events.tmpl") examples = self.units.get("event_examples") @@ -66,6 +80,11 @@ class MatrixSections(Sections): )) return "\n\n".join(sections) + def render_presence_events(self): + def filterFn(eventType): + return eventType.startswith("m.presence") + return self._render_events(filterFn, sorted) + def _render_ce_type(self, type): template = self.env.get_template("common-event-fields.tmpl") ce_types = self.units.get("common_event_fields") diff --git a/templating/matrix_templates/units.py b/templating/matrix_templates/units.py index 109223de..027a9ab0 100644 --- a/templating/matrix_templates/units.py +++ b/templating/matrix_templates/units.py @@ -170,6 +170,8 @@ class MatrixUnits(Units): schema["typeof"] = base_defs.get( json_schema["allOf"][0].get("$ref") ) + elif json_schema.get("title"): + schema["typeof"] = json_schema["title"] # add type schema["type"] = Units.prop(