Lots of blank empty lines in output
malkomalko opened this issue Β· 16 comments
It appears if you use an if block, and it doesn't pass the truth test, it's still adding blank lines to the output. Have you found this to be correct?
@malkomalko Would you be able to share an example template showing this behaviour?
Any if block adds an empty line even if it returns false, but I'll try to create something basic and post up as a test case.
Closing due to inactivity, please re-open if there if a sample showing there is a bug in Stencil.
I'm having a similar issue.
Template
enum Asset : String {
{% for image in images %}
case {{ image }} = "{{ image }}"
{% endfor %}
}
Context used
let ctx = Context(dictionary: [
"images": ["GreenApple", "RedApple", "Pears"]
])
Actual output
enum Asset : String {
case GreenApple = "GreenApple"
case RedApple = "RedApple"
case Pears = "Pears"
}
Expected output
enum Asset : String {
case GreenApple = "GreenApple"
case RedApple = "RedApple"
case Pears = "Pears"
}
Writing a PR rn
@kylef If you need more examples and tests, you can find plenty on the stencil
branch of SwiftGen
Before that commit is what I expected to have, after the commit is what I actually have (= the changes I did to make my tests pass until this issue is solved on Stencil)
@kylef Here's a dirty workaround I use to fix that issue until we have better. I don't like it very much (feels like cheating) but at least it works in the meantime.
Well, for now this works as expected (although we are talking about changing the behaviour). How it works now is not broken it's just how it was designed.
You don't need to do those workarounds, instead you could control how the newlines are used in your templates.
enum Suit { {% for suit in suits %}
case {{ suit }}{% endfor %}
}
β¦and make unreadable templates, yeah π
(And I though you were the perfectionist in the CoreTeam :troll face:)
I get your point, but the current behavior makes templates really hard to read and the new behavior would seem much more natural I think. So sure it's not a bug, but it's still a feature request π
Any there any updates on this? The solution that was discussed in #32 seems to be the right one. Preventing newlines when control flow blocks (eg. if and for) are on their own line
I'd also love to see this feature! My templates have become unwieldy all too quickly.
Hi,
Can we do something like jinja2 for Whitespace Control ?
https://jinja.palletsprojects.com/en/master/templates/#whitespace-control
Thanks
@paulosilva There's a PR that adds this here #287
Can this be merged and closed?
It's really hard generating code from templates without compromising the output or the template.
It's either creating ugly and unmaintainable templates or just code with a lot of empty lines.
I have the same issue. Output contains a lot of blank lines.