Skip to content

Commit

Permalink
#76 throw error if template engines does not match (#78)
Browse files Browse the repository at this point in the history
* #76 throw error if template engines does not match

* next release version

---------
  • Loading branch information
thmarx authored Nov 17, 2023
1 parent 4c1b235 commit 9c0a91d
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cms-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>cms-api</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String hostname () {
}

public String markdownEngine () {
return (String)getSubMap("markdown").getOrDefault("engine", "flexmark");
return (String)getSubMap("markdown").get("engine");
}

public String theme () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ThemeProperties (final Map<String, Object> properties) {
}

public String templateEngine () {
return (String)getSubMap("template").getOrDefault("engine", "freemarker");
return (String)getSubMap("template").get("engine");
}

public List<String> activeModules () {
Expand Down
2 changes: 1 addition & 1 deletion cms-filesystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>cms-filesystem</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 0 additions & 2 deletions cms-server/hosts/demo/site.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
hostname: localhost
baseurl: "http://localhost:1010"
language: en
template:
engine: thymeleaf
markdown:
engine: markedjs
theme: default
Expand Down
Binary file not shown.
4 changes: 0 additions & 4 deletions cms-server/modules/example-module/module.properties

This file was deleted.

2 changes: 1 addition & 1 deletion cms-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>cms-server</artifactId>
<packaging>jar</packaging>
Expand Down
39 changes: 29 additions & 10 deletions cms-server/src/main/java/com/github/thmarx/cms/server/VHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class VHost {

@Getter
private String hostname;

@Getter
private Theme theme;

Expand All @@ -88,9 +88,9 @@ public class VHost {
protected final ServerProperties serverProperties;

protected RequestContextFactory requestContextFactory;

private final Path hostBase;

public VHost(final Path hostBase, final ServerProperties serverProperties) {
this.hostBase = hostBase;
this.eventBus = new DefaultEventBus();
Expand All @@ -117,9 +117,9 @@ private Theme loadTheme() throws IOException {
}

public void init(Path modules) throws IOException {

contentParser = new ContentParser();

contentParser = new ContentParser();

this.fileSystem = new FileSystem(hostBase, eventBus, (file) -> {
try {
return contentParser.parseMeta(file);
Expand All @@ -135,6 +135,14 @@ public void init(Path modules) throws IOException {

theme = loadTheme();

try {
getTemplateEngine();
} catch (Exception e) {
log.error(null , e);
fileSystem.shutdown();
throw e;
}

var classLoader = new ModuleAPIClassLoader(ClassLoader.getSystemClassLoader(),
List.of(
"org.slf4j",
Expand Down Expand Up @@ -168,15 +176,15 @@ public void init(Path modules) throws IOException {
contentResolver = new ContentResolver(contentBase, contentRenderer, fileSystem);

this.requestContextFactory = new RequestContextFactory(() -> resolveMarkdownRenderer(), extensionManager, getTheme());

this.moduleManager.initModules();

List<String> activeModules = new ArrayList<>();
activeModules.addAll(siteProperties.activeModules());
if (!theme.empty()) {
activeModules.addAll(theme.properties().activeModules());
activeModules.addAll(theme.properties().activeModules());
}

activeModules.stream()
.filter(module_id -> moduleManager.getModuleIds().contains(module_id))
.forEach(module_id -> {
Expand Down Expand Up @@ -209,9 +217,20 @@ public void init(Path modules) throws IOException {
});
}

private String getTemplateEngine() {
var engine = this.siteProperties.templateEngine();

var theme_engine = getTheme().properties().templateEngine();
if (theme_engine != null && engine != null && !theme_engine.equals(engine)) {
throw new RuntimeException("site template engine does not match theme template engine");
}

return theme_engine != null ? theme_engine : engine;
}

protected TemplateEngine resolveTemplateEngine() {
if (this.templateEngine == null) {
var engine = this.siteProperties.templateEngine();
var engine = getTemplateEngine();

List<TemplateEngineProviderExtentionPoint> extensions = moduleManager.extensions(TemplateEngineProviderExtentionPoint.class);
Optional<TemplateEngineProviderExtentionPoint> extOpt = extensions.stream().filter((ext) -> ext.getName().equals(engine)).findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
import com.github.thmarx.cms.api.ServerProperties;
import com.github.thmarx.cms.api.ThemeProperties;
import com.github.thmarx.cms.request.RequestContextFactory;
import com.github.thmarx.cms.server.jetty.handler.JettyDefaultHandler;
import com.github.thmarx.cms.server.jetty.handler.JettyExtensionHandler;
import com.github.thmarx.cms.server.VHost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -40,7 +41,7 @@
@RequiredArgsConstructor
public class DefaultTheme implements Theme {

public static final Theme EMPTY = new DefaultTheme(null, null, true);
public static final Theme EMPTY = new DefaultTheme(null, new ThemeProperties(Collections.emptyMap()), true);

private final Path themePath;
private final ThemeProperties properties;
Expand Down
2 changes: 1 addition & 1 deletion modules/example-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>example-module</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion modules/flexmark-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>flexmark-module</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion modules/freemarker-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>freemarker-module</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion modules/markedjs-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>markedjs-module</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion modules/pebble-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>pebble-module</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion modules/pug-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>pug-module</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion modules/search-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>search-module</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion modules/thymeleaf-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
</parent>
<artifactId>thymeleaf-module</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>2.9.0-SNAPSHOT</version>
<version>2.9.0</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

0 comments on commit 9c0a91d

Please sign in to comment.