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

Feature: Add implicit conversion from Unit to Html #1204

Merged
merged 1 commit into from
Apr 14, 2022
Merged
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
3 changes: 3 additions & 0 deletions zio-http/src/main/scala/zhttp/html/Html.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package zhttp.html

import scala.annotation.nowarn
import scala.language.implicitConversions

/**
Expand All @@ -22,6 +23,8 @@ object Html {

implicit def fromDomElement(element: Dom): Html = Html.Single(element)

implicit def fromUnit(@nowarn unit: Unit): Html = Html.Empty

private[zhttp] case class Single(element: Dom) extends Html

private[zhttp] final case class Multiple(children: Seq[Dom]) extends Html
Expand Down
8 changes: 7 additions & 1 deletion zio-http/src/test/scala/zhttp/html/HtmlSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ case object HtmlSpec extends DefaultRunnableSpec {
val view = div("Hello!", css := "container" :: Nil)
val expected = """<div class="container">Hello!</div>"""
assert(view.encode)(equalTo(expected.stripMargin))
},
} +
suite("implicit conversions")(
test("from unit") {
val view: Html = {}
assert(view.encode)(equalTo(""))
},
),
)
}
}