-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thorsten Marx
committed
Jun 26, 2024
1 parent
8c77eac
commit 6d0d095
Showing
13 changed files
with
227 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ensions/src/main/java/com/github/thmarx/cms/extensions/hooks/TemplateFunctionWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.github.thmarx.cms.extensions.hooks; | ||
|
||
/*- | ||
* #%L | ||
* cms-extensions | ||
* %% | ||
* Copyright (C) 2023 - 2024 Marx-Software | ||
* %% | ||
* 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.github.thmarx.cms.extensions.TemplateFunctionExtension; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import lombok.Getter; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
public class TemplateFunctionWrapper { | ||
|
||
@Getter | ||
private final List<TemplateFunctionExtension> registerTemplateFunctions = new ArrayList<>(); | ||
|
||
public void add(final String path, final Function<?, ?> function) { | ||
registerTemplateFunctions.add(new TemplateFunctionExtension(path, function)); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
cms-extensions/src/main/java/com/github/thmarx/cms/extensions/hooks/TemplateHooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.github.thmarx.cms.extensions.hooks; | ||
|
||
/*- | ||
* #%L | ||
* cms-server | ||
* %% | ||
* Copyright (C) 2023 - 2024 Marx-Software | ||
* %% | ||
* 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.github.thmarx.cms.api.annotations.Experimental; | ||
import com.github.thmarx.cms.api.feature.Feature; | ||
import com.github.thmarx.cms.api.feature.features.HookSystemFeature; | ||
import com.github.thmarx.cms.api.request.RequestContext; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
@Experimental | ||
@RequiredArgsConstructor | ||
public class TemplateHooks implements Feature { | ||
|
||
private final RequestContext requestContext; | ||
|
||
|
||
public TemplateSupplierWrapper getTemplateSupplier () { | ||
var templateSupplier = new TemplateSupplierWrapper(); | ||
requestContext.get(HookSystemFeature.class).hookSystem() | ||
.execute("template/supplier/register", Map.of("suppliers", templateSupplier)); | ||
|
||
return templateSupplier; | ||
} | ||
|
||
public TemplateFunctionWrapper getTemplateFunctions () { | ||
var templateFunctions = new TemplateFunctionWrapper(); | ||
requestContext.get(HookSystemFeature.class).hookSystem() | ||
.execute("template/function/register", Map.of("functions", templateFunctions)); | ||
|
||
return templateFunctions; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ensions/src/main/java/com/github/thmarx/cms/extensions/hooks/TemplateSupplierWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.github.thmarx.cms.extensions.hooks; | ||
|
||
/*- | ||
* #%L | ||
* cms-extensions | ||
* %% | ||
* Copyright (C) 2023 - 2024 Marx-Software | ||
* %% | ||
* 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.github.thmarx.cms.extensions.TemplateSupplierExtension; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
import lombok.Getter; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
public class TemplateSupplierWrapper { | ||
|
||
@Getter | ||
private final List<TemplateSupplierExtension> registerTemplateSupplier = new ArrayList<>(); | ||
|
||
public void add(final String path, final Supplier<?> supplier) { | ||
registerTemplateSupplier.add(new TemplateSupplierExtension(path, supplier)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
cms-server/hosts/features/extensions/template.extension.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { $template } from 'system/template.mjs'; | ||
import { $hooks } from 'system/hooks.mjs'; | ||
|
||
/* | ||
$template.registerTemplateSupplier( | ||
"myName", | ||
() => "Thorsten" | ||
) | ||
*/ | ||
$hooks.registerAction("template/supplier/register", (context) => { | ||
context.arguments().get("suppliers").add( | ||
"myName", | ||
() => "My name is Thorsten" | ||
) | ||
return null; | ||
}) | ||
|
||
/* | ||
$template.registerTemplateFunction( | ||
"getHello", | ||
(name) => "Hello " + name + "!" | ||
) | ||
*/ | ||
$hooks.registerAction("template/function/register", (context) => { | ||
context.arguments().get("functions").add( | ||
"getHello", | ||
(name) => "Hello " + name + "!!" | ||
) | ||
return null; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## YAML Template. | ||
--- | ||
values: | ||
- id: blue | ||
title: Blau | ||
- id: red | ||
title: Rot | ||
- id: orange | ||
title: Orange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## YAML Template. | ||
--- | ||
taxonomies: | ||
- title: Kategorie | ||
slug: kategorien | ||
field: taxonomy.category | ||
- title: Tags | ||
slug: tags | ||
field: taxonomy.tags | ||
array: true |