You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2022/11/04 08:52:44 UTC
[sling-org-apache-sling-scripting-freemarker] branch master updated: SLING-11660 Improve IncludeDirective
This is an automated email from the ASF dual-hosted git repository.
olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-freemarker.git
The following commit(s) were added to refs/heads/master by this push:
new 054a0b7 SLING-11660 Improve IncludeDirective
054a0b7 is described below
commit 054a0b757e884cace2e9d690cbd7420af7706f8a
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Fri Nov 4 09:52:08 2022 +0100
SLING-11660 Improve IncludeDirective
add integration tests for path based includes
---
.../freemarker/it/tests/FreemarkerTestSupport.java | 5 ++++-
.../sling/scripting/freemarker/it/tests/IncludeIT.java | 18 +++++++++++++++---
.../apps/freemarker/page/include/html.ftl | 8 +++++++-
.../resources/initial-content/content/includes.json | 13 +++++++++++++
4 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java b/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
index b620019..4a55209 100644
--- a/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
+++ b/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
@@ -76,7 +76,10 @@ public abstract class FreemarkerTestSupport extends TestSupport {
mavenBundle().groupId("org.apache.servicemix.specs").artifactId("org.apache.servicemix.specs.jaxp-api-1.4").versionAsInProject(),
// testing
factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
- .put("scripts", new String[]{"create path (sling:OrderedFolder) /content/freemarker\nset ACL for everyone\nallow jcr:read on /content/freemarker\nend"})
+ .put("scripts", new String[]{
+ "create path (sling:OrderedFolder) /content/freemarker\nset ACL for everyone\nallow jcr:read on /content/freemarker\nend",
+ "create path (sling:OrderedFolder) /content/includes\nset ACL for everyone\nallow jcr:read on /content/includes\nend"
+ })
.asOption(),
slingResourcePresence(),
mavenBundle().groupId("org.jsoup").artifactId("jsoup").versionAsInProject()
diff --git a/src/test/java/org/apache/sling/scripting/freemarker/it/tests/IncludeIT.java b/src/test/java/org/apache/sling/scripting/freemarker/it/tests/IncludeIT.java
index 1a4ecbe..f36ddf1 100644
--- a/src/test/java/org/apache/sling/scripting/freemarker/it/tests/IncludeIT.java
+++ b/src/test/java/org/apache/sling/scripting/freemarker/it/tests/IncludeIT.java
@@ -73,9 +73,21 @@ public class IncludeIT extends FreemarkerTestSupport {
}
@Test
- public void testJspIncludeSimple() {
- final Element simple = document.getElementById("simple");
- assertThat(simple.text(), is("/content/freemarker/include"));
+ public void testJspIncludeResource() {
+ final Element element = document.getElementById("resource");
+ assertThat(element.text(), is("/content/freemarker/include"));
+ }
+
+ @Test
+ public void testJspIncludeAbspath() {
+ final Element element = document.getElementById("abspath");
+ assertThat(element.text(), is("/content/includes/foo"));
+ }
+
+ @Test
+ public void testJspIncludeRelpath() {
+ final Element element = document.getElementById("relpath");
+ assertThat(element.text(), is("/content/includes/bar"));
}
}
diff --git a/src/test/resources/initial-content/apps/freemarker/page/include/html.ftl b/src/test/resources/initial-content/apps/freemarker/page/include/html.ftl
index 3cb2828..8f6d098 100644
--- a/src/test/resources/initial-content/apps/freemarker/page/include/html.ftl
+++ b/src/test/resources/initial-content/apps/freemarker/page/include/html.ftl
@@ -23,8 +23,14 @@
<title>Sling Include (with JSP)</title>
</head>
<body>
-<span id="simple">
+<span id="resource">
<@sling.include include=resource resourceType="jsp/page/resource"/>
</span>
+<span id="abspath">
+<@sling.include include="/content/includes/foo"/>
+</span>
+<span id="relpath">
+<@sling.include include="../../includes/bar"/>
+</span>
</body>
</html>
diff --git a/src/test/resources/initial-content/content/includes.json b/src/test/resources/initial-content/content/includes.json
new file mode 100644
index 0000000..174910e
--- /dev/null
+++ b/src/test/resources/initial-content/content/includes.json
@@ -0,0 +1,13 @@
+{
+ "jcr:primaryType": "nt:unstructured",
+ "foo": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "jsp/page/resource",
+ "title": "Foo"
+ },
+ "bar": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "jsp/page/resource",
+ "title": "Bar"
+ }
+}