Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of blank empty lines in output #22

Closed
malkomalko opened this issue Apr 3, 2015 · 16 comments
Closed

Lots of blank empty lines in output #22

malkomalko opened this issue Apr 3, 2015 · 16 comments
Milestone

Comments

@malkomalko
Copy link

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?

@kylef
Copy link
Collaborator

kylef commented Apr 3, 2015

@malkomalko Would you be able to share an example template showing this behaviour?

@malkomalko
Copy link
Author

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.

@kylef
Copy link
Collaborator

kylef commented Aug 29, 2015

Closing due to inactivity, please re-open if there if a sample showing there is a bug in Stencil.

@kylef kylef closed this as completed Aug 29, 2015
@AliSoftware
Copy link
Collaborator

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"
}

@kylef kylef reopened this Oct 18, 2015
@AliSoftware
Copy link
Collaborator

Writing a PR rn

@AliSoftware
Copy link
Collaborator

@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)

AliSoftware added a commit to SwiftGen/SwiftGen that referenced this issue Oct 20, 2015
@AliSoftware
Copy link
Collaborator

@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.

@kylef
Copy link
Collaborator

kylef commented Oct 20, 2015

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 %}
}

@AliSoftware
Copy link
Collaborator

…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 😉

AliSoftware added a commit to SwiftGen/SwiftGen that referenced this issue Oct 25, 2015
AliSoftware added a commit to SwiftGen/SwiftGen that referenced this issue Oct 25, 2015
@kylef kylef closed this as completed Feb 21, 2016
@yonaskolb
Copy link
Collaborator

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

@bejar37
Copy link

bejar37 commented Dec 19, 2016

I'd also love to see this feature! My templates have become unwieldy all too quickly.

@yonaskolb
Copy link
Collaborator

I've just implemented this in #85

@paulosilva
Copy link

Hi,

Can we do something like jinja2 for Whitespace Control ?

https://jinja.palletsprojects.com/en/master/templates/#whitespace-control

Thanks

@yonaskolb
Copy link
Collaborator

@paulosilva There's a PR that adds this here #287

@arielpollack
Copy link

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.

@subdan
Copy link

subdan commented Sep 9, 2020

I have the same issue. Output contains a lot of blank lines.

@djbe djbe added this to the 0.15.0 milestone Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants