Skip to content

Commit

Permalink
Website (#123)
Browse files Browse the repository at this point in the history
* Add doc

* Clean samples

* Simpler

* Add twirl index page generation for server demo.

* Fix dev

* Useless import
  • Loading branch information
cheleb authored Nov 26, 2023
1 parent 7a58d39 commit d55708a
Show file tree
Hide file tree
Showing 29 changed files with 468 additions and 306 deletions.
76 changes: 39 additions & 37 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
//import ProjectDef._
import java.nio.charset.StandardCharsets
import org.scalajs.linker.interface.ModuleSplitStyle

lazy val currentYear: String =
java.util.Calendar.getInstance().get(java.util.Calendar.YEAR).toString

val scala33 = "3.3.1"

inThisBuild(
Expand Down Expand Up @@ -43,6 +39,15 @@ inThisBuild(
)
)

lazy val generator = project
.in(file("examples/generator"))
.enablePlugins(SbtTwirl)
.settings(
libraryDependencies += "com.github.scopt" %% "scopt" % "4.1.0",
libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.9.2",
libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.7.32"
)

val dev = sys.env.get("DEV").isDefined

val serverPlugins = dev match {
Expand All @@ -63,6 +68,7 @@ val serverSettings = dev match {
lazy val root = project
.in(file("."))
.aggregate(
generator,
server,
core,
ui5,
Expand All @@ -74,9 +80,36 @@ lazy val root = project
publish / skip := true
)

val staticGenerationSettings =
if (dev) Seq()
else
Seq(
Assets / resourceGenerators += Def
.taskDyn[Seq[File]] {
val baseDir = baseDirectory.value
val rootFolder = (Assets / resourceManaged).value / "public"
rootFolder.mkdirs()
(generator / Compile / runMain)
.toTask {
Seq(
"BuildIndex",
"--title",
s""""Laminar Form Derivation v ${version.value}"""",
"--resource-managed",
rootFolder
).mkString(" ", " ", "")
}
.map(_ => (rootFolder ** "*.html").get)
}
.taskValue
)

lazy val server = project
.in(file("examples/server"))
.enablePlugins(serverPlugins: _*)
.settings(
staticGenerationSettings
)
.settings(
fork := true,
scalaJSProjects := Seq(example),
Expand All @@ -102,7 +135,8 @@ val usedScalacOptions = Seq(
"-unchecked",
"-language:higherKinds",
"-language:implicitConversions",
"-Xmax-inlines:64"
"-Xmax-inlines:64",
"-Wunused:all"
)
lazy val core = scalajsProject("core", false)
.settings(
Expand Down Expand Up @@ -222,35 +256,3 @@ Global / onLoad := {

(Global / onLoad).value
}
enablePlugins(
SiteScaladocPlugin,
SitePreviewPlugin,
ScalaUnidocPlugin,
GhpagesPlugin
)

ScalaUnidoc / siteSubdirName := ""
addMappingsToSiteDir(
ScalaUnidoc / packageDoc / mappings,
ScalaUnidoc / siteSubdirName
)
git.remoteRepo := "[email protected]:cheleb/laminar-form-derivation.git"
ghpagesNoJekyll := true
Compile / doc / scalacOptions ++= Seq(
"-siteroot",
"docs",
"-project",
"Laminar Form Derivation",
"-groups",
"-project-version",
version.value,
"-revision",
version.value,
"-default-templates",
"static-site-main",
"-project-footer",
s"Copyright (c) 2022-$currentYear, Olivier NOUGUIER",
"-Ygenerate-inkuire",
"-skip-by-regex:demo\\..*",
"-skip-by-regex:samples\\..*"
)
47 changes: 47 additions & 0 deletions docs/_docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Getting Started

## Installation

```sbt
libraryDependencies += "dev.cheleb" %%% "laminar-form-derivation" % "{{ version }}"
```

### Requirements

### Sample

```scala sc:nocompile

import dev.cheleb.scalamigen.{*, given}
import dev.cheleb.scalamigen.ui5.UI5WidgetFactory

import com.raquo.laminar.api.L.*

import com.raquo.airstream.state.Var

given WidgetFactory = UI5WidgetFactory

case class Cat(name: String, age: Int)
case class Dog(name: String, age: Int)

val either = {

case class EitherSample(
either: Either[Cat, Dog],
optionalInt: Option[Int]
)

val eitherVar = Var(EitherSample(Left(Cat("Scala le chat", 6)), Some(1)))

div(
child <-- eitherVar.signal.map { item =>
div(
s"$item"
)
},
Form.renderVar(eitherVar)
)
}


```
8 changes: 8 additions & 0 deletions docs/_docs/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```scala mdoc
import java.time.Instant

def now() = Instant.now()
object Foo extends App{
println(now())
}
```
1 change: 1 addition & 0 deletions examples/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 25 additions & 46 deletions examples/client/src/main/scala/HelloWorld.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
package demo
package samples

import org.scalajs.dom
import com.raquo.laminar.api.L.*
import be.doeraene.webcomponents.ui5.*
import samples.tree

case class Sample(name: String, component: HtmlElement)

object App extends App {

val sample = Var(samples.enums)
val sample = Var(samples.enums.component)

private def item(name: String) = SideNavigation.item(
_.text := name,
dataAttr("component-name") := name
)

private val demos = Seq(
samples.simple,
samples.either,
samples.enums,
samples.person,
samples.validation,
samples.list,
samples.tree
)

val myApp =
div(
Expand All @@ -23,51 +39,14 @@ object App extends App {
_.events.onSelectionChange
.map(_.detail.item.dataset.get("componentName")) --> Observer[
Option[String]
] {
case e @ Some("Either") =>
sample.set(samples.either)
case e @ Some("Enums") =>
sample.set(samples.enums)
case v @ Some("Person") =>
sample.set(samples.person)
case v @ Some("Validation") =>
sample.set(samples.validation)
case v @ Some("Lists") =>
sample.set(
samples.component
)
case v @ Some("Tree") =>
sample.set(tree.component)
case _ =>
sample.set(div("????"))
] { name =>
val el = name
.flatMap(n => demos.find(_.name == n))

sample.set(el.map(_.component).getOrElse(div("Not found")))

},
Seq(
SideNavigation.item(
_.text := "Either",
dataAttr("component-name") := "Either"
),
SideNavigation.item(
_.text := "Enums",
dataAttr("component-name") := "Enums"
),
SideNavigation.item(
_.text := "Person",
dataAttr("component-name") := "Person"
),
SideNavigation.item(
_.text := "Validation",
dataAttr("component-name") := "Validation"
),
SideNavigation.item(
_.text := "List",
dataAttr("component-name") := "Lists"
),
SideNavigation.item(
_.text := "Tree",
dataAttr("component-name") := "Tree"
)
)
demos.map(_.name).map(item)
)
),
div(
Expand Down
4 changes: 2 additions & 2 deletions examples/client/src/main/scala/WebSocketDemo.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package polyui
package samples

import com.raquo.laminar.api.L.{*, given}
import com.raquo.laminar.api.L.*
import be.doeraene.webcomponents.ui5.*
import be.doeraene.webcomponents.ui5.configkeys.*
import io.laminext.websocket._
Expand Down
32 changes: 17 additions & 15 deletions examples/client/src/main/scala/samples/EitherSample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ import com.raquo.laminar.api.L.*

import com.raquo.airstream.state.Var

val either = {
val either = Sample(
"Either", {

case class EitherSample(
either: Either[Cat, Dog],
optionalInt: Option[Int]
)
case class EitherSample(
either: Either[Cat, Dog],
optionalInt: Option[Int]
)

val eitherVar = Var(EitherSample(Left(Cat("Scala le chat", 6)), Some(1)))
val eitherVar = Var(EitherSample(Left(Cat("Scala le chat", 6)), Some(1)))

div(
child <-- eitherVar.signal.map { item =>
div(
s"$item"
)
},
Form.renderVar(eitherVar)
)
}
div(
child <-- eitherVar.signal.map { item =>
div(
s"$item"
)
},
Form.renderVar(eitherVar)
)
}
)
60 changes: 31 additions & 29 deletions examples/client/src/main/scala/samples/EnumSample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,34 @@ import com.raquo.laminar.api.L.*

import com.raquo.airstream.state.Var

val enums = {

enum Color(code: String):
case Black extends Color("000")
case White extends Color("FFF")
case Isabelle extends Color("???")

case class Basket(@EnumValues(Color.values) color: Color, cat: Cat)

case class Cat(
name: String,
age: Int,
@EnumValues(Color.values)
color: Color
)

val eitherVar = Var(
Basket(Color.Black, Cat("Scala", 10, Color.White))
)

div(
child <-- eitherVar.signal.map { item =>
div(
s"$item"
)
},
Form.renderVar(eitherVar)
)
}
val enums = Sample(
"Enums", {

enum Color(val code: String):
case Black extends Color("000")
case White extends Color("FFF")
case Isabelle extends Color("???")

case class Basket(@EnumValues(Color.values) color: Color, cat: Cat)

case class Cat(
name: String,
age: Int,
@EnumValues(Color.values)
color: Color
)

val eitherVar = Var(
Basket(Color.Black, Cat("Scala", 10, Color.White))
)

div(
child <-- eitherVar.signal.map { item =>
div(
s"$item"
)
},
Form.renderVar(eitherVar)
)
}
)
Loading

0 comments on commit d55708a

Please sign in to comment.