-
Notifications
You must be signed in to change notification settings - Fork 2
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
Does not work if doctype is returned instead of Frag #44
Comments
Thanks for reporting, much appreciated! Unfortunately this project is only lightly-maintained at the moment (see #1, feel free to volunteer!) but I hope if you have a breakthrough you will report back and/or open a PR. |
@armanbilge Can I update this project to use scala 3? I am really having difficulties with fixing this. My project is using scala 3: trait ScalatagsInstances {
implicit def scalatagsEncoder[C <: Frag[_, String] | doctype](implicit
charset: Charset = `UTF-8`
): EntityEncoder.Pure[C] =
contentEncoder(MediaType.text.html)
private def contentEncoder[C <: Frag[_, String] | doctype](
mediaType: MediaType
)(implicit charset: Charset): EntityEncoder.Pure[C] =
EntityEncoder.stringEncoder
// .contramap[C](content => content.render)
.contramap[C](_ match
case content: doctype => content.render
case content: Frag[_, String] => content.render
)
.withContentType(`Content-Type`(mediaType, charset))
} This throws this warning, but it compiles and runs:
The people at the discord server told me to look into:
So I did a bit of researching and found this: https://stackoverflow.com/a/38572269
Maybe this would be worth reading also: https://squidarth.com/scala/types/2019/01/11/type-erasure-scala.html I don't know how to write this in scala 2 since there are no union types: trait ScalatagsInstances {
implicit def scalatagsEncoder[F[_], C <: Frag[_, String]](implicit
charset: Charset = `UTF-8`
): EntityEncoder[F, C] =
contentEncoder(MediaType.text.html)
private def contentEncoder[F[_], C <: Frag[_, String]](
mediaType: MediaType
)(implicit charset: Charset): EntityEncoder[F, C] =
EntityEncoder.stringEncoder[F]
// .contramap[C](content => content.render)
.contramap[C] {
case content: doctype => content.render
case content: Frag[_, String] => content.render
}
.withContentType(`Content-Type`(mediaType, charset))
} I have found this to get around the union type, but I can't figure it out: https://www.baeldung.com/scala/type-disjunction Do you have any idea on how to solve this? |
@mabasic have you consider defining a new |
I have not xD I'll do that tomorrow... Thank you for the suggestion ❤️ |
https://github.com/http4s/http4s-scalatags/blob/series/0.24/scalatags/src/main/scala/org/http4s/scalatags/ScalatagsInstances.scala#L25
https://github.com/com-lihaoyi/scalatags/blob/0cfff0c972d7e198210379eeac1a18ef6cd2d6bf/scalatags/src/scalatags/Text.scala#L70
Does not work because the return type of doctype is doctype:
Works because the return type of html is Frag[Builder, String] or something like that.
I can't decide where to create a fix in scalatags and have doctype return Frag, or in http4s and have it correctly handle doctype and Frag.
@armanbilge We talked about this on discord a few days ago.
The text was updated successfully, but these errors were encountered: