From 5ae4d25b3bc8f9cd5f7b3201b1b6f4609c91d437 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Mon, 28 Aug 2023 16:19:08 +0200 Subject: [PATCH] Qute: execute tag templates in isolation by default - see https://github.com/quarkusio/quarkus/discussions/22285 --- docs/src/main/asciidoc/qute-reference.adoc | 8 ++-- .../io/quarkus/qute/IncludeSectionHelper.java | 47 +++++++++---------- .../io/quarkus/qute/UserTagSectionHelper.java | 20 ++++++-- .../java/io/quarkus/qute/IncludeTest.java | 14 ++++++ .../java/io/quarkus/qute/UserTagTest.java | 25 ++++++++-- 5 files changed, 76 insertions(+), 38 deletions(-) diff --git a/docs/src/main/asciidoc/qute-reference.adoc b/docs/src/main/asciidoc/qute-reference.adoc index fed88390ff54f..fd9eabea895cb 100644 --- a/docs/src/main/asciidoc/qute-reference.adoc +++ b/docs/src/main/asciidoc/qute-reference.adoc @@ -1143,10 +1143,10 @@ Then, we can call the tag like this: <1> `item` is resolved to an iteration element and can be referenced using the `it` key in the tag template. <2> Tag content injected using the `nested-content` key in the tag template. -By default, the tag template can reference data from the parent context. -For example, the tag above could use the following expression `{items.size}`. -However, sometimes it might be useful to disable this behavior and execute the tag as an _isolated_ template, i.e. without access to the context of the template that calls the tag. -In this case, just add `_isolated` or `_isolated=true` argument to the call site, e.g. `{#itemDetail item showImage=true _isolated /}`. +By default, a tag template cannot reference the data from the parent context. +Qute executes the tag as an _isolated_ template, i.e. without access to the context of the template that calls the tag. +However, sometimes it might be useful to change the default behavior and disable the isolation. +In this case, just add `_isolated=false` or `_unisolated` argument to the call site, for example `{#itemDetail item showImage=true _isolated=false /}` or `{#itemDetail item showImage=true _unisolated /}`. User tags can also make use of the template inheritance in the same way as regular `{#include}` sections do. diff --git a/independent-projects/qute/core/src/main/java/io/quarkus/qute/IncludeSectionHelper.java b/independent-projects/qute/core/src/main/java/io/quarkus/qute/IncludeSectionHelper.java index d3e6489f497d5..d42298f4e3bb9 100644 --- a/independent-projects/qute/core/src/main/java/io/quarkus/qute/IncludeSectionHelper.java +++ b/independent-projects/qute/core/src/main/java/io/quarkus/qute/IncludeSectionHelper.java @@ -7,7 +7,6 @@ import java.util.Map.Entry; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; -import java.util.function.Predicate; import java.util.function.Supplier; import io.quarkus.qute.Template.Fragment; @@ -117,6 +116,8 @@ protected boolean ignoreParameterInit(String key, String value) { || key.equals(ISOLATED) // {#include foo _isolated /} || value.equals(ISOLATED) + // {#include foo _unisolated /} + || value.equals(UNISOLATED) // {#include foo _ignoreFragments=true /} || key.equals(IGNORE_FRAGMENTS) // {#include foo _ignoreFragments /} @@ -134,8 +135,9 @@ protected String getTemplateId(SectionInitContext context) { @Override protected IncludeSectionHelper newHelper(Supplier