]> WPIA git - gigi.git/commitdiff
add: ignored line breaks to template syntax
authorFelix Dörre <felix@dogcraft.de>
Fri, 29 Jul 2016 10:20:18 +0000 (12:20 +0200)
committerFelix Dörre <felix@dogcraft.de>
Fri, 29 Jul 2016 21:37:22 +0000 (23:37 +0200)
Change-Id: I58e64a31d667b1d59e1c574f128249999d776c49

doc/TemplateSyntax.txt
src/org/cacert/gigi/output/template/Template.java
tests/org/cacert/gigi/template/TestTemplate.java

index ad8e09ae170f0e9f82326af1f60b06199f37f890..f747c2257692a0b2c0e03c53918b44c5d2d6e004 100644 (file)
@@ -26,4 +26,5 @@ Syntax:
   Special variables that $variable defines can be used in the inner text.
  
   
   Special variables that $variable defines can be used in the inner text.
  
   
-  
\ No newline at end of file
+Adding a "\" before a newline will cause both the backslash and the newline get removed. This allows non-visible line-breaks in templates.
+Note: Mail templates consist of a template for subject and a template for the body. Prolonging the subject-line with this feature is not possible.
index 8ad47bc2876a271dea1cce221c4a732cc2907190..dfb7b46382f92c8b36e9a207fb28687016bf9eb5 100644 (file)
@@ -123,6 +123,9 @@ public class Template implements Outputable {
                     break outer;
                 }
                 buf.append((char) ch);
                     break outer;
                 }
                 buf.append((char) ch);
+                if (endsWith(buf, "\\\n")) {
+                    buf.delete(buf.length() - 2, buf.length());
+                }
             }
             buf.delete(buf.length() - 2, buf.length());
             splitted.add(buf.toString());
             }
             buf.delete(buf.length() - 2, buf.length());
             splitted.add(buf.toString());
index 7dca58e0eec50b785f818739cf0f3bb21cd4766f..fe7e25b85fee9b222cd32b4637da1d1400bfd72e 100644 (file)
@@ -137,4 +137,13 @@ public class TestTemplate {
         vars.put("b", null);
         assertEquals("false", testExecute(Language.getInstance(Locale.ENGLISH), vars, "<? if($b){ ?>true<? } else{?>false<?}?>"));
     }
         vars.put("b", null);
         assertEquals("false", testExecute(Language.getInstance(Locale.ENGLISH), vars, "<? if($b){ ?>true<? } else{?>false<?}?>"));
     }
+
+    @Test
+    public void testIgnoredNewline() {
+        assertEquals("\\ab\\\\n\n\\c", testExecute(Language.getInstance(Locale.ENGLISH), vars, "\\a\\\nb\\\\n\n\\\\\nc"));
+        assertEquals("a\\b\\c", testExecute(Language.getInstance(Locale.ENGLISH), vars, "a\\b\\\n\\c"));
+        // \r's are currently not valid.
+        assertEquals("a\\\r\nb", testExecute(Language.getInstance(Locale.ENGLISH), vars, "a\\\r\nb"));
+    }
+
 }
 }