From 1489bfe9a2012060c15bcd7bc8e7e3ce4432a74d Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 21 May 2019 07:33:21 +0100 Subject: [PATCH] Switch naming convention in MustacheView to async prefix --- .../MustacheAutoConfigurationReactiveIntegrationTests.java | 2 +- .../src/test/resources/mustache-templates/sse.html | 4 ++-- .../src/main/asciidoc/spring-boot-features.adoc | 6 +++--- .../boot/web/reactive/result/view/MustacheView.java | 3 +-- .../boot/web/reactive/result/view/MustacheViewTests.java | 6 +++--- .../springframework/boot/web/reactive/result/view/flux.html | 4 ++-- .../springframework/boot/web/reactive/result/view/sse.html | 4 ++-- .../boot/web/reactive/result/view/ssedata.html | 4 ++-- 8 files changed, 16 insertions(+), 17 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationReactiveIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationReactiveIntegrationTests.java index e6fb5fbdd30b..1133c0bcb1f9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationReactiveIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationReactiveIntegrationTests.java @@ -107,7 +107,7 @@ public String layout(Model model) { @RequestMapping(path = "/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE) public String sse(Model model) { model.addAttribute("time", new Date()); - model.addAttribute("flux.message", + model.addAttribute("async.message", Flux.just("Hello", "World") .delayElements(Duration.ofMillis(10))); model.addAttribute("title", "Hello App"); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/mustache-templates/sse.html b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/mustache-templates/sse.html index 2f3a79267505..8d0b96b19342 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/mustache-templates/sse.html +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/mustache-templates/sse.html @@ -1,7 +1,7 @@ -{{#flux.message}} +{{#async.message}} event: message {{#ssedata}}

Title

{{{.}}} {{/ssedata}} -{{/flux.message}} +{{/async.message}} diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index fbb7a7e94219..492c7445ebdc 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -3038,14 +3038,14 @@ There are some special features of the `MustacheView` that make it suitable for ===== Progressive Rendering -A model element of type `Publisher` will be left in the model (instead of expanding it before the view is rendered), if its name starts with "flux" or "mono" or "publisher". The `View` is then rendered and flushed to the HTTP response as soon as each element is published. Browsers are really good at rendering partially complete HTML, so the flux elements will most likely be visible to the user as soon as they are available. This is useful for rendering the "main" content of a page if it is a list or a table, for instance. +A model element of type `Publisher` will be left in the model (instead of expanding it before the view is rendered), if its name starts with "async." or "async:". The `View` is then rendered and flushed to the HTTP response as soon as each element is published. Browsers are really good at rendering partially complete HTML, so the flux elements will most likely be visible to the user as soon as they are available. This is useful for rendering the "main" content of a page if it is a list or a table, for instance. ===== Sserver Sent Event (SSE) Support To render a `View` with content type `text/event-stream` you need a model element of type `Publisher`, and also a template that includes that element (probably starts and ends with it). There is a convenience Lambda (`ssedata`) added to the model for you that prepends every line with `data:` - you can use it if you wish to simplify the rendering of the data elements. Two new lines are added after each item in `{{#ssedata}}`. E.g. with an element called `flux.events` of type `Flux`: ``` -{{#flux.events}} +{{#async.events}} event: message id: {{id}} {{#ssedata}} @@ -3054,7 +3054,7 @@ id: {{id}} Value: {{value}} {{/ssedata}} -{{/flux.events}} +{{/async.events}} ``` the output will be diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/result/view/MustacheView.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/result/view/MustacheView.java index 7343c3bae61a..832132c31744 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/result/view/MustacheView.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/result/view/MustacheView.java @@ -151,8 +151,7 @@ private Template compile(Resource resource) { protected Mono resolveAsyncAttributes(Map model) { Map result = new HashMap<>(); for (String key : model.keySet()) { - if (!key.startsWith("flux") && !key.startsWith("mono") - && !key.startsWith("publisher")) { + if (!key.startsWith("async.") && !key.startsWith("async:")) { result.put(key, model.get(key)); } else { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java index 65598ed730ba..894db16ccc4f 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/result/view/MustacheViewTests.java @@ -75,7 +75,7 @@ public void viewResolvesPublisher() { view.setUrl(this.templateUrl + "/flux.html"); view.setCharset(StandardCharsets.UTF_8.displayName()); view.setApplicationContext(this.context); - view.render(Collections.singletonMap("flux.value", Flux.just("World", "Spring")), + view.render(Collections.singletonMap("async:value", Flux.just("World", "Spring")), MediaType.TEXT_HTML, this.exchange).block(Duration.ofSeconds(30)); assertThat(this.exchange.getResponse().getBodyAsString() .block(Duration.ofSeconds(30))).isEqualTo("Hello\nWorld\nSpring\n"); @@ -90,7 +90,7 @@ public void viewResolvesSseManual() { view.setUrl(this.templateUrl + "/sse.html"); view.setCharset(StandardCharsets.UTF_8.displayName()); view.setApplicationContext(this.context); - view.render(Collections.singletonMap("flux.value", Flux.just("World", "Spring")), + view.render(Collections.singletonMap("async.value", Flux.just("World", "Spring")), MediaType.TEXT_EVENT_STREAM, this.exchange).block(Duration.ofSeconds(30)); assertThat(this.exchange.getResponse().getBodyAsString() .block(Duration.ofSeconds(30))).isEqualTo( @@ -106,7 +106,7 @@ public void viewResolvesSseData() { view.setUrl(this.templateUrl + "/ssedata.html"); view.setCharset(StandardCharsets.UTF_8.displayName()); view.setApplicationContext(this.context); - view.render(Collections.singletonMap("flux.value", Flux.just("World", "Spring")), + view.render(Collections.singletonMap("async.value", Flux.just("World", "Spring")), MediaType.TEXT_EVENT_STREAM, this.exchange) .block(Duration.ofSeconds(300)); assertThat(this.exchange.getResponse().getBodyAsString() diff --git a/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/flux.html b/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/flux.html index 0824469ef644..fe399fddb9e9 100644 --- a/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/flux.html +++ b/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/flux.html @@ -1,4 +1,4 @@ Hello -{{#flux.value}} +{{#async:value}} {{.}} -{{/flux.value}} \ No newline at end of file +{{/async:value}} \ No newline at end of file diff --git a/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/sse.html b/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/sse.html index 8a92ab36629e..449615cae3fa 100644 --- a/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/sse.html +++ b/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/sse.html @@ -1,6 +1,6 @@ -{{#flux.value}} +{{#async.value}} event: message data: {{.}} -{{/flux.value}} \ No newline at end of file +{{/async.value}} \ No newline at end of file diff --git a/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/ssedata.html b/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/ssedata.html index e164beadb91d..938d0eae52a5 100644 --- a/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/ssedata.html +++ b/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/web/reactive/result/view/ssedata.html @@ -1,6 +1,6 @@ -{{#flux.value}} +{{#async.value}} event: message {{#ssedata}} {{.}} {{/ssedata}} -{{/flux.value}} \ No newline at end of file +{{/async.value}} \ No newline at end of file