forked from PurpleKingdomGames/tyrian
-
Notifications
You must be signed in to change notification settings - Fork 0
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
cf9cf04
commit c193c7d
Showing
13 changed files
with
453 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
object Dependancies { | ||
object Dependencies { | ||
|
||
val indigoVersion = "0.15.2" | ||
|
||
|
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,114 @@ | ||
import sbt._ | ||
import scala.sys.process._ | ||
|
||
object HtmxAttributes { | ||
lazy val htmxAttrs = List( | ||
Normal("hxOn", "hx-on"), // TODO: this is the deprecated version, should be hx-on:event | ||
|
||
Normal("hxBoost", "hx-boost"), | ||
Normal("hxGet", "hx-get"), | ||
Normal("hxPost", "hx-post"), | ||
Normal("hxPushUrl", "hx-push-url"), | ||
Normal("hxSelect", "hx-select"), | ||
Normal("hxSelectOob", "hx-select-oob"), | ||
Normal("hxSwap", "hx-swap"), | ||
Normal("hxSwapOob", "hx-swap-oob"), | ||
Normal("hxTarget", "hx-target"), | ||
Normal("hxTrigger", "hx-trigger"), | ||
Normal("hxVals", "hx-vals"), | ||
Normal("hxConfirm", "hx-confirm"), | ||
Normal("hxDelete", "hx-delete"), | ||
NoValue("hxDisable", "hx-disable"), | ||
Normal("hxDisabledElt", "hx-disabled-elt"), | ||
Normal("hxDisinherit", "hx-disinherit"), | ||
Normal("hxEncoding", "hx-encoding"), | ||
Normal("hxExt", "hx-ext"), | ||
Normal("hxHeaders", "hx-headers"), | ||
Normal("hxHistory", "hx-history").withTypes("String", "Boolean"), | ||
NoValue("hxHistoryElt", "hx-history-elt"), | ||
Normal("hxInclude", "hx-include"), | ||
Normal("hxIndicator", "hx-indicator"), | ||
Normal("hxParams", "hx-params"), | ||
Normal("hxPatch", "hx-patch"), | ||
NoValue("hxPreserve", "hx-preserve"), | ||
Normal("hxPrompt", "hx-prompt"), | ||
Normal("hxPut", "hx-put"), | ||
Normal("hxReplaceUrl", "hx-replace-url").withTypes("String", "Boolean"), | ||
Normal("hxRequest", "hx-request"), | ||
Normal("hxSync", "hx-sync"), | ||
Normal("hxValidate", "hx-validate"), | ||
Normal("hxVars", "hx-vars") | ||
) | ||
|
||
def htmxAttrsList: AttributesList = AttributesList(htmxAttrs, List(), "HtmxAttributes") | ||
|
||
def genAttr(tag: AttributeType, isAttribute: Boolean): String = | ||
tag match { | ||
case Normal("hxTrigger", Some("hx-trigger"), _) => genHtmxTrigger | ||
case Normal(name, attrName, types) => AttributeGen.genNormal(name, attrName, types) | ||
case NoValue(name, attrName) => AttributeGen.genNoValue(name, attrName) | ||
} | ||
|
||
def triggerAttributeName = | ||
s""" final class AttributeNameTrigger(name: String): | ||
| def :=(value: Trigger): Attribute = Attribute(name.toString, value.render) | ||
| final class AttributeNameTriggers(name: String): | ||
| def :=(values: List[Trigger]): Attribute = Attribute(name.toString, values.map(_.render).mkString(",")) | ||
|""".stripMargin | ||
|
||
def genHtmxTrigger: String = { | ||
val res = s""" @targetName("hxTrigger-Trigger") | ||
| val hxTrigger: AttributeNameTrigger = AttributeNameTrigger("hx-trigger") | ||
| @targetName("hxTrigger-Triggers") | ||
| val hxTrigger: AttributeNameTriggers = AttributeNameTriggers("hx-trigger") | ||
| @targetName("hxTrigger-String") | ||
| val hxTrigger: AttributeNameString = AttributeNameString("hx-trigger") | ||
|""".stripMargin | ||
|
||
"\n" + res + "\n" | ||
} | ||
|
||
def template(moduleName: String, fullyQualifiedPath: String, contents: String): String = | ||
s"""package $fullyQualifiedPath | ||
| | ||
|import tyrian.* | ||
|import tyrian.Html.* | ||
|import scala.annotation.targetName | ||
| | ||
|// GENERATED by AttributeGen.scala - DO NOT EDIT | ||
|trait $moduleName { | ||
| | ||
|$contents | ||
| | ||
|} | ||
""".stripMargin | ||
|
||
def gen(fullyQualifiedPath: String, sourceManagedDir: File)(attributesList: AttributesList): File = | ||
attributesList match { | ||
case AttributesList(attrs, props, name) => | ||
val file: File = | ||
sourceManagedDir / s"$name.scala" | ||
|
||
if (!file.exists()) { | ||
println("Generating Html Attributes") | ||
|
||
val contents: String = | ||
AttributeGen.generateAttributeNameTypes + | ||
AttributeGen.genAttributesAndProperties + | ||
triggerAttributeName + | ||
"\n\n // Attributes\n\n" + | ||
attrs.map(a => genAttr(a, true)).mkString + | ||
"\n\n // Properties\n\n" + | ||
props.map(p => genAttr(p, false)).mkString | ||
|
||
val newContents: String = | ||
template(name, fullyQualifiedPath, contents) | ||
|
||
IO.write(file, newContents) | ||
|
||
println("Written: " + file.getCanonicalPath) | ||
} | ||
|
||
file | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
sandbox-ssr/.jvm/src/main/scala/example/CorvidDatabase.scala
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,43 @@ | ||
package example | ||
|
||
import cats.Applicative | ||
import cats.implicits.* | ||
|
||
trait CorvidDatabase[F[_]]: | ||
def search(query: String): F[List[(String, String)]] | ||
def listAll: F[List[(String, String)]] | ||
|
||
object CorvidDatabase: | ||
private val data: List[(String, String)] = List( | ||
"Canada Jay" -> "Perisoreus canadensis", | ||
"Green Jay" -> "Cyanocorax yncas", | ||
"Pinyon Jay" -> "Gymnorhinus cyanocephalus", | ||
"Steller's Jay" -> "Cyanocitta stelleri", | ||
"Blue Jay" -> "Cyanocitta cristata", | ||
"Florida Scrub-Jay" -> "Aphelocoma coerulescens", | ||
"California Scrub-Jay" -> "Aphelocoma californica", | ||
"Woodhouse's Scrub-Jay" -> "Aphelocoma woodhouseii", | ||
"Mexican Jay" -> "Aphelocoma wollweberi", | ||
"Black-billed Magpie" -> "Pica hudsonia", | ||
"Yellow-billed Magpie" -> "Pica nuttalli", | ||
"Clark's Nutcracker" -> "Nucifraga columbiana", | ||
"American Crow" -> "Corvus brachyrhynchos", | ||
"Fish Crow" -> "Corvus ossifragus", | ||
"Chihuahuan Raven" -> "Corvus cryptoleucus", | ||
"Eurasian Magpie" -> "Pica pica", | ||
"Eurasian Jackdaw" -> "Corvus monedula", | ||
"Common Raven" -> "Corvus corax" | ||
) | ||
|
||
def fakeImpl[F[_]: Applicative]: CorvidDatabase[F] = | ||
new CorvidDatabase[F]: | ||
override def search(query: String): F[List[(String, String)]] = | ||
data | ||
.filter(row => | ||
row._1.toLowerCase.contains(query.toLowerCase) || | ||
row._2.toLowerCase.contains(query.toLowerCase) | ||
) | ||
.pure[F] | ||
|
||
override def listAll: F[List[(String, String)]] = | ||
data.pure[F] |
Oops, something went wrong.