diff --git a/build.sbt b/build.sbt index 4d7736a..711a815 100644 --- a/build.sbt +++ b/build.sbt @@ -92,7 +92,7 @@ val staticGenerationSettings = (generator / Compile / runMain) .toTask { Seq( - "BuildIndex", + "samples.BuildIndex", "--title", s""""Laminar Form Derivation v ${version.value}"""", "--resource-managed", diff --git a/examples/generator/src/main/scala/TwirlTemplate.scala b/examples/generator/src/main/scala/samples/TwirlTemplate.scala similarity index 98% rename from examples/generator/src/main/scala/TwirlTemplate.scala rename to examples/generator/src/main/scala/samples/TwirlTemplate.scala index 35ae702..7b1ca65 100644 --- a/examples/generator/src/main/scala/TwirlTemplate.scala +++ b/examples/generator/src/main/scala/samples/TwirlTemplate.scala @@ -1,3 +1,5 @@ +package samples + import java.io.File import io.* diff --git a/modules/core/src/main/scala/dev/cheleb/scalamigen/Forms.scala b/modules/core/src/main/scala/dev/cheleb/scalamigen/Forms.scala index d5e08cd..9a1dc63 100644 --- a/modules/core/src/main/scala/dev/cheleb/scalamigen/Forms.scala +++ b/modules/core/src/main/scala/dev/cheleb/scalamigen/Forms.scala @@ -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]] { @@ -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], @@ -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] = diff --git a/modules/core/src/main/scala/dev/cheleb/scalamigen/IronTypeValidator.scala b/modules/core/src/main/scala/dev/cheleb/scalamigen/IronTypeValidator.scala index 211ddf0..a13d34a 100644 --- a/modules/core/src/main/scala/dev/cheleb/scalamigen/IronTypeValidator.scala +++ b/modules/core/src/main/scala/dev/cheleb/scalamigen/IronTypeValidator.scala @@ -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] { diff --git a/modules/core/src/main/scala/dev/cheleb/scalamigen/WidgetFactory.scala b/modules/core/src/main/scala/dev/cheleb/scalamigen/WidgetFactory.scala index 2f18dae..14ca369 100644 --- a/modules/core/src/main/scala/dev/cheleb/scalamigen/WidgetFactory.scala +++ b/modules/core/src/main/scala/dev/cheleb/scalamigen/WidgetFactory.scala @@ -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 diff --git a/modules/ui5/src/main/scala/dev/cheleb/scalamigen/ui5/UI5WidgetFactory.scala b/modules/ui5/src/main/scala/dev/cheleb/scalamigen/ui5/UI5WidgetFactory.scala index 2ffaa1c..7f5d478 100644 --- a/modules/ui5/src/main/scala/dev/cheleb/scalamigen/ui5/UI5WidgetFactory.scala +++ b/modules/ui5/src/main/scala/dev/cheleb/scalamigen/ui5/UI5WidgetFactory.scala @@ -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 diff --git a/website.sbt b/website.sbt index 1132b81..570e825 100644 --- a/website.sbt +++ b/website.sbt @@ -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" )