Skip to content

Commit

Permalink
Update IndentedLambda to take optional prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Peaches491 committed Aug 7, 2018
1 parent e143214 commit 1a1f728
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
*/
public class IndentedLambda implements Mustache.Lambda {
private final int prefixSpaceCount;
private final String prefix;
private int spaceCode;

/**
* Constructs a new instance of {@link IndentedLambda}, with an indent count of 4 spaces
*/
public IndentedLambda() {
this(4, " ");
this(4, " ", null);
}

/**
Expand All @@ -59,15 +60,38 @@ public IndentedLambda() {
* @param indentionCharacter String representation of the character used in the indent (e.g. " ", "\t", ".").
*/
public IndentedLambda(int prefixSpaceCount, String indentionCharacter) {
this(prefixSpaceCount, Character.codePointAt(indentionCharacter, 0));
this(prefixSpaceCount, Character.codePointAt(indentionCharacter, 0), null);
}

/**
* Constructs a new instance of {@link IndentedLambda}, with customized indent count and intention character
*
* @param prefixSpaceCount The number of indented characters to apply as a prefix to a fragment.
* @param indentionCharacter String representation of the character used in the indent (e.g. " ", "\t", ".").
* @param prefix An optional prefix to prepend before the line (useful for multi-line comments).
*/
public IndentedLambda(int prefixSpaceCount, String indentionCharacter, String prefix) {
this(prefixSpaceCount, Character.codePointAt(indentionCharacter, 0), prefix);
}

/**
* Constructs a new instance of {@link IndentedLambda}
*
* @param prefixSpaceCount The number of indented characters to apply as a prefix to a fragment.
* @param indentionCodePoint Code point of the single character used for indentation.
*/
private IndentedLambda(int prefixSpaceCount, int indentionCodePoint) {
this(prefixSpaceCount, indentionCodePoint, null);
}

/**
* Constructs a new instance of {@link IndentedLambda}
*
* @param prefixSpaceCount The number of indented characters to apply as a prefix to a fragment.
* @param indentionCodePoint Code point of the single character used for indentation.
* @param prefix An optional prefix to prepend before the line (useful for multi-line comments).
*/
private IndentedLambda(int prefixSpaceCount, int indentionCodePoint, String prefix) {
if (prefixSpaceCount <= 0) {
throw new IllegalArgumentException("prefixSpaceCount must be greater than 0");
}
Expand All @@ -78,6 +102,7 @@ private IndentedLambda(int prefixSpaceCount, int indentionCodePoint) {

this.prefixSpaceCount = prefixSpaceCount;
this.spaceCode = indentionCodePoint;
this.prefix = prefix;
}

@Override
Expand All @@ -96,6 +121,7 @@ public void execute(Template.Fragment fragment, Writer writer) throws IOExceptio
// So, we want to skip the first line.
if (i > 0) {
sb.append(prefixedIndention);
if (prefix != null) sb.append(prefix);
}

sb.append(line);
Expand Down

0 comments on commit 1a1f728

Please # to comment.