-
Notifications
You must be signed in to change notification settings - Fork 225
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
[Review] Jinja2-like whitespace trim behavior #92
Conversation
The parser keeps track of the whitespace behavior from immediate neighboring Block tokens, and uses that information when creating TextNodes. TextNode at render-time strips leading or trailing whitespace as necessary.
Oops, I see |
corelibs-foundation has the implementation but mistakenly named as #if os(Linux)
typealias NSRegularExpression = RegularExpression
#endif |
If it's different per version, perhaps that conditional could be per Swift version so this will continue to work for both Swift versions? |
This simplifies the parsing code for each node and gives every block token automatic support for the "-" and "+" whitespace control characters.
I realized that I could add support for all block tokens automatically by keeping the whitespace state inside of the |
Are there any updates on this? |
@yonaskolb @AliSoftware @kylef I'd love to get this pulled and am willing to do the work to do so this weekend. A review would be appreciated! I'll look at Jinja or other templating solutions for a good name for the environment variable. |
Update - I did the required work to get this building with the latest master. I decided to hold off on adding the environment variable since there isn't consensus that it's wanted, and it makes sense to me to add it in a follow on PR when and if this one is merged. |
Would love to see this get merged |
I've got some seriously funky stencil formatting in order to get output whitespace to be correct. No fun reading the many >400 character lines stencil authors are required to write. |
@DanielAsher agreed. @kylef or @ilyapuchka do you have any comments on @bejar37's approach here? Has anything relevant changed since this was last rebased? |
@yonaskolb I think its fine, though myself I don't see the reason to have |
@kylef @yonaskolb @AliSoftware @djbe can you guys look at this any time soon? |
The lack of movement on this PR is so frustrating for metaprogramming with stencil. Ordinary indenting and source formatting of stencil files is completely impossible without totally munging the output. I don't want to rewrite my stencils in |
@ilyapuchka As you've probably noticed, I'm working through reviewing some of the PRs, mostly in an order of first those "I get why" and that I understand (as I'm not so familiar with the codebase as with SwiftGen's). Just to say that I'll get to this one soon-ish. |
@kylef @djbe @yonaskolb will it make sense if I try to update this? Or we should just close all related issues and forget about this like it never happened? 🙄 |
@ilyapuchka yeah I’d love for this to get merged. It’s the last holdout for me to use this over my fork. For my purposes I’d need to have this on by default via a setting on environment |
I'm waiting for this!!! Meanwhile on my machine...
|
I was working on this last night. Will get something up hopefully tonight. It includes the behaviour in this PR as well as a way to set a default behaviour in the environment |
To go around this issue I switched to mustache and followed the workaround explained in groue/GRMustache#46 (comment). Same workaround can be followed in stencil. |
This has been attempted at least twice in #85 and #32 .
In #89 you expressed interest in the way this is done in Jinja2, I've attempted to recreate that here. This is still Review because I'm waiting on feedback before adding: