Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2bc3d18
simple template engine basics
thmarx Nov 10, 2024
00a8ee6
add basic template syntax
Nov 11, 2024
f5b7409
test for multiline short code
thmarx Nov 13, 2024
b2e2a75
Merge branch 'default_template_engine' of github.com:thmarx/cms-serve…
thmarx Nov 13, 2024
dce8b99
Merge branch 'CondationCMS:main' into default_template_engine
thmarx Nov 19, 2024
7cab450
add support for comments
thmarx Nov 21, 2024
64534d4
update some token processing
Nov 22, 2024
f0a643e
fix parser to detect and tags
thmarx Nov 24, 2024
f44db8f
implement template class
thmarx Nov 24, 2024
748f64f
add simple parsing and rendering
Nov 25, 2024
65dade7
update if-elseif-else
Nov 25, 2024
a644c80
for tag added
Nov 26, 2024
923c714
implement set and include
Nov 26, 2024
2e002a5
support for macros
Nov 27, 2024
8c462b3
add parent scope vor macros
Nov 27, 2024
67cc6e0
remoe legacy test
Nov 27, 2024
372da06
add some tests
Nov 27, 2024
edf146d
extract CharacterSTream from lexer
Nov 28, 2024
63eb88c
Merge branch 'CondationCMS:main' into default_template_engine
thmarx Nov 28, 2024
c5fab98
add variable filter implementation
Nov 28, 2024
961f44f
introduce filter pipeline
Nov 28, 2024
342a05f
add import statement
Nov 29, 2024
351e546
fix test
Nov 29, 2024
386380c
file loader
Nov 29, 2024
55c8da7
Merge branch 'CondationCMS:main' into default_template_engine
thmarx Nov 29, 2024
ef54c65
core refactoring
thmarx Nov 29, 2024
85259b6
core refactoring
thmarx Nov 29, 2024
49ff4cd
add simple benchmark for templates
thmarx Nov 30, 2024
305c9c1
refactor set to assign tag
thmarx Dec 1, 2024
04a1b66
add layout block extends and block
thmarx Dec 1, 2024
04d6dea
more template module to root modules
Dec 2, 2024
32f77e5
refactoring and stabilaziation
Dec 2, 2024
05a54a0
refactoring
Dec 3, 2024
70a84d0
refactoring
Dec 3, 2024
01c7e1a
Merge branch 'CondationCMS:main' into default_template_engine
thmarx Dec 3, 2024
d1dc43a
lexer optimizaqtions, benchmark
Dec 4, 2024
47135c5
Merge origin/default_template_engine into default_template_engine
Dec 4, 2024
73c9131
use system template engine for default
Dec 4, 2024
01ac7e1
update engine on theme change
Dec 5, 2024
77f87a4
add test for prod mode
Dec 5, 2024
3f3595d
use expression
thmarx Dec 5, 2024
d024365
fix lexer and record resolving
Dec 6, 2024
f6c24fa
remove unused import
Dec 6, 2024
dc7d606
render template from string
Dec 7, 2024
96a0fab
merge main
Dec 9, 2024
dd5d50f
update exceptions
Dec 9, 2024
468b3a7
Merge branch 'CondationCMS:main' into default_template_engine
thmarx Dec 9, 2024
1802d3c
optimized replace implementation
Dec 10, 2024
15689c7
use first matching config
Dec 10, 2024
ec0789c
Merge branch 'performance_improvments' into default_template_engine
Dec 10, 2024
c6a76ed
remove imports
Dec 10, 2024
79cc225
organize imports
Dec 10, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.condation.cms.api.feature.features;

/*-
* #%L
* cms-api
* %%
* 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 com.condation.cms.api.annotations.FeatureScope;
import com.condation.cms.api.cache.CacheManager;
import com.condation.cms.api.feature.Feature;

/**
*
* @author t.marx
*/
@FeatureScope(FeatureScope.Scope.MODULE)
public record CacheManagerFeature (CacheManager cacheManager) implements Feature {
}
44 changes: 42 additions & 2 deletions cms-api/src/main/java/com/condation/cms/api/utils/MapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
*
Expand All @@ -49,7 +50,7 @@ public static Object getValue(final Map<String, Object> map, final String field)

public static <T> T getValue(final Map<String, Object> map, final String field, final T defaultValue) {
if (!field.contains(".")) {
return (T)map.getOrDefault(field, defaultValue);
return (T) map.getOrDefault(field, defaultValue);
}
String[] keys = field.split("\\.");
Map<String, Object> subMap = map;
Expand Down Expand Up @@ -107,4 +108,43 @@ public static void deepMerge(
}
}
}

