-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from superkonduktr/master
add newline_to_br filter
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package liqp.filters; | ||
|
||
class Newline_To_Br extends Filter { | ||
|
||
/* | ||
* newline_to_br(input) | ||
* | ||
* Add <br /> tags in front of all newlines in input string | ||
*/ | ||
@Override | ||
public Object apply(Object value, Object... params) { | ||
|
||
return super.asString(value).replaceAll("[\n]", "<br />\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package liqp.filters; | ||
|
||
import liqp.Template; | ||
import org.antlr.runtime.RecognitionException; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class Newline_To_BrTest { | ||
|
||
@Test | ||
public void applyTest() throws RecognitionException { | ||
|
||
String[][] tests = { | ||
{"{{ '' | newline_to_br }}", ""}, | ||
{"{{ nil | newline_to_br }}", ""}, | ||
{"{{ 'Line 1\nLine 2' | newline_to_br }}", "Line 1<br />\nLine 2"} | ||
}; | ||
|
||
for (String[] test : tests) { | ||
|
||
Template template = Template.parse(test[0]); | ||
String rendered = String.valueOf(template.render()); | ||
|
||
assertThat(rendered, is(test[1])); | ||
} | ||
} | ||
} |