Skip to content

Commit

Permalink
propose
Browse files Browse the repository at this point in the history
refactor

refactor

refactor
  • Loading branch information
linux-root authored and davesmith00000 committed Jan 11, 2025
1 parent d604a3e commit 7ca2039
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tyrian-tags/js/src/main/scala/tyrian/syntax.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package tyrian

import tyrian.Html.text

object syntax:

extension [M](oa: Option[Elem[M]]) def orEmpty: Elem[M] = oa.getOrElse(tyrian.Empty)

given Conversion[String, Text] = text(_)
given Conversion[Int, Text] = n => text(n.toString)
given Conversion[Double, Text] = d => text(d.toString)
26 changes: 26 additions & 0 deletions tyrian-tags/js/src/test/scala/tyrian/HtmlTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,30 @@ class HtmlTests extends munit.FunSuite {

}

test("literal values : text, number implicit conversion") {
import tyrian.syntax.given

trait Msg

val example1: Html[Msg] = div[Msg](cls := "container")(
"text abc ",
"Total are: ",
28,
div(cls := "inner")(99.99)
)

val example2 = button(
tpe := "button",
cls := "inline-flex items-center p"
)(
"Messages",
span(
cls := "inline-flex items-center"
)(2)
)

println(example1.render)
println(example2.render)
}

}

0 comments on commit 7ca2039

Please sign in to comment.