@SuppressWarnings("unchecked")
public static Map<String, Object> deepUnmodifiableMap(Map<String, Object> original) {
return original.entrySet().stream()
.collect(Collectors.toUnmodifiableMap(
Map.Entry::getKey,
entry -> {
Object value = entry.getValue();
if (value instanceof Map) {
// Rekursiver Aufruf für verschachtelte Maps
return deepUnmodifiableMap((Map<String, Object>) value);
} else if (value instanceof List) {
// Rekursiver Aufruf für Listen
return deepUnmodifiableList((List<Object>) value);
} else {
// Andere Objekte bleiben unverändert
return value;
}
}
));
}

@SuppressWarnings("unchecked")
private static List<Object> deepUnmodifiableList(List<Object> original) {
return original.stream()
.map(value -> {
if (value instanceof Map) {
// Rekursiver Aufruf für verschachtelte Maps
return deepUnmodifiableMap((Map<String, Object>) value);
} else if (value instanceof List) {
// Rekursiver Aufruf für verschachtelte Listen
return deepUnmodifiableList((List<Object>) value);
} else {
// Andere Objekte bleiben unverändert
return value;
}
})
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.google.common.base.Strings;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
*
Expand All @@ -36,35 +36,44 @@ public class StringUtils {
private static final String AMP_PLACEHOLDER = "AMP#PLACE#HOLDER";

static {
ESCAPE.put("\\\\#", AMP_PLACEHOLDER + "#35;");
ESCAPE.put("\\\\\\*", AMP_PLACEHOLDER + "#42;");
ESCAPE.put("\\\\`", AMP_PLACEHOLDER + "#96;");
ESCAPE.put("\\\\_", AMP_PLACEHOLDER + "#95;");
ESCAPE.put("\\\\\\{", AMP_PLACEHOLDER + "#123;");
ESCAPE.put("\\\\\\}", AMP_PLACEHOLDER + "#125;");
ESCAPE.put("\\\\\\[", AMP_PLACEHOLDER + "#91;");
ESCAPE.put("\\\\\\]", AMP_PLACEHOLDER + "#93;");
ESCAPE.put("\\\\<", AMP_PLACEHOLDER + "#60;");
ESCAPE.put("\\\\>", AMP_PLACEHOLDER + "#62;");
ESCAPE.put("\\\\\\(", AMP_PLACEHOLDER + "#40;");
ESCAPE.put("\\\\\\)", AMP_PLACEHOLDER + "#41;");
ESCAPE.put("\\\\\\+", AMP_PLACEHOLDER + "#43;");
ESCAPE.put("\\\\-", AMP_PLACEHOLDER + "#45;");
ESCAPE.put("\\\\\\.", AMP_PLACEHOLDER + "#46;");
ESCAPE.put("\\\\!", AMP_PLACEHOLDER + "#33;");
ESCAPE.put("\\\\\\|", AMP_PLACEHOLDER + "#124;");
ESCAPE.put("\\#", AMP_PLACEHOLDER + "#35;");
ESCAPE.put("\\*", AMP_PLACEHOLDER + "#42;");
ESCAPE.put("\\`", AMP_PLACEHOLDER + "#96;");
ESCAPE.put("\\_", AMP_PLACEHOLDER + "#95;");
ESCAPE.put("\\{", AMP_PLACEHOLDER + "#123;");
ESCAPE.put("\\}", AMP_PLACEHOLDER + "#125;");
ESCAPE.put("\\[", AMP_PLACEHOLDER + "#91;");
ESCAPE.put("\\]", AMP_PLACEHOLDER + "#93;");
ESCAPE.put("\\<", AMP_PLACEHOLDER + "#60;");
ESCAPE.put("\\>", AMP_PLACEHOLDER + "#62;");
ESCAPE.put("\\(", AMP_PLACEHOLDER + "#40;");
ESCAPE.put("\\)", AMP_PLACEHOLDER + "#41;");
ESCAPE.put("\\+", AMP_PLACEHOLDER + "#43;");
ESCAPE.put("\\-", AMP_PLACEHOLDER + "#45;");
ESCAPE.put("\\.", AMP_PLACEHOLDER + "#46;");
ESCAPE.put("\\!", AMP_PLACEHOLDER + "#33;");
ESCAPE.put("\\|", AMP_PLACEHOLDER + "#124;");
}

public static String unescape(String html) {
return html.replaceAll(AMP_PLACEHOLDER, "&");
}

public static String escape(String md) {
AtomicReference<String> escaped = new AtomicReference<>(md);
ESCAPE.entrySet().forEach(entry -> {
escaped.updateAndGet(value -> value.replaceAll(entry.getKey(), entry.getValue()));
if (Strings.isNullOrEmpty(md)) {
return md;
}
StringBuilder escaped = new StringBuilder(md);

ESCAPE.forEach((key, value) -> {
int index = escaped.indexOf(key);
while (index != -1) {
escaped.replace(index, index + key.length(), value);
index = escaped.indexOf(key, index + value.length());
}
});
return escaped.get();

return escaped.toString();
}

public static String removeLeadingPipe(String s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* #L%
*/
import com.condation.cms.api.configuration.configs.SiteConfiguration;
import com.condation.cms.api.feature.Feature;
import com.condation.cms.api.feature.features.ConfigurationFeature;
import com.condation.cms.api.feature.features.TemplateEngineFeature;
import com.condation.cms.api.hooks.FilterContext;
Expand All @@ -34,8 +33,6 @@
import java.io.IOException;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public void namespace() {
result = tagParser.parse("[[ns1:print message='Hello CondationCMS' /]]", tagMap);
Assertions.assertThat(result).isEqualTo("message: Hello CondationCMS");
}
@Test

@Test
public void multiline () {
String content = """
[[content]]
Expand Down
15 changes: 0 additions & 15 deletions cms-core/configs/server.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.condation.cms.api.cache.CacheManager;
import com.condation.cms.api.cache.CacheProvider;
import com.condation.cms.api.cache.ICache;
import java.io.Serializable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.condation.cms.api.db.DB;
import com.condation.cms.core.configuration.configs.SimpleConfiguration;
import com.condation.cms.api.eventbus.EventBus;
import com.condation.cms.api.scheduler.CronJobScheduler;
Expand Down Expand Up @@ -111,8 +110,8 @@ private static SimpleConfiguration serverConfiguration(EventBus eventBus) throws
return SimpleConfiguration.builder(eventBus)
.id("server")
.reloadStrategy(new NoReload())
.addSource(YamlConfigSource.build(ServerUtil.getPath("server.yaml")))
.addSource(TomlConfigSource.build(ServerUtil.getPath("server.toml")))
.addSource(YamlConfigSource.build(ServerUtil.getPath("server.yaml")))
.build();
}

Expand Down Expand Up @@ -143,8 +142,8 @@ public static SimpleConfiguration siteConfiguration(String env, Path hostBase) t
private static SimpleConfiguration siteConfiguration(EventBus eventBus, String env, Path siteBase, ReloadStrategy reloadStrategy) throws IOException {

List<ConfigSource> siteSources = new ArrayList<>();
siteSources.add(YamlConfigSource.build(siteBase.resolve("site.yaml")));
siteSources.add(TomlConfigSource.build(siteBase.resolve("site.toml")));
siteSources.add(YamlConfigSource.build(siteBase.resolve("site.yaml")));

var envFile = siteBase.resolve("site-%s.yaml".formatted(env));
if (Files.exists(envFile)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.condation.cms.core.configuration.reload.NoReload;
import com.condation.cms.api.eventbus.events.ConfigurationReloadEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -156,14 +157,15 @@ public Long getLong (String field, long defaultValue) {
}

public Map<String, Object> getMap (String field) {
Map<String, Object> result = new HashMap<>();
sources.stream()
var configSource = sources.stream()
.filter(ConfigSource::exists)
.map(config -> config.getMap(field))
.forEach(sourceMap -> {
MapUtil.deepMerge(result, sourceMap);
});
return result;
.findFirst();

if (configSource.isPresent()) {
return MapUtil.deepUnmodifiableMap(configSource.get().getMap(field));
}

return Collections.emptyMap();
}

public <T> T get(String field, Class<T> aClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.tomlj.Toml;
import org.tomlj.TomlArray;
import org.tomlj.TomlPosition;
import org.tomlj.TomlTable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ public void test_env() {

Assertions.assertThat(env).isEqualTo("prod");
}

@Test
public void test_from_yaml() {
var env = configuration.getString("test");

Assertions.assertThat(env).isEqualTo("only in yaml");
}

@Test
public void test_reload () throws InterruptedException, IOException {
Expand Down
Loading