Last active
November 20, 2016 21:36
-
-
Save ndemengel/b9fdd87011ebcc8be83b20820359bb5b to your computer and use it in GitHub Desktop.
Handlebars helper "concat" in JavaScript and Java
This file contains hidden or 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
module.exports = function () { | |
var args = Array.prototype.slice.call(arguments, 0, arguments.length - 1); | |
return args.join(''); | |
}; |
This file contains hidden or 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
import com.github.jknack.handlebars.Helper; | |
import com.github.jknack.handlebars.Options; | |
import java.io.IOException; | |
import java.util.StringJoiner; | |
public class ConcatHelper implements Helper<Object> { | |
@Override | |
public Object apply(Object firstObjectToConcat, Options options) throws IOException { | |
StringJoiner joiner = new StringJoiner(""); | |
joiner.add(String.valueOf(firstObjectToConcat)); | |
// all params except the first one | |
for (Object param : options.params) { | |
joiner.add(String.valueOf(param)); | |
} | |
return joiner.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment