You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/05/29 09:08:22 UTC
[sling-whiteboard] branch master updated (f33a02b -> b73ef07)
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git.
from f33a02b Move 'under the hood' to the README
new 9beeb8d Fix tag lists templates
new b73ef07 Fix titles
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
org.apache.sling.graphql.samples.website/README.md | 4 ++--
.../sling/scripting/handlebars/HandlebarsScriptEngine.java | 11 ++++++++++-
.../initial-content/apps/samples/article/article.hbs | 4 ++--
.../initial-content/apps/samples/section/section.hbs | 2 +-
.../SLING-INF/initial-content/apps/samples/tag/tag.hbs | 4 ++--
5 files changed, 17 insertions(+), 8 deletions(-)
[sling-whiteboard] 01/02: Fix tag lists templates
Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit 9beeb8d7b326a7c34afa0b7271e0de8779c31607
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri May 29 11:04:04 2020 +0200
Fix tag lists templates
---
org.apache.sling.graphql.samples.website/README.md | 4 ++--
.../sling/scripting/handlebars/HandlebarsScriptEngine.java | 11 ++++++++++-
.../initial-content/apps/samples/article/article.hbs | 2 +-
.../SLING-INF/initial-content/apps/samples/tag/tag.hbs | 2 +-
4 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/org.apache.sling.graphql.samples.website/README.md b/org.apache.sling.graphql.samples.website/README.md
index 16ee86f..f962b73 100644
--- a/org.apache.sling.graphql.samples.website/README.md
+++ b/org.apache.sling.graphql.samples.website/README.md
@@ -90,9 +90,9 @@ And open the above mentioned start page.
## Under the hood
The following explanations apply to the article and navigation pages. The (upcoming) single-page apps
-will use different mechanisms.
+will use similar mechanisms client-side.
-The scripts and source code mentioned below are foud in the source code and initial content of this
+The scripts and source code mentioned below are found in the source code and initial content of this
demo module.
The GraphQL core retrieves a schema for the current Sling Resource by making a request with
diff --git a/org.apache.sling.graphql.samples.website/src/main/java/org/apache/sling/scripting/handlebars/HandlebarsScriptEngine.java b/org.apache.sling.graphql.samples.website/src/main/java/org/apache/sling/scripting/handlebars/HandlebarsScriptEngine.java
index cf628ef..eb79f20 100644
--- a/org.apache.sling.graphql.samples.website/src/main/java/org/apache/sling/scripting/handlebars/HandlebarsScriptEngine.java
+++ b/org.apache.sling.graphql.samples.website/src/main/java/org/apache/sling/scripting/handlebars/HandlebarsScriptEngine.java
@@ -34,6 +34,7 @@ import javax.script.ScriptException;
import com.cedarsoftware.util.io.JsonReader;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
+import com.github.jknack.handlebars.helper.StringHelpers;
import org.apache.commons.io.IOUtils;
import org.apache.sling.api.resource.Resource;
@@ -50,6 +51,8 @@ import org.apache.sling.servlethelpers.MockSlingHttpServletResponse;
* The JSON representation of the current Resource is retrieved
* using an internal request with the Resource path + ".json", and
* the result converted to a Handlebars-friendly Map of Maps.
+ *
+ * See https://github.com/jknack/handlebars.java for Handlebars docs
*/
public class HandlebarsScriptEngine extends AbstractScriptEngine {
@@ -65,7 +68,7 @@ public class HandlebarsScriptEngine extends AbstractScriptEngine {
final PrintWriter out = (PrintWriter) context.getBindings(ScriptContext.ENGINE_SCOPE).get(SlingBindings.OUT);
try {
- final Handlebars handlebars = new Handlebars();
+ final Handlebars handlebars = setupHandlebars();
final Template template = handlebars.compileInline(script);
out.println(template.apply(getData(resource)));
} catch(IOException ioe) {
@@ -76,6 +79,12 @@ public class HandlebarsScriptEngine extends AbstractScriptEngine {
return null;
}
+ private Handlebars setupHandlebars() {
+ final Handlebars result = new Handlebars();
+ result.registerHelpers(StringHelpers.class);
+ return result;
+ }
+
/** We might do this with a BindingsValuesProvider? */
private Map<?, ?> getData(Resource r) throws ScriptException {
// Request resource.json and convert the result to Maps
diff --git a/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/article/article.hbs b/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/article/article.hbs
index 84980f0..612db9a 100644
--- a/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/article/article.hbs
+++ b/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/article/article.hbs
@@ -47,7 +47,7 @@
<a href="/tags/{{this}}.html">{{this}}</a>
</span>
{{/each}}
- - Find articles <a href="/tags/{{data.article.tagsQuery}}.html">with all these tags</a>
+ - Find articles <a href='/tags/{{join data.article.tags "+"}}.html'>with all these tags</a>
<hr/>
{{/if}}
</div>
diff --git a/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/tag/tag.hbs b/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/tag/tag.hbs
index f8b6b3e..19bf581 100644
--- a/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/tag/tag.hbs
+++ b/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/tag/tag.hbs
@@ -34,7 +34,7 @@
<hr/>
</div>
- <h1>Articles with tags "{{data.tagQuery.query}}"</h1>
+ <h1>Articles with tags "{{join data.tagQuery.query ','}}"</h1>
<ul>
{{#each data.tagQuery.articles}}
<li class="seeAlso">
[sling-whiteboard] 02/02: Fix titles
Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit b73ef07d7510c80244968c00bb34ecb7e4700357
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri May 29 11:08:09 2020 +0200
Fix titles
---
.../SLING-INF/initial-content/apps/samples/article/article.hbs | 2 +-
.../SLING-INF/initial-content/apps/samples/section/section.hbs | 2 +-
.../main/resources/SLING-INF/initial-content/apps/samples/tag/tag.hbs | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/article/article.hbs b/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/article/article.hbs
index 612db9a..fab9208 100644
--- a/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/article/article.hbs
+++ b/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/article/article.hbs
@@ -19,7 +19,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
<html>
<head>
- <title>{{data.title}}</title>
+ <title>{{data.article.title}}</title>
<link rel="stylesheet" href="https://fonts.xz.style/serve/inter.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@exampledev/new.css@1.1.2/new.min.css">
</head>
diff --git a/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/section/section.hbs b/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/section/section.hbs
index caf36f5..9c3199f 100644
--- a/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/section/section.hbs
+++ b/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/section/section.hbs
@@ -19,7 +19,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
<html>
<head>
- <title>{{data.title}}</title>
+ <title>{{data.section.name}}</title>
<link rel="stylesheet" href="https://fonts.xz.style/serve/inter.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@exampledev/new.css@1.1.2/new.min.css">
</head>
diff --git a/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/tag/tag.hbs b/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/tag/tag.hbs
index 19bf581..7c04a0b 100644
--- a/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/tag/tag.hbs
+++ b/org.apache.sling.graphql.samples.website/src/main/resources/SLING-INF/initial-content/apps/samples/tag/tag.hbs
@@ -19,7 +19,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
<html>
<head>
- <title>{{data.title}}</title>
+ <title>Articles with tags "{{join data.tagQuery.query ','}}"</title>
<link rel="stylesheet" href="https://fonts.xz.style/serve/inter.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@exampledev/new.css@1.1.2/new.min.css">
</head>