-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a18ede6
commit 81f6655
Showing
9 changed files
with
82 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package tyrian | ||
|
||
import tyrian.* | ||
|
||
val DOCTYPE: String = "<!DOCTYPE HTML>" | ||
|
||
private val spacer = (str: String) => if str.isEmpty then str else " " + str | ||
|
||
extension [Msg](elem: Elem[Msg]) | ||
def render: String = | ||
elem match | ||
case _: Empty.type => "" | ||
case t: Text => t.value | ||
case h: Html[_] => h.render | ||
|
||
extension [Msg](html: Html[Msg]) | ||
def render: String = | ||
html match | ||
case tag: RawTag[_] => | ||
val attributes = | ||
spacer(tag.attributes.map(_.render).filterNot(_.isEmpty).mkString(" ")) | ||
s"""<${tag.name}$attributes>${tag.innerHTML}</${tag.name}>""" | ||
case tag: Tag[_] => | ||
val attributes = | ||
spacer(tag.attributes.map(_.render).filterNot(_.isEmpty).mkString(" ")) | ||
|
||
val children = tag.children.map { | ||
case _: Empty.type => "" | ||
case t: Text => t.value | ||
case h: Html[_] => h.render | ||
}.mkString | ||
|
||
s"""<${tag.name}$attributes>$children</${tag.name}>""" | ||
|
||
extension (a: Attr[_]) | ||
def render: String = | ||
a match | ||
case _: Event[_, _] => "" | ||
case a: Attribute => a.render | ||
case p: Property => p.render | ||
case a: NamedAttribute => a.name | ||
case _: EmptyAttribute.type => "" | ||
|
||
extension (a: Attribute) | ||
def render: String = | ||
s"""${a.name}="${a.value}"""" | ||
|
||
extension (p: Property) | ||
def render: String = | ||
val asStr: String = | ||
p.valueOf match | ||
case x: Boolean => x.toString | ||
case x: String => x | ||
|
||
s"""${p.name}="${asStr}"""" | ||
|
||
extension [Msg](elems: List[Elem[Msg]]) | ||
def render: String = | ||
elems.map(_.render).mkString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 0 additions & 80 deletions
80
tyrian/shared/src/main/scala/tyrian/runtime/TyrianSSR.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.