Skip to content

Commit

Permalink
12 themes (#73)
Browse files Browse the repository at this point in the history
* #12 refactoring properties

* #12 add simple template theme support

* #12 template loader for themes, priority in site templates

* #12 add theme support

* #12 add theme support

* #12 add theme support

* #12 add theme support

* #12 add theme support

* #12 theme example

* #12 add js and style to theme rendering

* #12 load extensions from theme

* #12 some code clean up

* #12 some code clean up

* #12 more code cleanup and simplification

* add changelog

* Update README.md

* #12 update readme

* update release version

* prepare release 2.7.0

---------

Co-authored-by: Thorsten Marx <t.marx@eggheads.de>
  • Loading branch information
thmarx and Thorsten Marx authored Nov 14, 2023
1 parent 271b3ec commit 636b5c5
Show file tree
Hide file tree
Showing 122 changed files with 2,240 additions and 1,391 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ target/
.vscode/
cms-server/hosts/marx-software
cms-server/hosts/demo/modules_data/search-module/index
cms-server/hosts/theme-demo/modules_data/search-module/index
cms-server/modules/flexmark-module
cms-server/modules/markedjs-module
cms-server/modules/pebble-module
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# java based flat file cms
# cms

cms is a simple java based flat file content management system.
see wiki for more information: [wiki](https://github.com/thmarx/cms/wiki)


# changelog

## 2.7.0

* theme support [#12](https://github.com/thmarx/cms/issues/12)
* legacy server implementation removed [#68](https://github.com/thmarx/cms/issues/68)
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>v2.7.0-SNAPSHOT</version>
<version>2.7.0</version>
</parent>
<artifactId>cms-api</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
*/

import com.github.thmarx.cms.api.eventbus.EventBus;
import com.github.thmarx.cms.api.theme.Theme;
import com.github.thmarx.modules.api.Context;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Function;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -46,4 +46,6 @@ public class CMSModuleContext implements Context {
private final EventBus eventBus;
@Getter
private final BiFunction<String, Map<String, List<String>>, Optional<String>> renderContentFunction;
@Getter
private final Theme theme;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public static class MetaFields {
public static final String MENU_TITLE = "title";
}

public static class Folders {
public static final String CONTENT = "content/";
public static final String TEMPLATES = "templates/";
public static final String ASSETS = "assets/";
public static final String EXTENSIONS = "extensions/";
public static final String MODULES = "modules/";
}

public static final String SPLIT_PATH_PATTERN = Pattern.quote("/");

public static final Pattern SECTION_PATTERN = Pattern.compile("\\w+[a-zA-Z0-9-]*\\.(?<section>[a-zA-Z0-9]+[a-zA-Z0-9-]*)\\.md");
Expand Down
73 changes: 73 additions & 0 deletions cms-api/src/main/java/com/github/thmarx/cms/api/Media.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.github.thmarx.cms.api;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 Marx-Software
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

/**
*
* @author thmar
*/
public class Media {

public enum Format {
PNG,
JPEG,
WEBP;
}

public static Format format4String(final String format) {
return switch (format) {
case "webp" ->
Format.WEBP;
case "jpeg" ->
Format.JPEG;
case "png" ->
Format.PNG;
default ->
throw new RuntimeException("unknown image format");
};
}

public static String mime4Format(final Format format) {
return switch (format) {
case JPEG ->
"image/jpeg";
case PNG ->
"image/png";
case WEBP ->
"image/webp";
default ->
throw new RuntimeException("unknown image format");
};
}

public static String fileending4Format(final Format format) {
return switch (format) {
case JPEG ->
".jpeg";
case PNG ->
".png";
case WEBP ->
".webp";
default ->
throw new RuntimeException("unknown image format");
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,23 @@
* #L%
*/

import java.util.Collections;
import java.nio.file.Path;
import java.util.Map;
import lombok.RequiredArgsConstructor;

/**
*
* @author t.marx
*/
@RequiredArgsConstructor
public class ServerProperties {
public class ServerProperties extends YamlProperties {

private final Map<String, Object> properties;
public ServerProperties (final Map<String, Object> properties) {
super(properties);
}

public boolean dev () {
return (Boolean) properties.getOrDefault("dev", true);
}

private Map<String, Object> getSubMap (final String name) {
return (Map<String, Object>) properties.getOrDefault(name, Collections.emptyMap());
}

public String serverEngine () {
return (String)getSubMap("server").getOrDefault("engine", "jetty");
}
Expand All @@ -50,4 +46,8 @@ public String serverIp () {
public int serverPort () {
return (int)getSubMap("server").getOrDefault("port", 8080);
}

public Path getThemesFolder () {
return Path.of("themes/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,27 @@
* #L%
*/

import java.util.Collections;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;

/**
*
* @author t.marx
*/
@RequiredArgsConstructor
public class SiteProperties {
public class SiteProperties extends ThemeProperties {

private final Map<String, Object> properties;
public SiteProperties (final Map<String, Object> properties) {
super(properties);
}

public String hostname () {
return (String) properties.getOrDefault("hostname", "localhost");
}

public Object get (final String name) {
return properties.get(name);
}
public <T> T getOrDefault (final String name, final T defaultValue) {
return (T)properties.getOrDefault(name, defaultValue);
}

private Map<String, Object> getSubMap (final String name) {
return (Map<String, Object>) properties.getOrDefault(name, Collections.emptyMap());
}

public String templateEngine () {
return (String)getSubMap("template").getOrDefault("engine", "freemarker");
}
public String markdownEngine () {
return (String)getSubMap("markdown").getOrDefault("engine", "flexmark");
}
public List<String> activeModules () {
return (List<String>)getSubMap("modules").getOrDefault("active", List.of());

public String theme () {
return (String) properties.get("theme");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.github.thmarx.cms.api;

/*-
* #%L
* cms-server
* %%
* Copyright (C) 2023 Marx-Software
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
*
* @author t.marx
*/
public class ThemeProperties extends YamlProperties {

public ThemeProperties (final Map<String, Object> properties) {
super(properties);
}

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

public List<String> activeModules () {
return (List<String>)getSubMap("modules").getOrDefault("active", List.of());
}

public Map<String, MediaFormat> getMediaFormats() {
Map<String, MediaFormat> mediaFormats = new HashMap<>();
Map<String, Object> media = (Map<String, Object>) properties.getOrDefault("media", Collections.emptyMap());
List<Map<String, Object>> formats = (List<Map<String, Object>>) media.getOrDefault("formats", Collections.emptyList());
formats.forEach(map -> {
var mediaFormat = new MediaFormat(
(String) map.get("name"),
(int) map.get("width"),
(int) map.get("height"),
Media.format4String((String) map.get("format")),
(boolean) map.get("compression")
);
mediaFormats.put(mediaFormat.name(), mediaFormat);
});

return mediaFormats;
}

public static record MediaFormat(String name, int width, int height, Media.Format format, boolean compression) {
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.thmarx.cms.server.undertow.extension;
package com.github.thmarx.cms.api;

/*-
* #%L
* cms-server
* cms-api
* %%
* Copyright (C) 2023 Marx-Software
* %%
Expand All @@ -20,24 +20,31 @@
* #L%
*/

import com.github.thmarx.cms.api.extensions.http.ExtensionHttpHandler;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import lombok.RequiredArgsConstructor;
import java.util.Collections;
import java.util.Map;

/**
*
* @author t.marx
* @author thmar
*/
@RequiredArgsConstructor
@Deprecated(since = "2.5.0")
public class UndertowHttpHandlerWrapper implements HttpHandler {
public class YamlProperties {

private final ExtensionHttpHandler handler;
protected final Map<String, Object> properties;

protected YamlProperties (final Map<String, Object> properties) {
this.properties = properties;
}

@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
handler.execute(new UndertowRequest(exchange), new UndertowResponse(exchange));
public Object get(final String name) {
return properties.get(name);
}

public <T> T getOrDefault(final String name, final T defaultValue) {
return (T) properties.getOrDefault(name, defaultValue);
}

protected Map<String, Object> getSubMap(final String name) {
return (Map<String, Object>) properties.getOrDefault(name, Collections.emptyMap());
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.thmarx.cms.markdown.home.bb;
package com.github.thmarx.cms.api.theme;

/*-
* #%L
* cms-server
* cms-api
* %%
* Copyright (C) 2023 Marx-Software
* %%
Expand All @@ -24,14 +24,8 @@
*
* @author t.marx
*/
class OpenTag {

String tag;
String html;

OpenTag(String tag, String html) {
this.tag = tag;
this.html = html;
}
public interface Assets {
void addCss (final String css);

void addJs (final String js);
}
Loading

0 comments on commit 636b5c5

Please sign in to comment.