Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move handling of text into a single place

  • Loading branch information...
commit b059f7a36ea16c93147155dbe08cc2329cd4685f 1 parent 8309bbb
Sam Pullara authored
View
9 compiler/src/main/java/com/github/mustachejava/codes/DefaultCode.java
@@ -20,7 +20,7 @@
* Simplest possible code implementaion with some default shared behavior
*/
public class DefaultCode implements Code {
- protected StringBuilder appended;
+ protected String appended;
protected final ObjectHandler oh;
protected final String name;
@@ -189,7 +189,7 @@ private void tag(Writer writer, String tag) throws IOException {
protected Writer appendText(Writer writer) {
if (appended != null) {
try {
- writer.append(appended);
+ writer.write(appended);
} catch (IOException e) {
throw new MustacheException(e);
}
@@ -210,9 +210,10 @@ protected Writer runCodes(Writer writer, Object[] scopes) {
@Override
public void append(String text) {
if (appended == null) {
- appended = new StringBuilder();
+ appended = text;
+ } else {
+ appended = appended + text;
}
- appended.append(text);
}
private ThreadLocal<Object[]> localScopes = new ThreadLocal<Object[]>();
View
20 compiler/src/main/java/com/github/mustachejava/codes/WriteCode.java
@@ -13,30 +13,12 @@
* To change this template use File | Settings | File Templates.
*/
public class WriteCode extends DefaultCode {
- private String text;
-
public WriteCode(String text) {
- appended = new StringBuilder(this.text = text);
+ super.append(text);
}
@Override
public void identity(Writer writer) {
execute(writer, null);
}
-
- @Override
- public void append(String text) {
- super.append(text);
- this.text = appended.toString();
- }
-
- @Override
- public Writer execute(Writer writer, Object[] scopes) {
- try {
- writer.write(text);
- } catch (IOException e) {
- throw new MustacheException();
- }
- return writer;
- }
}
Please sign in to comment.
Something went wrong with that request. Please try again.