You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
One more thing that I did note that was even more confusing is that, even when using prettyPrint, if I appended something (any non-whitespace char) AFTER the end of my section, then the indentation of the whole section works as expected. For example, with a template that looks like:
---
/// one
/// two
/// three
/// four
x
---
/// one
/// two
/// three
/// four
---
I don't know how having an x character AFTER the {{/list}} marker affects everything INSIDE the list but I'm sure that's just my lack of knowledge showing... 🤔
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:
If I run as-is, I see:
However, if I use
setPrettyPrint(false)
, then I see: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.
The text was updated successfully, but these errors were encountered: