From d6345f0df2fec12c08aaadac6fe3c6423a4bf87b Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Wed, 26 Oct 2022 16:33:41 -0400 Subject: [PATCH] apply changes from code review --- .../client-server-api/modules/instant_messaging.md | 2 +- layouts/partials/events/example.html | 11 ++++++++++- layouts/partials/events/render-event.html | 14 ++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/content/client-server-api/modules/instant_messaging.md b/content/client-server-api/modules/instant_messaging.md index 47440cd3..efa2c579 100644 --- a/content/client-server-api/modules/instant_messaging.md +++ b/content/client-server-api/modules/instant_messaging.md @@ -10,7 +10,7 @@ room itself such as a room name and topic. #### Events -{{% event event="m.room.message" %}} +{{% event event="m.room.message" desired_example_name="m.room.message$m.text" %}} {{% event event="m.room.name" %}} diff --git a/layouts/partials/events/example.html b/layouts/partials/events/example.html index 95e17e22..7059d453 100644 --- a/layouts/partials/events/example.html +++ b/layouts/partials/events/example.html @@ -1,4 +1,13 @@ -{{ $example_content := partial "json-schema/resolve-refs" (dict "schema" .example "path" "event-schemas/examples") }} +{{/* + + Renders an event example. Resolves `$ref`s, serializes as JSON, and ensures + that it can be included in HTML. + + This partial is called with the example data as its context. + +*/}} + +{{ $example_content := partial "json-schema/resolve-refs" (dict "schema" . "path" "event-schemas/examples") }} {{ $example_json := jsonify (dict "indent" " ") $example_content }} {{ $example_json = replace $example_json "\\u003c" "<" }} {{ $example_json = replace $example_json "\\u003e" ">" | safeHTML }} diff --git a/layouts/partials/events/render-event.html b/layouts/partials/events/render-event.html index 73421741..71951937 100644 --- a/layouts/partials/events/render-event.html +++ b/layouts/partials/events/render-event.html @@ -22,7 +22,7 @@

- {{ with .title }}{{ $.title | markdownify }}{{ else }}{{ $event_name }}{{ end }} + {{ with .title }}{{ . | markdownify }}{{ else }}{{ $event_name }}{{ end }}


@@ -74,10 +74,16 @@ */}} {{ if $desired_example_name }} {{ if eq $example_name $desired_example_name }} - {{ partial "events/example" (dict "example" $example)}} + {{ partial "events/example" $example }} {{ end }} + {{/* + If `$desired_example_name` is not given, we will include any + example that is equal to the event name. Normally, this would + be handled by the case below, but that case does not work if + the event name includes a "$". + */}} {{ else if eq $event_name $example_name }} - {{ partial "events/example" (dict "example" $example)}} + {{ partial "events/example" $example }} {{/* If `$desired_example_name` is not given, we will include any examples whose first part (before "$") matches the event name @@ -87,7 +93,7 @@ {{ $pieces := split $example_name "$" }} {{ $example_base_name := index $pieces 0 }} {{ if eq $event_name $example_base_name }} - {{ partial "events/example" (dict "example" $example)}} + {{ partial "events/example" $example }} {{ end }} {{ end }} {{ end }}