From b21cdbeddb97c2211393d5a51398d5836d31cc86 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 8 Aug 2024 20:15:44 +0200 Subject: [PATCH] text wrap function (using zero with space) --- CHANGELOG.md | 1 + .../java/doc/base/helper/TextWrapHelper.java | 22 +++++++++++++++++++ .../doc/base/helper/TestTextWrapHelper.java | 17 ++++++++++++++ .../java/doc/freemarker/fun/FMFunHelper.java | 21 ++++++++++++++++++ .../doc/freemarker/fun/SimpleMessageFun.java | 4 +--- .../java/doc/freemarker/fun/TextWrapFun.java | 21 ++++++++++++++++++ .../fj_doc_test/freemarker-doc-process.xml | 1 + .../fj_doc_test/template/test_01.ftl | 3 +++ 8 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 fj-doc-base/src/main/java/org/fugerit/java/doc/base/helper/TextWrapHelper.java create mode 100644 fj-doc-base/src/test/java/test/org/fugerit/java/doc/base/helper/TestTextWrapHelper.java create mode 100644 fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/fun/FMFunHelper.java create mode 100644 fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/fun/TextWrapFun.java diff --git a/CHANGELOG.md b/CHANGELOG.md index d50825d34..17f57aad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - [playground-quarkus] Config conversion user interface +- [freemarker] text wrap function (using zero with space `​`) ### Changed diff --git a/fj-doc-base/src/main/java/org/fugerit/java/doc/base/helper/TextWrapHelper.java b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/helper/TextWrapHelper.java new file mode 100644 index 000000000..2d07e39e2 --- /dev/null +++ b/fj-doc-base/src/main/java/org/fugerit/java/doc/base/helper/TextWrapHelper.java @@ -0,0 +1,22 @@ +package org.fugerit.java.doc.base.helper; + +import org.fugerit.java.core.function.SafeFunction; + +public class TextWrapHelper { + + private TextWrapHelper() {} + + public static final String ZERO_WITH_SPACE = "​"; + + public static String padZeroWithSpace( String input ) { + return SafeFunction.getIfNotNull( input, () -> { + StringBuilder builder = new StringBuilder(); + for( int i=0; i arguments, String message ) throws TemplateModelException { + if ( arguments.isEmpty() ) { + throw new TemplateModelException( message ); + } + } + + public static void checkFirstRequred( List arguments ) throws TemplateModelException { + checkFirstRequredWithMessage( arguments, "At least one parameter is needed" ); + } + +} diff --git a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/fun/SimpleMessageFun.java b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/fun/SimpleMessageFun.java index 828883620..315e4563b 100644 --- a/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/fun/SimpleMessageFun.java +++ b/fj-doc-freemarker/src/main/java/org/fugerit/java/doc/freemarker/fun/SimpleMessageFun.java @@ -12,9 +12,7 @@ public class SimpleMessageFun implements TemplateMethodModelEx { @Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { - if ( arguments.isEmpty() ) { - throw new TemplateModelException( "At least one parameter is needed" ); - } + FMFunHelper.checkFirstRequred( arguments ); String key = ((TemplateScalarModel)arguments.get( 0 )).getAsString(); Object[] args = new Object[ arguments.size()-1 ]; for ( int k=1; k + diff --git a/fj-doc-freemarker/src/test/resources/fj_doc_test/template/test_01.ftl b/fj-doc-freemarker/src/test/resources/fj_doc_test/template/test_01.ftl index 4e041cdee..bfa016e5d 100644 --- a/fj-doc-freemarker/src/test/resources/fj_doc_test/template/test_01.ftl +++ b/fj-doc-freemarker/src/test/resources/fj_doc_test/template/test_01.ftl @@ -41,6 +41,9 @@ Test right ${messageFormat('test format -> {0} {1}', 'param1', 'param2')} + + ${textWrap('test text wrap')} +