Closed tbje closed 2 years ago
I'd like to speak in favour of merging this commit ASAP. In my case, I got bit by creating a set of classes to add with code similar to the following:
def myClasses(cond1: Boolean, cond2: Boolean) =
cls := Seq(
if (cond1) "cond1" else "",
if (cond2) "cond2" else ""
).mkString(" ")
Of the four possible ways to call myClasses
, one of them fails when the html is rendered:
p(myClasses(false, true), "my paragraph").toString() ==> "<p class=\"cond2\">my paragraph</p>"
Or, in a simpler form (note the leading space in " cond2"
):
p(cls := " cond2", "my paragraph").toString() ==> "<p class=\"cond2\">my paragraph</p>"
Curiously, a trailing space in the class renders just fine.
@bwbecker IDK if this is more readable to you, but you can use Option[AttrValue]
and Option[AttrPair]
:
https://scastie.scala-lang.org/9BDfZS9xQpq8xgrHcJityA (the last example)
Also, the 2.13's Option.when
is really handy for these. 😃
classList.add("")
throws an exception that is somehow swallowed.