You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2018/12/19 21:14:59 UTC

[2/5] freemarker git commit: Forward ported from 2.3-gae: When configuring FreeMarker with string values (like with a .properties file), in the settings that support the object builder syntax, now you can create a TemplateMarkupOutputModel value with the

Forward ported from 2.3-gae: When configuring FreeMarker with string values (like with a .properties file), in the settings that support the object builder syntax, now you can create a TemplateMarkupOutputModel value with the new markup function, like markup(HTMLOutputFormat(), "<p>Example</p>").


Project: http://git-wip-us.apache.org/repos/asf/freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/freemarker/commit/dd8b17cc
Tree: http://git-wip-us.apache.org/repos/asf/freemarker/tree/dd8b17cc
Diff: http://git-wip-us.apache.org/repos/asf/freemarker/diff/dd8b17cc

Branch: refs/heads/3
Commit: dd8b17ccd1581c543ff36507a143347baebdb831
Parents: 78ec2df
Author: ddekany <dd...@apache.org>
Authored: Wed Dec 19 11:08:53 2018 +0100
Committer: ddekany <dd...@apache.org>
Committed: Wed Dec 19 11:08:53 2018 +0100

----------------------------------------------------------------------
 .../core/MutableProcessingConfiguration.java    |  7 ++++
 .../apache/freemarker/core/_MarkupBuilder.java  | 43 ++++++++++++++++++++
 .../core/_ObjectBuilderSettingEvaluator.java    |  6 +++
 3 files changed, 56 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/freemarker/blob/dd8b17cc/freemarker-core/src/main/java/org/apache/freemarker/core/MutableProcessingConfiguration.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/MutableProcessingConfiguration.java b/freemarker-core/src/main/java/org/apache/freemarker/core/MutableProcessingConfiguration.java
index 74c8692..ab58924 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/MutableProcessingConfiguration.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/MutableProcessingConfiguration.java
@@ -40,8 +40,10 @@ import org.apache.freemarker.core.arithmetic.ArithmeticEngine;
 import org.apache.freemarker.core.arithmetic.impl.BigDecimalArithmeticEngine;
 import org.apache.freemarker.core.arithmetic.impl.ConservativeArithmeticEngine;
 import org.apache.freemarker.core.model.ObjectWrapper;
+import org.apache.freemarker.core.model.TemplateMarkupOutputModel;
 import org.apache.freemarker.core.model.impl.DefaultObjectWrapper;
 import org.apache.freemarker.core.model.impl.RestrictedObjectWrapper;
+import org.apache.freemarker.core.outputformat.MarkupOutputFormat;
 import org.apache.freemarker.core.outputformat.OutputFormat;
 import org.apache.freemarker.core.outputformat.impl.HTMLOutputFormat;
 import org.apache.freemarker.core.outputformat.impl.PlainTextOutputFormat;
@@ -1627,6 +1629,11 @@ public abstract class MutableProcessingConfiguration<SelfT extends MutableProces
      *     constructor.
      *   </li>
      *   <li>
+     *     <p>{@link TemplateMarkupOutputModel} objects can be created like
+     *     {@code markup(HTMLOutputFormat(), "<h1>Example</h1>")}. Of course the 1st argument can be any other
+     *     {@link MarkupOutputFormat} too.
+     *   </li>
+     *   <li>
      *     <p>{@link Charset} objects can be created like {@code Charset("ISO-8859-5")}, despite that there's no a such
      *     constructor.
      *   </li>

http://git-wip-us.apache.org/repos/asf/freemarker/blob/dd8b17cc/freemarker-core/src/main/java/org/apache/freemarker/core/_MarkupBuilder.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/_MarkupBuilder.java b/freemarker-core/src/main/java/org/apache/freemarker/core/_MarkupBuilder.java
new file mode 100644
index 0000000..5471642
--- /dev/null
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/_MarkupBuilder.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.freemarker.core;
+
+import org.apache.freemarker.core.model.TemplateMarkupOutputModel;
+import org.apache.freemarker.core.outputformat.MarkupOutputFormat;
+
+/**
+ * For internal use only; don't depend on this, there's no backward compatibility guarantee at all!
+ * Used by {@link _ObjectBuilderSettingEvaluator}.
+ */
+public class _MarkupBuilder<MO extends TemplateMarkupOutputModel> {
+
+    private final String markupSource;
+    private final MarkupOutputFormat<MO> markupOutputFormat;
+
+    public _MarkupBuilder(MarkupOutputFormat<MO> markupOutputFormat, String markupSource) {
+        this.markupOutputFormat = markupOutputFormat;
+        this.markupSource = markupSource;
+    }
+
+    public MO build() throws TemplateException {
+        return markupOutputFormat.fromMarkup(markupSource);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/freemarker/blob/dd8b17cc/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java b/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java
index 0039249..4377372 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java
@@ -693,6 +693,12 @@ public class _ObjectBuilderSettingEvaluator {
             }
 
             {
+                String mbClassName = _MarkupBuilder.class.getName();
+                SHORTHANDS.put("markup",
+                        mbClassName.substring(0, mbClassName.length() - BUILDER_CLASS_POSTFIX_2.length()));
+            }
+
+            {
                 String csClassName = _CharsetBuilder.class.getName();
                 SHORTHANDS.put("Charset",
                         csClassName.substring(0, csClassName.length() - BUILDER_CLASS_POSTFIX_2.length()));