Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cms-api/src/main/java/com/condation/cms/api/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public static class ContentTypes {

public static final String DEFAULT_CACHE_ENGINE = "local";
public static final boolean DEFAULT_CONTENT_CACHE_ENABLED = false;

public static final String DEFAULT_MODULE_NAMESPACE = "mod";

public static class Taxonomy {
public static final String DEFAULT_TEMPLATE = "taxonomy.html";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.condation.cms.api.extensions;

import java.util.Map;

import com.condation.cms.api.Constants;

/*-
* #%L
* cms-api
Expand All @@ -26,6 +30,21 @@

public abstract class TemplateModelExtendingExtensionPoint extends AbstractExtensionPoint{

/**
* deprecated: use @TemplateModelExtendingExtensionPoint.getModel instead
* @param model
*/
@Deprecated(since = "7.3.0", forRemoval = true)
public abstract void extendModel (TemplateEngine.Model model);


public Map<String, Object> getModel () {
TemplateEngine.Model model = new TemplateEngine.Model(null, null);
extendModel(model);
return model.values;
}

public String getNamespace () {
return Constants.DEFAULT_MODULE_NAMESPACE;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.condation.cms.api.extensions;

import java.util.Map;

import com.condation.cms.api.Constants;

/*-
* #%L
* cms-api
Expand Down Expand Up @@ -35,4 +39,13 @@ public abstract class TemplateModelExtendingExtentionPoint extends AbstractExten

public abstract void extendModel (TemplateEngine.Model model);

public Map<String, Object> getModel () {
TemplateEngine.Model model = new TemplateEngine.Model(null, null);
extendModel(model);
return model.values;
}

public String getNamespace () {
return Constants.DEFAULT_MODULE_NAMESPACE;
}
}
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
@@ -1,5 +1,6 @@
package com.condation.cms.content;

import com.condation.cms.api.Constants;
/*-
* #%L
* cms-content
Expand Down Expand Up @@ -139,20 +140,41 @@ 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("node", "meta", new MapAccess(meta));
namespace.add("node", "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);
model.values.put("mediaService", context.get(SiteMediaServiceFeature.class).mediaService());
namespace.add("cms", "mediaService", context.get(SiteMediaServiceFeature.class).mediaService());

model.values.put("taxonomies", context.get(InjectorFeature.class).injector().getInstance(TaxonomyFunction.class));

namespace.add("cms", "taxonomies", context.get(InjectorFeature.class).injector().getInstance(TaxonomyFunction.class));

var theme = context.get(RenderContext.class).theme();
if (theme.empty()) {
model.values.put("messages", context.get(InjectorFeature.class).injector().getInstance(MessageSource.class));
Expand All @@ -161,8 +183,10 @@ public String render(final ReadOnlyFile contentFile, final RequestContext contex
}

model.values.put("hooks", context.get(HookSystemFeature.class).hookSystem());
namespace.add("cms", "hooks", context.get(HookSystemFeature.class).hookSystem());

model.values.put("links", new LinkFunction(context));
namespace.add("cms", "links", new LinkFunction(context));

model.values.put("PREVIEW_MODE", isPreview(context));
model.values.put("DEV_MODE", isDevMode(context));
Expand All @@ -174,17 +198,21 @@ public String render(final ReadOnlyFile contentFile, final RequestContext contex

context.get(TemplateHooks.class).getTemplateSupplier().getRegisterTemplateSupplier().forEach(service -> {
model.values.put(service.name(), service.supplier());
namespace.add(Constants.DEFAULT_MODULE_NAMESPACE, service.name(), service.supplier());
});
context.get(TemplateHooks.class).getTemplateFunctions().getRegisterTemplateFunctions().forEach(service -> {
model.values.put(service.name(), service.function());
namespace.add(Constants.DEFAULT_MODULE_NAMESPACE, service.name(), service.function());
});

extendModel(model);
extendModel(model, namespace);

model.values.put("content",
renderContent(rawContent, context, model)
);
String content = renderContent(rawContent, context, model);
model.values.put("content", content);
namespace.add("node", "content", content);

model.values.putAll(namespace.getNamespaces());

return templates.get().render((String) meta.get("template"), model);
}

Expand Down Expand Up @@ -223,9 +251,27 @@ private boolean isDevMode(final RequestContext context) {
return context.has(IsDevModeFeature.class);
}

private void extendModel(final TemplateEngine.Model model) {
moduleManager.extensions(TemplateModelExtendingExtentionPoint.class).forEach(extensionPoint -> extensionPoint.extendModel(model));
moduleManager.extensions(TemplateModelExtendingExtensionPoint.class).forEach(extensionPoint -> extensionPoint.extendModel(model));
private void extendModel(final TemplateEngine.Model model, Namespace namespace) {
moduleManager.extensions(TemplateModelExtendingExtentionPoint.class).forEach(extensionPoint -> {
var modModel = extensionPoint.getModel();
// deprecated: module extensions on root will be remove in 8.0.0
model.values.putAll(modModel);
modModel.entrySet().forEach(entry -> namespace.add(
extensionPoint.getNamespace(),
entry.getKey(),
entry.getValue()
));
});
moduleManager.extensions(TemplateModelExtendingExtensionPoint.class).forEach(extensionPoint -> {
var modModel = extensionPoint.getModel();
// deprecated: module extensions on root will be remove in 8.0.0
model.values.putAll(modModel);
modModel.entrySet().forEach(entry -> namespace.add(
extensionPoint.getNamespace(),
entry.getKey(),
entry.getValue()
));
});
}

@Override
Expand Down
41 changes: 41 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,41 @@
package com.condation.cms.content;

/*-
* #%L
* cms-content
* %%
* Copyright (C) 2023 - 2024 CondationCMS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

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);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.condation.cms.modules.example;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.condation.cms.api.extensions.TemplateModelExtendingExtensionPoint;
Expand Down Expand Up @@ -40,7 +41,11 @@ public class ExampleTemplateModelExtendingExtensionEndPoint extends TemplateMode

@Override
public void extendModel(TemplateEngine.Model model) {
model.values.put("searcher", new Searcher());
}

@Override
public Map<String, Object> getModel() {
return Map.of("searcher", new Searcher());
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions test-server/hosts/features/site-dev.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[modules]
active = [ "example-module" ]
3 changes: 0 additions & 3 deletions test-server/hosts/features/site-dev.yaml

This file was deleted.

15 changes: 15 additions & 0 deletions test-server/hosts/features/site.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id = "feature-site"
hostname = [ "localhost2" ]
baseurl = "http://localhost2:1010"
language = "en"
test = "Hallo"
theme = "test"

[cache]
content = true

[query.index]
mode = "PERSISTENT"

[modules]
active = [ "forms-module" ]
32 changes: 0 additions & 32 deletions test-server/hosts/features/site.yaml

This file was deleted.

5 changes: 5 additions & 0 deletions test-server/hosts/features/templates/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ <h3>Call ShortCode from template</h3>
[(${shortCodes.call('hello', #{'name': 'CondationCMS'})})]
</div>

<div class="container">
<h3>Test mod-Namespace</h3>
<p th:text="${mod.searcher.search('query').total}"></p>
</div>

<th:block th:replace="libs/fragments.html :: footer"></th:block>

</body>
Expand Down
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="${node.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
2 changes: 1 addition & 1 deletion test-server/themes/demo/templates/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body class="centered">

<div id="content">
<div class="container" th:utext="${content}"></div>
<div class="container" th:utext="${node.content}"></div>
</div>

</body>
Expand Down
2 changes: 1 addition & 1 deletion test-server/themes/parent/templates/blog-entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<div class="row">
<h2 th:utext="${title}"></h2>
<p th:utext="${content}"></p>
<p th:utext="${node.content}"></p>
</div>

<div class="row"
Expand Down
2 changes: 1 addition & 1 deletion test-server/themes/parent/templates/blog.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<h1 th:text="${title}"></h1>
</div>

<div class="row" th:utext="${content}"></div>
<div class="row" th:utext="${node.content}"></div>
<div class="row"
th:with='page = ${nodeList.from("/blog/*").sort("publish_date").reverse(true).page(pageNumber).size(1).list()}'>
<th:block th:each="entry : ${page.items}" data-test="e">
Expand Down
2 changes: 1 addition & 1 deletion test-server/themes/parent/templates/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<nav th:replace="libs/fragments.html :: navigation"></nav>

<div id="content">
<div class="container" th:utext="${content}"></div>
<div class="container" th:utext="${node.content}"></div>

<div class="container" th:if="${sections.containsKey('part')}">
<th:block th:each="part : ${sections.get('part')}">
Expand Down
4 changes: 2 additions & 2 deletions test-server/themes/parent/templates/content.part.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="card mb-3" xmlns:th="http://www.thymeleaf.org">
<div class="card-body">
<h5 class="card-title" th:text="${meta.title}"></h5>
<p class="card-text" th:utext="${content}"></p>
<h5 class="card-title" th:text="${node.meta.title}"></h5>
<p class="card-text" th:utext="${node.content}"></p>
<!--a href="#" class="card-link">readmore</a-->
</div>
</div>
Loading