playframework / twirl

Twirl is Play's default template engine
Apache License 2.0
545 stars 108 forks source link

[1.6.x] Fix whitespaces after `else{...}` and `elseif{...}` is not shown #712

Closed yousuketto closed 10 months ago

yousuketto commented 10 months ago

The parser does not recognize whitespace after else {...} as a plain, so it is not showing.

Refs #711

yousuketto commented 10 months ago

Oh, I didn't notice the document. As you say, it has to be changed as the following. Thanks.

  *   elseCall : whitespaceNoBreak? "else" whitespaceNoBreak? expressionPart
yousuketto commented 10 months ago

Furthermore, I noticed that elseIfCall has the same bug as elseCall. I'll fix it too.

@(b: Boolean, b2: Boolean)
x@if(b) {ifbody} <-whitespace
x@if(b) {ifbody} else if(b2) {elseifbody} <-whitespace
scala> com.github.yousuketto.txt.sample(true, false)
val res0: play.twirl.api.TxtFormat.Appendable =
xifbody <-whitespace
xifbody<-whitespace

scala> com.github.yousuketto.txt.sample(false, false)
val res1: play.twirl.api.TxtFormat.Appendable =
x <-whitespace
x<-whitespace

scala> com.github.yousuketto.txt.sample(false, true)
val res2: play.twirl.api.TxtFormat.Appendable =
x <-whitespace
xelseifbody<-whitespace
yousuketto commented 10 months ago

I also fixed a bug in elseIfCall. If we need to split this pull request, I'll split it. Please let me know.

mkurz commented 10 months ago

Perfect, thanks!

mkurz commented 10 months ago

@Mergifyio backport main

mergify[bot] commented 10 months ago

backport main

✅ Backports have been created

* [#713 [main] Fix whitespaces after `else{...}` and `elseif{...}` is not shown (backport #712) by @yousuketto](https://github.com/playframework/twirl/pull/713) has been created for branch `main`
mkurz commented 10 months ago

Thanks! This is now included in just released twirl 1.6.3 and 2.0.2

yousuketto commented 10 months ago

It's so helpful. Thanks for releasing.