summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2022-10-23 08:00:31 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2022-10-23 08:00:31 +0200
commit40e7925ca10f60357ec6161685499e2f12de99fe (patch)
tree08555f24b6fe07841f46f7628dee64a281b1ff8a /src
parent264283c9021e6060e45453f59e0cd6f4d6e2138b (diff)
refactor: Consolidate Qute extensions in a separate package.
Change-Id: I03526ef4f5d99db202cbbf1045e52464e2d83a9a
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java47
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java23
-rw-r--r--src/main/java/eu/mulk/mulkcms2/common/template/TemporalExtensions.java58
3 files changed, 58 insertions, 70 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
index 07a9f2f..d6fe538 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
@@ -78,17 +78,6 @@ import org.jsoup.Jsoup;
public abstract class PostResource {
- private static final DateTimeFormatter htmlDateTimeFormatter =
- DateTimeFormatter.ISO_OFFSET_DATE_TIME;
-
- private static final DateTimeFormatter humanDateTimeFormatter =
- DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT);
-
- private static final DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_LOCAL_DATE;
-
- private static final DateTimeFormatter humanDateFormatter =
- DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
-
private static final String hashcashDigestAlgorithm = "SHA-256";
private static final int pageKeyBytes = 32;
@@ -496,42 +485,6 @@ public abstract class PostResource {
return wireFeedOutput.outputString(feed);
}
- @TemplateExtension
- @CheckForNull
- static String humanDateTime(@CheckForNull TemporalAccessor x) {
- if (x == null) {
- return null;
- }
- return humanDateTimeFormatter.format(x);
- }
-
- @TemplateExtension
- @CheckForNull
- static String htmlDateTime(@CheckForNull TemporalAccessor x) {
- if (x == null) {
- return null;
- }
- return htmlDateTimeFormatter.format(x);
- }
-
- @TemplateExtension
- @CheckForNull
- static String humanDate(@CheckForNull TemporalAccessor x) {
- if (x == null) {
- return null;
- }
- return humanDateFormatter.format(x);
- }
-
- @TemplateExtension
- @CheckForNull
- static String htmlDate(@CheckForNull TemporalAccessor x) {
- if (x == null) {
- return null;
- }
- return htmlDateFormatter.format(x);
- }
-
private boolean showBookmarkForm() {
switch (postFilter) {
case ALL:
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
index edf9c72..4100dc2 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
@@ -37,11 +37,6 @@ import org.jsoup.safety.Safelist;
@Path("/wiki")
public class WikiResource {
- private static final DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
-
- private static final DateTimeFormatter humanDateFormatter =
- DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT);
-
private static final JsonProvider jsonProvider = JsonProvider.provider();
@CheckedTemplate(basePath = "benki/wiki")
@@ -158,22 +153,4 @@ public class WikiResource {
return Templates.wikiPageRevisionList(page, pageName);
}
-
- @TemplateExtension
- @CheckForNull
- static String humanDateTime(@CheckForNull TemporalAccessor x) {
- if (x == null) {
- return null;
- }
- return humanDateFormatter.format(x);
- }
-
- @TemplateExtension
- @CheckForNull
- static String htmlDateTime(@CheckForNull TemporalAccessor x) {
- if (x == null) {
- return null;
- }
- return htmlDateFormatter.format(x);
- }
}
diff --git a/src/main/java/eu/mulk/mulkcms2/common/template/TemporalExtensions.java b/src/main/java/eu/mulk/mulkcms2/common/template/TemporalExtensions.java
new file mode 100644
index 0000000..35d6d32
--- /dev/null
+++ b/src/main/java/eu/mulk/mulkcms2/common/template/TemporalExtensions.java
@@ -0,0 +1,58 @@
+package eu.mulk.mulkcms2.common.template;
+
+import io.quarkus.qute.TemplateExtension;
+import java.time.format.DateTimeFormatter;
+import java.time.format.FormatStyle;
+import java.time.temporal.TemporalAccessor;
+import javax.annotation.CheckForNull;
+
+public class TemporalExtensions {
+
+ private static final DateTimeFormatter htmlDateTimeFormatter =
+ DateTimeFormatter.ISO_OFFSET_DATE_TIME;
+
+ private static final DateTimeFormatter humanDateTimeFormatter =
+ DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT);
+
+ private static final DateTimeFormatter htmlDateFormatter = DateTimeFormatter.ISO_LOCAL_DATE;
+
+ private static final DateTimeFormatter humanDateFormatter =
+ DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
+
+ @TemplateExtension
+ @CheckForNull
+ static String humanDateTime(@CheckForNull TemporalAccessor x) {
+ if (x == null) {
+ return null;
+ }
+ return humanDateTimeFormatter.format(x);
+ }
+
+ @TemplateExtension
+ @CheckForNull
+ static String htmlDateTime(@CheckForNull TemporalAccessor x) {
+ if (x == null) {
+ return null;
+ }
+ return htmlDateTimeFormatter.format(x);
+ }
+
+ @TemplateExtension
+ @CheckForNull
+ static String humanDate(@CheckForNull TemporalAccessor x) {
+ if (x == null) {
+ return null;
+ }
+ return humanDateFormatter.format(x);
+ }
+
+ @TemplateExtension
+ @CheckForNull
+ static String htmlDate(@CheckForNull TemporalAccessor x) {
+ if (x == null) {
+ return null;
+ }
+ return htmlDateFormatter.format(x);
+ }
+
+}