com-lihaoyi / scalatags

ScalaTags is a small XML/HTML construction library for Scala.
https://com-lihaoyi.github.io/scalatags/
MIT License
758 stars 117 forks source link

Combining scalatags.stylesheet classes and `cls :=` classes behaves badly #139

Closed lihaoyi closed 5 years ago

lihaoyi commented 8 years ago
@ import $ivy.`com.lihaoyi::scalatags:0.6.0`, scalatags.Text.all._
import $ivy.$                             , scalatags.Text.all._
@ object Foo extends scalatags.stylesheet.StyleSheet{
    val myCls = cls(color := "red")
  }
defined object Foo
@ div(Foo.myCls, cls := "red") // Badly concatenated
res2: scalatags.Text.TypedTag[String] = <div class=" $sess-cmd1-Foo-myClsred"></div>
@ div(cls := "red", Foo.myCls) // Seems to work
res3: scalatags.Text.TypedTag[String] = <div class="red $sess-cmd1-Foo-myCls"></div>

For some reason, if the stylesheet class is applied before the manual class, the output is borked. The other way around works just fine. This should be fixed

bwbecker commented 7 years ago

This also fails on a much simpler case. Note the classes "red" and "yellow" are concatenated into "redyellow".

scsmac081:scalatags bwbecker$ /usr/local/Cellar/scala/2.11.8/bin/scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions for evaluation. Or try :help.

scala> :require /Users/bwbecker/.ivy2/cache/com.lihaoyi/scalatags_2.11/jars/scalatags_2.11-0.6.1.jar
Added '/Users/bwbecker/.ivy2/cache/com.lihaoyi/scalatags_2.11/jars/scalatags_2.11-0.6.1.jar' to classpath.

scala> import scalatags.Text.all._
import scalatags.Text.all._

scala> div(cls := "red", cls := "yellow")
res0: scalatags.Text.TypedTag[String] = <div class="redyellow"></div>
bwbecker commented 6 years ago

This is still an issue in 0.6.7 (and I just got bit by it again):

belser:scalatags bwbecker$ /usr/local/Cellar/scala/2.12.4/bin/scala
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_121).
Type in expressions for evaluation. Or try :help.

scala> :require /Users/bwbecker/.ivy2/cache/com.lihaoyi/scalatags_2.12/jars/scalatags_2.12-0.6.7.jar
Added '/Users/bwbecker/.ivy2/cache/com.lihaoyi/scalatags_2.12/jars/scalatags_2.12-0.6.7.jar' to classpath.

scala> import scalatags.Text.all._
import scalatags.Text.all._

scala> div()
res0: scalatags.Text.TypedTag[String] = <div></div>

scala> div(cls := "red", cls := "yellow")
res1: scalatags.Text.TypedTag[String] = <div class="redyellow"></div>

In the last line it should be <div class="red yellow"></div> -- needs a space.

Pull request #152 fixes it...