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


The following commit(s) were added to refs/heads/master by this push:
     new 89c1b7d  SLING-9950 - tweak renderers
89c1b7d is described below

commit 89c1b7d096bb811de0b82866e9bdf84b18b9c367
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Fri Dec 4 12:38:38 2020 +0100

    SLING-9950 - tweak renderers
---
 .../openwhisk-rendering/content-renderer.js        | 51 +++++++++++++++++-----
 1 file changed, 40 insertions(+), 11 deletions(-)

diff --git a/remote-content-api/openwhisk-rendering/content-renderer.js 
b/remote-content-api/openwhisk-rendering/content-renderer.js
index 9be324f..3f7f505 100644
--- a/remote-content-api/openwhisk-rendering/content-renderer.js
+++ b/remote-content-api/openwhisk-rendering/content-renderer.js
@@ -35,25 +35,54 @@ class HandlebarsRenderer {
 var renderers = {}
 
 var DEFAULT_RENDERER = new HandlebarsRenderer('\
-    <h3>{{title}}</h3>\
-    This is the default renderer<br>\
+    <h3>Default renderer</h3>\
     <b>Path</b>:{{path}}<br>\
     <b>sling:resourceType</b>:{{sling:resourceType}}<br>\
-    {{{text}}}\
-    ');
+    ')
 
 renderers["samples/article"] = new HandlebarsRenderer('\
-      <h3>{{section}}: {{title}}</h3>\
+      <h3>Articles renderer</h3>\
+      <h4>{{title}}</h4>\
       <div><b>tags</b>:{{tags}}</div>\
       <blockquote>{{{text}}}</blockquote>\
-    ');
+    ')
+
+renderers["samples/section"] = new HandlebarsRenderer('\
+    <h3>Articles section renderer</h3>\
+    This is the <b>{{name}}</b> section.\
+    ')
 
-renderers["samples/section"] = new HandlebarsRenderer('This is the 
<b>{{name}}</b> section.')
+class WkndPageRenderer extends HandlebarsRenderer {
+    constructor(templateSrc) {
+        super(templateSrc)
+    }
 
-// Need to recurse in the content and dispatch to more renderers
-renderers["wknd/components/page"] = new HandlebarsRenderer('\
-    <h3>WKND page - TODO this renderer is very incomplete</h3>\
-    <div>tags: {{jcr:content.cq:tags}}</div>\
+    collectResourceTypes(resource, targetSet) {
+        for(const key in resource) {
+            const prop = resource[key]
+            if("sling:resourceType" == key) {
+                targetSet.add(`${prop} ${renderers[prop] ? " (renderer 
provided)": ""}`)
+            } else if(typeof prop == "object") {
+                this.collectResourceTypes(prop, targetSet)
+            }
+        }
+    }
+
+    render(content) { 
+        content.rendererInfo = { resourceTypes:new Set() }
+        this.collectResourceTypes(content, content.rendererInfo.resourceTypes)
+        return super.render(content)
+    }
+}
+renderers["wknd/components/page"] = new WkndPageRenderer('\
+    <h3>WKND page renderer</h3>\n\
+    <div>tags: {{jcr:content.cq:tags}}</div>\n\
+    <h4>We will need renderers for the following resource types, found in the 
page content:</h4>\n\
+    <ul>\n\
+      {{#each rendererInfo.resourceTypes}}\n\
+      <li>{{this}}</li>\n\
+      {{/each}}\
+    </ul></div>\n\
     ');
 
 class ContentRenderer {

Reply via email to