diff --git a/cms-content/pom.xml b/cms-content/pom.xml index f0e11619..c386d566 100644 --- a/cms-content/pom.xml +++ b/cms-content/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 com.condation.cms @@ -8,7 +10,7 @@ cms-content jar - + com.condation.cms diff --git a/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java b/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java index 915250d3..ed887121 100644 --- a/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java +++ b/cms-content/src/main/java/com/condation/cms/content/DefaultContentRenderer.java @@ -139,13 +139,32 @@ public String render(final ReadOnlyFile contentFile, final RequestContext contex modelExtending.accept(model); + //model.values.put("cms", Namespace.create("cms", meta)); + + Namespace namespace = new Namespace(); + model.values.put("meta", new MapAccess(meta)); model.values.put("sections", sections); - model.values.put("shortCodes", createShortCodeFunction(context)); - model.values.put("navigation", createNavigationFunction(contentFile, context)); - model.values.put("nodeList", createNodeListFunction(contentFile, context)); - model.values.put("query", createQueryFunction(contentFile, context)); + namespace.add("page", "meta", new MapAccess(meta)); + namespace.add("page", "sections", sections); + + ShortCodeTemplateFunction shortCodeFunction = createShortCodeFunction(context); + model.values.put("shortCodes", shortCodeFunction); + namespace.add("cms", "shortCodes", shortCodeFunction); + + NavigationFunction navigationFunction = createNavigationFunction(contentFile, context); + model.values.put("navigation", navigationFunction); + namespace.add("cms", "navigation", shortCodeFunction); + + NodeListFunctionBuilder nodeListFunction = createNodeListFunction(contentFile, context); + model.values.put("nodeList", nodeListFunction); + namespace.add("cms", "nodeList", nodeListFunction); + + QueryFunction queryFunction = createQueryFunction(contentFile, context); + model.values.put("query", queryFunction); + namespace.add("cms", "query", queryFunction); + model.values.put("requestContext", context.get(RequestFeature.class)); model.values.put("theme", context.get(RenderContext.class).theme()); model.values.put("site", siteProperties); @@ -181,10 +200,12 @@ public String render(final ReadOnlyFile contentFile, final RequestContext contex extendModel(model); - model.values.put("content", - renderContent(rawContent, context, model) - ); + String content = renderContent(rawContent, context, model); + model.values.put("content", content); + namespace.add("page", "content", content); + model.values.putAll(namespace.getNamespaces()); + return templates.get().render((String) meta.get("template"), model); } diff --git a/cms-content/src/main/java/com/condation/cms/content/Namespace.java b/cms-content/src/main/java/com/condation/cms/content/Namespace.java new file mode 100644 index 00000000..e2b84944 --- /dev/null +++ b/cms-content/src/main/java/com/condation/cms/content/Namespace.java @@ -0,0 +1,19 @@ +package com.condation.cms.content; + +import java.util.HashMap; +import java.util.Map; + +import lombok.Getter; + + +public class Namespace { + + @Getter + Map> namespaces = new HashMap<>(); + + public void add (String namespace, String key, Object object) { + var namespaceMap = namespaces.computeIfAbsent(namespace, k -> new HashMap<>()); + namespaceMap.put(key, object); + } + +} diff --git a/test-server/themes/demo/templates/libs/fragments.html b/test-server/themes/demo/templates/libs/fragments.html index 41d934f4..68753512 100644 --- a/test-server/themes/demo/templates/libs/fragments.html +++ b/test-server/themes/demo/templates/libs/fragments.html @@ -2,7 +2,7 @@ - +