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 2015/10/04 12:45:45 UTC

incubator-freemarker git commit: Added new built-in: is_markup_output, returns true if the value is of type markup output.

Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae fa6ac0eea -> 75fab1f78


Added new built-in: is_markup_output, returns true if the value is of type markup output.


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

Branch: refs/heads/2.3-gae
Commit: 75fab1f789523ed8513a1aa6b938f6a89e9fe906
Parents: fa6ac0e
Author: ddekany <dd...@apache.org>
Authored: Sun Oct 4 12:45:26 2015 +0200
Committer: ddekany <dd...@apache.org>
Committed: Sun Oct 4 12:45:26 2015 +0200

----------------------------------------------------------------------
 src/main/java/freemarker/core/BuiltIn.java            |  3 ++-
 .../freemarker/core/BuiltInsForMultipleTypes.java     | 10 ++++++++++
 src/manual/book.xml                                   | 14 ++++++++++++++
 src/test/java/freemarker/core/OutputFormatTest.java   |  9 +++++++++
 4 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/75fab1f7/src/main/java/freemarker/core/BuiltIn.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltIn.java b/src/main/java/freemarker/core/BuiltIn.java
index 11e9be4..144d70b 100644
--- a/src/main/java/freemarker/core/BuiltIn.java
+++ b/src/main/java/freemarker/core/BuiltIn.java
@@ -77,7 +77,7 @@ abstract class BuiltIn extends Expression implements Cloneable {
     protected Expression target;
     protected String key;
 
-    static final int NUMBER_OF_BIS = 257;
+    static final int NUMBER_OF_BIS = 259;
     static final HashMap builtins = new HashMap(NUMBER_OF_BIS * 3 / 2 + 1, 1f);
     static {
         // Note that you must update NUMBER_OF_BIS if you add new items here!
@@ -140,6 +140,7 @@ abstract class BuiltIn extends Expression implements Cloneable {
         putBI("is_infinite", "isInfinite", new is_infiniteBI());
         putBI("is_indexable", "isIndexable", new BuiltInsForMultipleTypes.is_indexableBI());
         putBI("is_macro", "isMacro", new BuiltInsForMultipleTypes.is_macroBI());
+        putBI("is_markup_output", "isMarkupOutput", new BuiltInsForMultipleTypes.is_markup_outputBI());
         putBI("is_method", "isMethod", new BuiltInsForMultipleTypes.is_methodBI());
         putBI("is_nan", "isNan", new is_nanBI());
         putBI("is_node", "isNode", new BuiltInsForMultipleTypes.is_nodeBI());

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/75fab1f7/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java b/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java
index 4b5d548..a15c3b6 100644
--- a/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java
+++ b/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java
@@ -391,6 +391,16 @@ class BuiltInsForMultipleTypes {
         }
     }
 
+    static class is_markup_outputBI extends BuiltIn {
+        @Override
+        TemplateModel _eval(Environment env) throws TemplateException {
+            TemplateModel tm = target.eval(env);
+            target.assertNonNull(tm, env);
+            return (tm instanceof TemplateMarkupOutputModel)  ?
+                TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
+        }
+    }
+    
     static class is_methodBI extends BuiltIn {
         @Override
         TemplateModel _eval(Environment env) throws TemplateException {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/75fab1f7/src/manual/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/book.xml b/src/manual/book.xml
index 3546923..5685b35 100644
--- a/src/manual/book.xml
+++ b/src/manual/book.xml
@@ -17168,6 +17168,13 @@ Sorted by name.last:
 
                 <td>node</td>
               </tr>
+
+              <tr>
+                <td><literal>is_markup_output</literal></td>
+
+                <td>markup output (a value that won't be <link
+                linkend="dgui_misc_autoescaping">auto-escaped</link>)</td>
+              </tr>
             </tbody>
           </informaltable>
         </section>
@@ -25673,6 +25680,13 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
                 </listitem>
 
                 <listitem>
+                  <para>Added new built-in:
+                  <literal>is_markup_output</literal>, returns
+                  <literal>true</literal> if the value is of type
+                  <quote>markup output</quote>.</para>
+                </listitem>
+
+                <listitem>
                   <para>New directive: <literal>outputformat</literal>, used
                   to change the output format for a section of a template,
                   like <literal>&lt;#outputformat

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/75fab1f7/src/test/java/freemarker/core/OutputFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/OutputFormatTest.java b/src/test/java/freemarker/core/OutputFormatTest.java
index b36761e..b596437 100644
--- a/src/test/java/freemarker/core/OutputFormatTest.java
+++ b/src/test/java/freemarker/core/OutputFormatTest.java
@@ -991,6 +991,15 @@ public class OutputFormatTest extends TemplateTest {
             assertErrorContains(ftl, InvalidReferenceException.class, "noSuchVar", "null or missing");
         }
     }
+
+    @Test
+    public void testIsMarkupOutputBI() throws Exception {
+        addToDataModel("m1", HTMLOutputFormat.INSTANCE.fromPlainTextByEscaping("x"));
+        addToDataModel("m2", HTMLOutputFormat.INSTANCE.fromMarkup("x"));
+        addToDataModel("s", "x");
+        assertOutput("${m1?isMarkupOutput?c} ${m2?isMarkupOutput?c} ${s?isMarkupOutput?c}", "true true false");
+        assertOutput("${m1?is_markup_output?c}", "true");
+    }
     
     @Override
     protected Configuration createConfiguration() throws TemplateModelException {