From: Felix Dörre Date: Fri, 29 Jul 2016 10:20:18 +0000 (+0200) Subject: add: ignored line breaks to template syntax X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=b49c9e8c7820a7e5b797c102a87613e6925012ac add: ignored line breaks to template syntax Change-Id: I58e64a31d667b1d59e1c574f128249999d776c49 --- diff --git a/doc/TemplateSyntax.txt b/doc/TemplateSyntax.txt index ad8e09ae..f747c225 100644 --- a/doc/TemplateSyntax.txt +++ b/doc/TemplateSyntax.txt @@ -26,4 +26,5 @@ Syntax: 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. diff --git a/src/org/cacert/gigi/output/template/Template.java b/src/org/cacert/gigi/output/template/Template.java index 8ad47bc2..dfb7b463 100644 --- a/src/org/cacert/gigi/output/template/Template.java +++ b/src/org/cacert/gigi/output/template/Template.java @@ -123,6 +123,9 @@ public class Template implements Outputable { 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()); diff --git a/tests/org/cacert/gigi/template/TestTemplate.java b/tests/org/cacert/gigi/template/TestTemplate.java index 7dca58e0..fe7e25b8 100644 --- a/tests/org/cacert/gigi/template/TestTemplate.java +++ b/tests/org/cacert/gigi/template/TestTemplate.java @@ -137,4 +137,13 @@ public class TestTemplate { vars.put("b", null); assertEquals("false", testExecute(Language.getInstance(Locale.ENGLISH), vars, "truefalse")); } + + @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")); + } + }