Factor out ImageInfo into a core type. Refer to that in other msgtypes.

Add templating for msgtypes. ImageInfo core type is not referred to for
m.image in order for the ImageInfo table to render for it.
This commit is contained in:
Kegan Dougal 2015-05-27 16:30:11 +01:00
parent 59168df363
commit 59f856c7e6
9 changed files with 106 additions and 43 deletions

View file

@ -58,6 +58,31 @@
}
},
"required": ["state_key"]
},
"msgtype_infos": {
"image_info": {
"type": "object",
"title": "ImageInfo",
"description": "Metadata about an image.",
"properties": {
"size": {
"type": "integer",
"description": "Size of the image in bytes."
},
"w": {
"type": "integer",
"description": "The width of the image in pixels."
},
"h": {
"type": "integer",
"description": "The height of the image in pixels."
},
"mimetype": {
"type": "string",
"description": "The mimetype of the image, e.g. ``image/jpeg``."
}
}
}
}
}
}

View file

@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "FileMessage",
"description": "TODO.",
"description": "This message represents a generic file.",
"allOf": [{
"$ref": "core#/definitions/room_event"
}],
@ -49,24 +49,9 @@
"type": "object",
"title": "ImageInfo",
"description": "Metadata about the image referred to in ``thumbnail_url``.",
"properties": {
"size": {
"type": "integer",
"description": "Size of the image in bytes."
},
"w": {
"type": "integer",
"description": "The width of the image in pixels."
},
"h": {
"type": "integer",
"description": "The height of the image in pixels."
},
"mimetype": {
"type": "string",
"description": "The mimetype of the image, e.g. ``image/jpeg``."
}
}
"allOf": [{
"$ref": "core#/definitions/msgtype_infos/image_info"
}]
}
},
"required": ["msgtype", "body", "url", "filename"]

View file

@ -30,24 +30,9 @@
"type": "object",
"title": "ImageInfo",
"description": "Metadata about the image referred to in ``thumbnail_url``.",
"properties": {
"size": {
"type": "integer",
"description": "Size of the image in bytes."
},
"w": {
"type": "integer",
"description": "The width of the image in pixels."
},
"h": {
"type": "integer",
"description": "The height of the image in pixels."
},
"mimetype": {
"type": "string",
"description": "The mimetype of the image, e.g. ``image/jpeg``."
}
}
"allOf": [{
"$ref": "core#/definitions/msgtype_infos/image_info"
}]
},
"info": {
"type": "object",

View file

@ -28,7 +28,10 @@
},
"thumbnail_info": {
"type": "object",
"title": "ImageInfo"
"title": "ImageInfo",
"allOf": [{
"$ref": "core#/definitions/msgtype_infos/image_info"
}]
}
},
"required": ["msgtype", "body", "geo_uri"]

View file

@ -53,7 +53,10 @@
},
"thumbnail_info": {
"type": "object",
"title": "ImageInfo"
"title": "ImageInfo",
"allOf": [{
"$ref": "core#/definitions/msgtype_infos/image_info"
}]
}
}
}

View file

@ -20,7 +20,22 @@ class MatrixSections(Sections):
schemas = self.units.get("event_schemas")
sections = []
for event_name in sorted(schemas):
if not event_name.startswith("m.room"):
if (not event_name.startswith("m.room") or
event_name.startswith("m.room.message#m.")):
continue
sections.append(template.render(
example=examples[event_name],
event=schemas[event_name]
))
return "\n\n".join(sections)
def render_msgtype_events(self):
template = self.env.get_template("msgtypes.tmpl")
examples = self.units.get("event_examples")
schemas = self.units.get("event_schemas")
sections = []
for event_name in sorted(schemas):
if not event_name.startswith("m.room.message#m."):
continue
sections.append(template.render(
example=examples[event_name],

View file

@ -0,0 +1,23 @@
``{{event.msgtype}}``
{{(4 + event.msgtype | length) * '~'}}
{{event.desc | wrap(80)}}
{% for table in event.content_fields -%}
{{"``"+table.title+"``" if table.title else "" }}
================== ================= ===========================================
{{table.title or "Content"}} Key Type Description
================== ================= ===========================================
{% for row in table.rows -%}
{# -#}
{# Row type needs to prepend spaces to line up with the type column (19 ch) -#}
{# Desc needs to prepend the required text (maybe) and prepend spaces too -#}
{# It also needs to then wrap inside the desc col (43 ch width) -#}
{# -#}
{{row.key}}{{row.type|indent(19-row.key|length)}}{{row.desc|wrap(43,row.req_str | indent(18 - (row.type|length))) |indent_block(37)}}
{% endfor -%}
================== ================= ===========================================
{% endfor %}
Example::
{{example | jsonify(4, 4)}}

View file

@ -14,6 +14,8 @@ class MatrixUnits(Units):
with open(path, "r") as f:
core_json = json.loads(f.read())
for event_type in core_json["definitions"]:
if "event" not in event_type:
continue # filter ImageInfo and co
event_info = core_json["definitions"][event_type]
table = {
"title": event_info["title"],
@ -68,7 +70,19 @@ class MatrixUnits(Units):
}
tables = [fields]
props = obj["properties"]
props = obj.get("properties")
parents = obj.get("allOf")
if not props and not parents:
raise Exception(
"Object %s has no properties or parents." % obj
)
if not props: # parents only
return [{
"title": obj["title"],
"parent": parents[0]["$ref"],
"no-table": True
}]
for key_name in sorted(props):
value_type = None
required = key_name in required_keys
@ -87,6 +101,8 @@ class MatrixUnits(Units):
enforce_title=True
)
value_type = "{%s}" % nested_object[0]["title"]
if not nested_object[0].get("no-table"):
tables += nested_object
elif props[key_name]["type"] == "array":
# if the items of the array are objects then recurse
@ -133,6 +149,7 @@ class MatrixUnits(Units):
"type": None,
"title": None,
"desc": None,
"msgtype": None,
"content_fields": [
# {
# title: "<title> key"
@ -168,6 +185,13 @@ class MatrixUnits(Units):
Units.prop(json_schema, "properties/content")
)
# grab msgtype if it is the right kind of event
msgtype = Units.prop(
json_schema, "properties/content/properties/msgtype/enum"
)
if msgtype:
schema["msgtype"] = msgtype[0] # enum prop
# Assign state key info
if schema["typeof"] == "State Event":
skey_desc = Units.prop(