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')} +