Skip to content

Commit

Permalink
Scaladoc
Browse files Browse the repository at this point in the history
  • Loading branch information
cheleb committed Nov 27, 2023
1 parent e8a12d2 commit 7fb488a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ val staticGenerationSettings =
(generator / Compile / runMain)
.toTask {
Seq(
"BuildIndex",
"samples.BuildIndex",
"--title",
s""""Laminar Form Derivation v ${version.value}"""",
"--resource-managed",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package samples

import java.io.File

import io.*
Expand Down
18 changes: 18 additions & 0 deletions modules/core/src/main/scala/dev/cheleb/scalamigen/Forms.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,35 @@ import com.raquo.laminar.api.L.*
import scala.util.Try
import com.raquo.airstream.state.Var

/** Default value for Int is 0.
*/
given Defaultable[Int] with
def default = 0

/** Default value for String is "".
*/
given Defaultable[String] with
def default = ""

/** Default value for [Iron type Double
* positive](https://iltotore.github.io/iron/io/github/iltotore/iron/constraint/numeric$.html#Positive-0)
* is 0.0.
*/
given Defaultable[IronType[Double, Positive]] with
def default = 1.0.refine[Positive]

/** Validator for [Iron type Double
* positive](https://iltotore.github.io/iron/io/github/iltotore/iron/constraint/numeric$.html#Positive-0).
*/
given IronTypeValidator[Double, Positive] with
def validate(a: String): Either[String, IronType[Double, Positive]] =
a.toDoubleOption match
case None => Left("Not a number")
case Some(double) => double.refineEither[Positive]

/** Form for an Iron type. This is a form for a type that can be validated with
* an Iron type.
*/
given [T, C](using fv: IronTypeValidator[T, C]): Form[IronType[T, C]] =
new Form[IronType[T, C]] {

Expand All @@ -39,6 +53,8 @@ given [T, C](using fv: IronTypeValidator[T, C]): Form[IronType[T, C]] =
variable.set(value)
}

/** Form for to a string, aka without validation.
*/
given Form[String] with
override def render(
variable: Var[String],
Expand Down Expand Up @@ -71,6 +87,8 @@ def stringForm[A](to: String => A) = new Form[A]:
}
)

/** Form for a numeric type.
*/
def numericForm[A](f: String => Option[A], zero: A): Form[A] = new Form[A] {
self =>
override def fromString(s: String): Option[A] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package dev.cheleb.scalamigen

import io.github.iltotore.iron.IronType

/** Type validator for IronType.
/** Type validator for
* [IronType](https://iltotore.github.io/iron/docs/index.html).
*
* Iron is a library for compile-time type validation. See
* https://iltotore.github.io/iron/ for more information.
* Iron is a library for compile-time or runtime type validation.
*/
trait IronTypeValidator[T, C] {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,40 @@ import com.raquo.laminar.modifiers.EventListener
/** This is a trait that defines the interface for the widget factory.
*/
trait WidgetFactory:
/** Render a text input, for strings.
*/
def renderText: HtmlElement

/** Render a label for a widget.
*/
def renderLabel(required: Boolean, name: String): HtmlElement

/** Render a numeric input, for numbers.
*/
def renderNumeric: HtmlElement

/** Render a button.
*/
def renderButton: HtmlElement

/** Render a link.
*/
def renderLink(text: String, obs: EventListener[_, _]): HtmlElement

/** Render a panel. This is a container for other widgets derived from a case
* class.
*/
def renderPanel(headerText: String): HtmlElement

/** Render an unordered list. This is a container for other widgets derived
* from a case class.
*/
def renderUL(id: String): HtmlElement

/** Render a select.
*/
def renderSelect(f: Int => Unit): HtmlElement

/** Render an option.
*/
def renderOption(label: String, idx: Int, selected: Boolean): HtmlElement
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import com.raquo.laminar.modifiers.EventListener
import be.doeraene.webcomponents.ui5.configkeys.ListSeparator
import be.doeraene.webcomponents.ui5.configkeys.TitleLevel

/** UI5WidgetFactory is a factory for [SAP UI5
* widgets](https://sap.github.io/ui5-webcomponents/).
*
* It relies on [Laminar UI5
* bindings](https://github.com/sherpal/LaminarSAPUI5Bindings).
*/
object UI5WidgetFactory extends dev.cheleb.scalamigen.WidgetFactory:
def renderText: HtmlElement = Input(
_.showClearIcon := true
Expand Down
1 change: 1 addition & 0 deletions website.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ Compile / doc / scalacOptions ++= Seq(
s"Copyright (c) 2022-$currentYear, Olivier NOUGUIER",
"-Ygenerate-inkuire",
"-skip-by-regex:samples\\..*",
"-skip-by-regex:html\\..*",
"-snippet-compiler:compile"
)

0 comments on commit 7fb488a

Please sign in to comment.