handlebars.java
handlebars.java copied to clipboard
Indenting only first line
I've been looking at using handlebars.java to generated some Kotlin/Swift source code (awesome library, BTW!) and have run afoul of a strange indenting problem. Note that I need to use prettyPrint
otherwise my generated source code is really difficult to read (as a human)
Consider the following code:
val handlebars = Handlebars()
handlebars.setPrettyPrint(true)
val template = handlebars.compileInline(
"""
---
{{#list}}/// {{.}}
{{/list}}
---
{{#list}}/// {{.}}
{{/list}}
---
""".trimIndent()
)
println(template.apply(mapOf("list" to listOf("one", "two", "three", "four"))))
If I run as-is, I see:
---
/// one
/// two
/// three
/// four
---
/// one
/// two
/// three
/// four
---
However, if I use setPrettyPrint(false)
, then I see:
---
/// one
/// two
/// three
/// four
---
/// one
/// two
/// three
/// four
---
I'm trying to figure out why using prettyPrint
gives me the first result? I noted a similar ticket in #401 (I initially stumbled across this problem using a partial, but I've managed to reproduce just using a standalone template) but it was closed by the OP without any more info about what they did to solve it.
Reading the doco for prettyPrint
suggests that there's some rules in the Mustache spec that it is following, but I'm struggling to find where in the spec so I can tweak my template accordingly.
I'm not convinced that this is a bug in this project (it is probably user error)... but, even if so, I'm super keen to figure out why it is behaving like this and more importantly how I can work around it so that they're all indented (maybe I need the opposite of ~
)
Any help would be awesome. Thanks.