Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ cms-content/src/test/resources/site/data
integration-tests/hosts/test/data
/modules/example-module/src/main/ts/node_modules/
/modules/example-module/src/main/ts/pnpm-lock.yaml
*.jfr
*.jfr
/modules/ui-module/src/main/ts/node_modules
12 changes: 6 additions & 6 deletions cms-api/src/main/java/com/condation/cms/api/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ public static class ContentTypes {

public static final Pattern TAXONOMY_VALUE = Pattern.compile("taxonomy\\.([a-zA-Z0-9-]+)\\.yaml");

public static final Pattern SECTION_PATTERN = Pattern.compile("\\w+\\.(?<section>[a-zA-Z0-9-]+)\\.md");
public static final Pattern SLOT_ITEM_PATTERN = Pattern.compile("\\w+\\.(?<slot>[a-zA-Z0-9-]+)\\.md");

public static final Function<String, Pattern> SECTION_OF_PATTERN = (fileName) -> {
return Pattern.compile("%s\\.(?<section>[a-zA-Z0-9-]+)\\.md".formatted(Pattern.quote(fileName)));
public static final Function<String, Pattern> SLOT_ITEM_OF_PATTERN = (fileName) -> {
return Pattern.compile("%s\\.(?<slot>[a-zA-Z0-9-]+)\\.md".formatted(Pattern.quote(fileName)));
};

public static final Pattern SECTION_NAMED_PATTERN = Pattern.compile("[\\w-]+\\.(?<section>[a-zA-Z0-9-]+)\\.(?<id>[\\w-]+)\\.md");
public static final Pattern SLOT_ITEM_NAMED_PATTERN = Pattern.compile("[\\w-]+\\.(?<slot>[a-zA-Z0-9-]+)\\.(?<id>[\\w-]+)\\.md");

public static final Function<String, Pattern> SECTION_NAMED_OF_PATTERN = (fileName) -> {
public static final Function<String, Pattern> SLOT_ITEM_NAMED_OF_PATTERN = (fileName) -> {
return Pattern.compile("%s\\.[a-zA-Z0-9-]+\\.[a-zA-Z0-9-]+\\.md".formatted(Pattern.quote(fileName)));
};

public static final int DEFAULT_SECTION_LAYOUT_ORDER = 0;
public static final int DEFAULT_SLOT_ITEM_LAYOUT_ORDER = 0;
public static final double DEFAULT_MENU_POSITION = 1000f;
public static final boolean DEFAULT_MENU_VISIBILITY = true;
public static final int DEFAULT_EXCERPT_LENGTH = 200;
Expand Down
11 changes: 11 additions & 0 deletions cms-api/src/main/java/com/condation/cms/api/content/MapAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Set;

import com.condation.cms.api.utils.MapUtil;
import com.google.common.base.Strings;

import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -53,6 +54,16 @@ public boolean containsKey(Object key) {
return MapUtil.getValue(wrapped, (String)key) != null;
}

public boolean empty(Object key) {
var value = MapUtil.getValue(wrapped, (String)key);

if (value instanceof String stringValue) {
return Strings.isNullOrEmpty(stringValue);
}

return value == null;
}

@Override
public boolean containsValue(Object value) {
throw new UnsupportedOperationException("Unimplemented method 'containsValue'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface Content {

boolean isVisible (ContentNode node);

List<ContentNode> listSections(final ReadOnlyFile contentFile);
List<ContentNode> listSlotItems(final ReadOnlyFile contentFile);

List<ContentNode> listContent(final ReadOnlyFile base, final String start);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.condation.cms.api.request.RequestContextScope;
import com.condation.cms.api.utils.DateRange;
import com.condation.cms.api.utils.MapUtil;
import com.condation.cms.api.utils.SectionUtil;
import com.condation.cms.api.utils.SlotUtil;
import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDate;
Expand Down Expand Up @@ -124,8 +124,8 @@ public boolean isVisible() {
return DateRange.isNowWithin(publish_date, unpublish_date);
}

public boolean isSection() {
return SectionUtil.isSection(name);
public boolean isSlotItem() {
return SlotUtil.isSlotItem(name);
}

public boolean isRedirect() {
Expand Down
4 changes: 2 additions & 2 deletions cms-api/src/main/java/com/condation/cms/api/db/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* #L%
*/

import com.condation.cms.api.db.cms.ReadyOnlyFileSystem;
import com.condation.cms.api.db.taxonomy.Taxonomies;
import com.condation.cms.api.db.cms.ReadOnlyFileSystem;


/**
Expand All @@ -33,7 +33,7 @@ public interface DB extends AutoCloseable{

public DBFileSystem getFileSystem();

public ReadyOnlyFileSystem getReadOnlyFileSystem();
public ReadOnlyFileSystem getReadOnlyFileSystem();

public Content getContent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author t.marx
*/
public interface ReadyOnlyFileSystem {
public interface ReadOnlyFileSystem {

/**
* Resolves a file if it is a child of the host base directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @author t.marx
*/
@RequiredArgsConstructor
public class WrappedReadOnlyFileSystem implements ReadyOnlyFileSystem {
public class WrappedReadOnlyFileSystem implements ReadOnlyFileSystem {

private final DBFileSystem dbFileSytem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ContentTypes {

public Set<PageTemplate> pageTemplates = new HashSet();

public Set<SectionTemplate> sectionTemplates = new HashSet<>();
public Set<SlotItemTemplate> slotItemTemplates = new HashSet<>();

public Set<ListItemType> listItemTypes = new HashSet<>();

Expand All @@ -55,21 +55,21 @@ public void registerPageTemplate(Map<String, Object> pageTemplate) {
pageTemplates.add(new PageTemplate(pageTemplate));
}

public void registerSectionTemplate(Map<String, Object> sectionTempate) {
sectionTemplates.add(new SectionTemplate(sectionTempate));
public void registerSlotItemTemplate(Map<String, Object> slotItemTemplate) {
slotItemTemplates.add(new SlotItemTemplate(slotItemTemplate));
}

public Set<PageTemplate> getPageTemplates () {
return new HashSet<>(pageTemplates);
}

public Set<SectionTemplate> getSectionTemplates (String section) {
return sectionTemplates.stream()
.filter(template -> template.section().equals(section))
public Set<SlotItemTemplate> getSlotItemTemplates (String slot) {
return slotItemTemplates.stream()
.filter(template -> template.slot().equals(slot))
.collect(Collectors.toSet());
}
public Set<SectionTemplate> getSectionTemplates () {
return new HashSet<>(sectionTemplates);
public Set<SlotItemTemplate> getSlotItemTemplates () {
return new HashSet<>(slotItemTemplates);
}

public static record PageTemplate(String name, String template, Map<String, Object> data) {
Expand All @@ -85,19 +85,26 @@ public Map<String, Object> getForm (String name) {
var forms = (Map<String, Object>)data.getOrDefault("forms", Collections.emptyMap());
return (Map<String, Object>)forms.getOrDefault(name, Collections.emptyMap());
}

public String getContentFolder () {
return (String) data.getOrDefault("contentFolder", "");
}
public boolean addCreateButton () {
return (boolean) data.getOrDefault("createButton", true);
}
}

public static record SectionTemplate(String name, String template, Map<String, Object> data) {
public static record SlotItemTemplate(String name, String template, Map<String, Object> data) {

public SectionTemplate (Map<String, Object> data) {
public SlotItemTemplate (Map<String, Object> data) {
this(
(String) data.getOrDefault("name", "<no name>"),
(String) data.getOrDefault("template", "<no template>"),
data);
}

public String section() {
return (String) data.getOrDefault("section", "<no section>");
public String slot() {
return (String) data.getOrDefault("slot", "<no slot>");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@
*
* @author t.marx
*/
public class SectionUtil {
public class SlotUtil {

public static boolean isNamedSection(final String name) {
return Constants.SECTION_NAMED_PATTERN.matcher(name).matches();
public static boolean isNamedSlotItem(final String name) {
return Constants.SLOT_ITEM_NAMED_PATTERN.matcher(name).matches();
}

public static String getSectionName(final String name) {
if (isNamedSection(name)) {
var matcher = Constants.SECTION_NAMED_PATTERN.matcher(name);
public static String getSlotItemName(final String name) {
if (isNamedSlotItem(name)) {
var matcher = Constants.SLOT_ITEM_NAMED_PATTERN.matcher(name);
matcher.matches();
return matcher.group("section");
return matcher.group("slot");
} else {
var matcher = Constants.SECTION_PATTERN.matcher(name);
var matcher = Constants.SLOT_ITEM_PATTERN.matcher(name);
matcher.matches();
return matcher.group("section");
return matcher.group("slot");
}
}

public static boolean isSection(final String name) {
return Constants.SECTION_PATTERN.matcher(name).matches()
|| Constants.SECTION_NAMED_PATTERN.matcher(name).matches();
public static boolean isSlotItem(final String name) {
return Constants.SLOT_ITEM_PATTERN.matcher(name).matches()
|| Constants.SLOT_ITEM_NAMED_PATTERN.matcher(name).matches();
}
}
34 changes: 17 additions & 17 deletions cms-api/src/test/java/com/condation/cms/api/ConstantsNGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,53 +36,53 @@ public class ConstantsNGTest {


@Test
public void test_section_pattern() {
Assertions.assertThat(Constants.SECTION_PATTERN.matcher("index.md").matches()).isFalse();
Assertions.assertThat(Constants.SECTION_PATTERN.matcher(".section.md").matches()).isFalse();
public void test_slot_pattern() {
Assertions.assertThat(Constants.SLOT_ITEM_PATTERN.matcher("index.md").matches()).isFalse();
Assertions.assertThat(Constants.SLOT_ITEM_PATTERN.matcher(".section.md").matches()).isFalse();

Matcher matcher = Constants.SECTION_PATTERN.matcher("page.section.md");
Matcher matcher = Constants.SLOT_ITEM_PATTERN.matcher("page.section.md");
Assertions.assertThat(matcher.matches()).isTrue();
Assertions.assertThat(matcher.group(1)).isEqualTo("section");
Assertions.assertThat(matcher.group("section")).isEqualTo("section");
Assertions.assertThat(matcher.group("slot")).isEqualTo("section");

matcher = Constants.SECTION_PATTERN.matcher("index.card.md");
matcher = Constants.SLOT_ITEM_PATTERN.matcher("index.card.md");
Assertions.assertThat(matcher.matches()).isTrue();
Assertions.assertThat(matcher.group(1)).isEqualTo("card");
Assertions.assertThat(matcher.group("section")).isEqualTo("card");
Assertions.assertThat(matcher.group("slot")).isEqualTo("card");
}


@Test
public void test_named_sections_pattern() {
Assertions.assertThat(Constants.SECTION_NAMED_PATTERN.matcher("index.md").matches()).isFalse();
Assertions.assertThat(Constants.SECTION_NAMED_PATTERN.matcher(".section.md").matches()).isFalse();
Assertions.assertThat(Constants.SLOT_ITEM_NAMED_PATTERN.matcher("index.md").matches()).isFalse();
Assertions.assertThat(Constants.SLOT_ITEM_NAMED_PATTERN.matcher(".section.md").matches()).isFalse();

Matcher matcher = Constants.SECTION_NAMED_PATTERN.matcher("page.section.md");
Matcher matcher = Constants.SLOT_ITEM_NAMED_PATTERN.matcher("page.section.md");
Assertions.assertThat(matcher.matches()).isFalse();

matcher = Constants.SECTION_NAMED_PATTERN.matcher("page.section..md");
matcher = Constants.SLOT_ITEM_NAMED_PATTERN.matcher("page.section..md");
Assertions.assertThat(matcher.matches()).isFalse();

matcher = Constants.SECTION_NAMED_PATTERN.matcher("index.card.1.md");
matcher = Constants.SLOT_ITEM_NAMED_PATTERN.matcher("index.card.1.md");
Assertions.assertThat(matcher.matches()).isTrue();
Assertions.assertThat(matcher.group("section")).isEqualTo("card");
Assertions.assertThat(matcher.group("slot")).isEqualTo("card");
Assertions.assertThat(matcher.group("id")).isEqualTo("1");

matcher = Constants.SECTION_NAMED_PATTERN.matcher("index.card.10.md");
matcher = Constants.SLOT_ITEM_NAMED_PATTERN.matcher("index.card.10.md");
Assertions.assertThat(matcher.matches()).isTrue();
Assertions.assertThat(matcher.group("section")).isEqualTo("card");
Assertions.assertThat(matcher.group("slot")).isEqualTo("card");
Assertions.assertThat(matcher.group("id")).isEqualTo("10");
}

@Test
public void test_named_section_of() {

var pattern = Constants.SECTION_NAMED_OF_PATTERN.apply("page");
var pattern = Constants.SLOT_ITEM_NAMED_OF_PATTERN.apply("page");

var matcher = pattern.matcher("page.left.10.md");
Assertions.assertThat(matcher.matches()).isTrue();

pattern = Constants.SECTION_NAMED_OF_PATTERN.apply("other");
pattern = Constants.SLOT_ITEM_NAMED_OF_PATTERN.apply("other");

matcher = pattern.matcher("page.left.10.md");
Assertions.assertThat(matcher.matches()).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
*
* @author thorstenmarx
*/
public class SectionUtilTest {
public class SlotUtilTest {

@ParameterizedTest
@CsvSource({
"index.asection.md, asection",
"index.asection.1.md, asection",
"index.asection.blabla.md, asection"
})
public void test_getSectionName(String filename, String sectionname) {
Assertions.assertThat(SectionUtil.getSectionName(filename)).isEqualTo(sectionname);
public void test_getSlotName(String filename, String slotItemName) {
Assertions.assertThat(SlotUtil.getSlotItemName(filename)).isEqualTo(slotItemName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public interface ContentRenderer {

String render(final ReadOnlyFile contentFile, final RequestContext context) throws IOException;

String render(final ReadOnlyFile contentFile, final RequestContext context, final Map<String, List<Section>> sections) throws IOException;
String render(final ReadOnlyFile contentFile, final RequestContext context, final Map<String, List<SlotItem>> slotItems) throws IOException;

String render(final ReadOnlyFile contentFile, final RequestContext context, final Map<String, List<Section>> sections, final Map<String, Object> meta, final String markdownContent, final Consumer<TemplateEngine.Model> modelExtending) throws IOException;
String render(final ReadOnlyFile contentFile, final RequestContext context, final Map<String, List<SlotItem>> slotItems, final Map<String, Object> meta, final String markdownContent, final Consumer<TemplateEngine.Model> modelExtending) throws IOException;

Map<String, List<Section>> renderSections(final List<ContentNode> sectionNodes, final RequestContext context) throws IOException;
Map<String, List<SlotItem>> renderSlotItems(final List<ContentNode> slotItemNodes, final RequestContext context) throws IOException;

String renderTaxonomy(final Optional<ReadOnlyFile> contentFileOpt, final Taxonomy taxonomy, Optional<String> taxonomyValue, final RequestContext context, final Map<String, Object> meta, final Page<ListNode> page, Map<String, List<Section>> sections) throws IOException;
String renderTaxonomy(final Optional<ReadOnlyFile> contentFileOpt, final Taxonomy taxonomy, Optional<String> taxonomyValue, final RequestContext context, final Map<String, Object> meta, final Page<ListNode> page, Map<String, List<SlotItem>> slotItems) throws IOException;

String renderView(final ReadOnlyFile viewFile, final View view, final ContentNode contentNode, final RequestContext requestContext, final Page<ListNode> page) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ private Optional<ContentResponse> getContent(final RequestContext context, boole

try {

List<ContentNode> sections = db.getContent().listSections(contentFile);
List<ContentNode> slotItems = db.getContent().listSlotItems(contentFile);

Map<String, List<Section>> renderedSections = contentRenderer.renderSections(sections, context);
Map<String, List<SlotItem>> renderedSlotItems = contentRenderer.renderSlotItems(slotItems, context);

var content = contentRenderer.render(contentFile, context, renderedSections);
var content = contentRenderer.render(contentFile, context, renderedSlotItems);

var contentType = contentNode.contentType();

Expand Down
Loading