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
8 changes: 7 additions & 1 deletion cms-api/src/main/java/com/condation/cms/api/hooks/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,23 @@
*/
public enum Hooks {

/* navigation */
NAVIGATION_PATH("system/navigation/%s/path"),
NAVIGATION_LIST("system/navigation/%s/list"),
/* content */
CONTENT_TAGS("system/content/tags"),
CONTENT_FILTER("system/content/filter"),
TEMPLATE_COMPONENT("system/template/component"),
/*query*/
DB_QUERY_OPERATIONS("system/db/query/operations"),
/* scheduler */
SCHEDULER_REGISTER("system/scheduler/register"),
SCHEDULER_REMOVE("system/scheduler/remove"),
/* http */
HTTP_EXTENSION("system/server/http/extension"),
HTTP_ROUTE("system/server/http/route"),
API_ROUTE("system/server/api/route"),
/* Template */
TEMPLATE_COMPONENT("system/template/component"),
TEMPLATE_SUPPLIER("system/template/supplier"),
TEMPLATE_FUNCTION("system/template/function")
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,6 @@ public Optional<ContentResponse> getErrorContent (final RequestContext context)
}

private Optional<ContentResponse> getContent(final RequestContext context, boolean checkVisibility) {
/*
String path;
if (Strings.isNullOrEmpty(context.get(RequestFeature.class).uri())) {
path = "";
} else if (context.get(RequestFeature.class).uri().startsWith("/")) {
// remove leading slash
path = context.get(RequestFeature.class).uri().substring(1);
} else {
path = context.get(RequestFeature.class).uri();
}

var contentBase = db.getReadOnlyFileSystem().contentBase();
var contentPath = contentBase.resolve(path);
ReadOnlyFile contentFile = null;
if (contentPath.exists() && contentPath.isDirectory()) {
// use index.md
var tempFile = contentPath.resolve("index.md");
if (tempFile.exists()) {
contentFile = tempFile;
}
} else {
var temp = contentBase.resolve(path + ".md");
if (temp.exists()) {
contentFile = temp;
}
}
*/

var contentBase = db.getReadOnlyFileSystem().contentBase();
var path = ContentResolvingStrategy.uriToPath(context.get(RequestFeature.class).uri());
Optional<ReadOnlyFile> contentFileOpt = ContentResolvingStrategy.resolve(context.get(RequestFeature.class).uri(), db);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import com.condation.cms.api.Constants;
import com.condation.cms.api.db.ContentNode;
import com.condation.cms.api.feature.features.IsPreviewFeature;
import com.condation.cms.api.request.RequestContextScope;
import com.condation.cms.filesystem.MetaData;
import com.google.common.base.Strings;
import java.util.Arrays;
Expand Down Expand Up @@ -72,6 +74,13 @@ public ConcurrentMap<String, ContentNode> getTree() {
}

public static boolean isVisible (ContentNode node) {

if (RequestContextScope.REQUEST_CONTEXT.isBound()
&& RequestContextScope.REQUEST_CONTEXT.get().has(IsPreviewFeature.class)
&& RequestContextScope.REQUEST_CONTEXT.get().get(IsPreviewFeature.class).mode().equals(com.condation.cms.api.feature.features.IsPreviewFeature.Mode.MANAGER)
) {
return true;
}

if (node == null || node.isSection()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public void startup() throws IOException {
MdcScope.forSite(site.id()).run(() -> {
try {
var host = new VHost(site.id(), site.basePath(), ServerUtil.getPath(Constants.Folders.MODULES), globalInjector);
log.debug("warmup host {}", site.id());
host.warmup();
log.debug("init host {}", site.id());
host.init();
vhosts.add(host);
globalInjector.getInstance(SiteService.class).add(new Site(host.getInjector()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public CacheProvider cacheProvider (ModuleManager moduleManager, SiteProperties
@Provides
@Singleton
public SiteConfigInitializer siteConfigInitializer (Injector injector) {
return new SiteConfigInitializer(injector);
var configInitializer = new SiteConfigInitializer(injector);
return configInitializer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ public TagParser tagParser (Configuration configuration) {
@Provides
@Singleton
public ConfigManagement configurationManagement(SiteCronJobScheduler scheduler, EventBus eventBus) throws IOException {
ConfigManagement cm = ConfigurationFactory.create(hostBase, eventBus, scheduler);

ConfigManagement cm = ConfigurationFactory.create(hostBase, eventBus, scheduler);
return cm;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@
import com.condation.cms.server.handler.media.JettyMediaHandler;
import com.condation.cms.server.handler.module.JettyModuleHandler;
import com.condation.modules.api.ModuleManager;
import com.google.inject.Binding;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provider;
import com.google.inject.name.Names;

import lombok.Getter;
Expand Down Expand Up @@ -166,6 +168,12 @@ public void reload() {
public List<String> hostnames() {
return injector.getInstance(SiteProperties.class).hostnames();
}

public void warmup () {
injector.getAllBindings().values().stream()
.map(Binding::getProvider)
.forEach(Provider::get); // Trigger eager Load
}

public void init() throws IOException {

Expand Down
1 change: 0 additions & 1 deletion cms-templates/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<dependency>
<groupId>com.condation.cms</groupId>
<artifactId>cms-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.condation.cms.templates.functions.JexlTemplateFunction;
import com.condation.cms.templates.functions.impl.DateFunction;
import com.condation.cms.templates.functions.impl.NodeFunction;
import com.condation.cms.templates.parser.ASTNode;
import com.condation.cms.templates.renderer.Renderer;
import com.condation.cms.templates.renderer.ScopeStack;
Expand Down Expand Up @@ -72,7 +73,8 @@ public void evaluate (ScopeStack scopes, Writer writer, DynamicConfiguration dyn

private ScopeStack createScope (Map<String, Object> context, DynamicConfiguration dynamicConfiguration) {
var scope = new ScopeStack(context);
scope.setVariable("date", new JexlTemplateFunction(new DateFunction()));
scope.setVariable(DateFunction.NAME, new JexlTemplateFunction(new DateFunction()));
scope.setVariable(NodeFunction.NAME, new JexlTemplateFunction(new NodeFunction(dynamicConfiguration.requestContext())));

dynamicConfiguration.templateFunctions().forEach(tf -> {
scope.setVariable(tf.name(), new JexlTemplateFunction(tf));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@
*/
public class DateFunction implements TemplateFunction {

public static final String NAME = "date";

@Override
public Object invoke(Object... params) {
return new Date();
}

@Override
public String name() {
return "date";
return NAME;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.condation.cms.templates.functions.impl;

/*-
* #%L
* cms-templates
* %%
* Copyright (C) 2023 - 2026 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 com.condation.cms.api.content.MapAccess;
import com.condation.cms.api.db.ContentNode;
import com.condation.cms.api.db.DB;
import com.condation.cms.api.db.cms.ReadOnlyFile;
import com.condation.cms.api.feature.features.DBFeature;
import com.condation.cms.api.feature.features.InjectorFeature;
import com.condation.cms.api.feature.features.RequestFeature;
import com.condation.cms.api.request.RequestContext;
import com.condation.cms.api.utils.PathUtil;
import com.condation.cms.core.content.ContentResolvingStrategy;
import com.condation.cms.templates.functions.TemplateFunction;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import lombok.RequiredArgsConstructor;

/**
*
* @author thorstenmarx
*/
@RequiredArgsConstructor
public class NodeFunction implements TemplateFunction {

public static final String NAME = "select_node";

private final RequestContext requestContext;

@Override
public Object invoke(Object... params) {

if (params == null || params.length == 0 ) {
return null;
}
if (!(params[0] instanceof String)) {
return null;
}
String uri = ContentResolvingStrategy.uriToPath((String)params[0]);

var db = requestContext.get(InjectorFeature.class).injector().getInstance(DB.class);
var contentBase = db.getReadOnlyFileSystem().contentBase();

Optional<ReadOnlyFile> contentFileOpt = ContentResolvingStrategy.resolve(uri, db);

if (contentFileOpt.isPresent()) {
var node_uri = PathUtil.toRelativeFile(contentFileOpt.get(), contentBase);
final Optional<ContentNode> nodeByUri = db.getContent().byUri(node_uri);
if (nodeByUri.isPresent()) {
return Map.of(
"meta", new MapAccess(nodeByUri.get().data()),
"uri", PathUtil.toURL(contentFileOpt.get(), contentBase)
);
}
}

return null;
}

@Override
public String name() {
return NAME;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void setVariable(String name, Object value) {
public Optional<Object> getVariable(String name) {
for (Map<String, Object> scope : scopes) {
if (scope.containsKey(name)) {
return Optional.of(scope.get(name));
return Optional.ofNullable(scope.get(name));
}
}
if (parent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.condation.cms.templates.exceptions.RenderException;
import com.condation.cms.templates.loaders.StringTemplateLoader;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

/**
Expand Down
4 changes: 4 additions & 0 deletions test-server/hosts/demo/content/.technical/globals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
name: "Global Values"
version: "v2026.01"
---
4 changes: 3 additions & 1 deletion test-server/themes/demo/templates/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

<body class="centered">
<div id="content">
<div class="container">
<div class="container"
{{ ext.ui.toolbar("main", "main", ["editContent"]) | raw }}
>
{{ node.content | raw}}
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions test-server/themes/demo/templates/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ <h4>template function test</h4>

</div>

<div>
<h3>Test Node references</h3>
<div>
{% assign globals = select_node("/.technical/globals") %}
{% if !empty(globals) %}
Version: {{ globals.meta.get('version') }} <br/>
{% else %}
Globals node not found! <br/>
{% endif %}
</div>
</div>

</body>


Expand Down