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

Introduce apply as alternative to := #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scalatags/src/scalatags/generic/Attrs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ trait GlobalAttrs[Builder, Output <: FragT, FragT]
def selectDynamic(s: String) = new DataAttribute(s :: sections)
def :=[T](v: T)(implicit ev: AttrValue[Builder, T]) =
AttrPair(Attr(sections.reverse.mkString("-")), v, ev)
def apply[T](v: T)(implicit ev: AttrValue[Builder, T]) = :=(v)(ev)
}
def data(suffix: String) = Attr("data-" + suffix)
/**
Expand Down
4 changes: 4 additions & 0 deletions scalatags/src/scalatags/generic/Core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ case class Attr(name: String, namespace: Option[Namespace] = None, raw: Boolean
requireNonNull(v)
AttrPair(this, v, ev)
}
def apply[Builder, T](v: T)(implicit ev: AttrValue[Builder, T]) = :=(v)(ev)

def empty[Builder](implicit ev: AttrValue[Builder, String]) = this := name
}
Expand All @@ -127,6 +128,7 @@ case class Style(jsName: String, cssName: String) {
requireNonNull(v)
StylePair(this, v, ev)
}
def apply[Builder, T](v: T)(implicit ev: StyleValue[Builder, T]) = :=(v)(ev)
}
/**
* Wraps up a CSS style in a value.
Expand All @@ -141,6 +143,7 @@ case class PixelStyle(jsName: String, cssName: String) {
requireNonNull(v)
ev(realStyle, v)
}
def apply[Builder, T](v: T)(implicit ev: PixelStyleValue[Builder, T]) = :=(v)(ev)

}
trait StyleProcessor{
Expand All @@ -157,6 +160,7 @@ case class AttrPair[Builder, T](a: Attr, v: T, ev: AttrValue[Builder, T]) extend
requireNonNull(v)
AttrPair(a, v, ev)
}
def apply[Builder, T](v: T)(implicit ev: AttrValue[Builder, T]) = :=(v)(ev)
}
/**
* Used to specify how to handle a particular type [[T]] when it is used as
Expand Down
2 changes: 2 additions & 0 deletions scalatags/src/scalatags/generic/Styles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ trait Styles2[Builder, Output <: FragT, FragT] extends StyleMisc[Builder, Output
*/
object columns extends Style("columns", "columns") {
def :=(number: Int, width: String): StylePair[Builder, String] = this := s"$number $width"
def apply(number: Int, width: String): StylePair[Builder, String] = this.:=(number, width)
}

/**
Expand Down Expand Up @@ -1174,6 +1175,7 @@ trait Styles[Builder, Output <: FragT, FragT] extends StyleMisc[Builder, Output,
*/
object borderSpacing extends Style("borderSpacing", "border-spacing") {
def :=(horizontal: String, vertical: String): StylePair[Builder, String] = this := s"$horizontal $vertical"
def apply(horizontal: String, vertical: String): StylePair[Builder, String] = this.:=(horizontal, vertical)
}


Expand Down
12 changes: 12 additions & 0 deletions scalatags/test/src/scalatags/generic/BasicTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ class BasicTests[Builder, Output <: FragT, FragT](omg: Bundle[Builder, Output, F
"""<a tabindex="1" onclick="lol" href="boo" alt="g"></a>"""
)
}
test("apply instead of :="){
strCheck(
a(
tabindex(1),
onclick("lol")
)(
href("boo"),
alt("g")
),
"""<a tabindex="1" onclick="lol" href="boo" alt="g"></a>"""
)
}
test("autoPixel"){
strCheck(
div(width:=100, zIndex:=100, height:=100),
Expand Down
2 changes: 1 addition & 1 deletion scalatags/test/src/scalatags/generic/StyleSheetTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class StyleSheetTests[Builder, Output <: FragT, FragT]
height := 125
)
val y = cls.hover(
opacity := 0.5
opacity(0.5)
)

val z = cls(x.splice, y.splice)
Expand Down