Skip to content

Commit

Permalink
first prototype of namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsten Marx committed Nov 13, 2024
1 parent ddd26ff commit c778cfa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cms-content/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.condation.cms</groupId>
Expand All @@ -8,7 +10,7 @@
</parent>
<artifactId>cms-content</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.condation.cms</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
19 changes: 19 additions & 0 deletions cms-content/src/main/java/com/condation/cms/content/Namespace.java
Original file line number Diff line number Diff line change
@@ -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<String, Map<String, Object>> namespaces = new HashMap<>();

public void add (String namespace, String key, Object object) {
var namespaceMap = namespaces.computeIfAbsent(namespace, k -> new HashMap<>());
namespaceMap.put(key, object);
}

}
2 changes: 1 addition & 1 deletion test-server/themes/demo/templates/libs/fragments.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<th:block th:fragment="header">
<title th:text="${meta.title}"></title>
<title th:text="${page.meta.title}"></title>
<link rel="canonical" th:href="${site.get('baseurl')} + ${requestContext.uri}" />
<link rel="shortcut icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down

0 comments on commit c778cfa

Please sign in to comment.