-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor import statements * Render product as table * Bugfix: renderSelect in enumForm to update variable and sync parent
- Loading branch information
Showing
22 changed files
with
618 additions
and
405 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Usage | ||
|
||
## Basic usage | ||
|
||
```scala sc:nocompile | ||
import dev.cheleb.scalamigen.* | ||
``` | ||
This import is necessary to bring the implicit conversions into scope. | ||
|
||
Now you can use the `asForm` method on any `Var` to render a form for the value it holds with double binding. | ||
|
||
```scala sc:nocompile | ||
|
||
case class Cat(name: String, age: Int) | ||
|
||
val eitherVar = Var(Cat("Scala le chat", 6)) | ||
|
||
eitherVar.asForm // (2) form rendering | ||
|
||
``` | ||
|
||
As long as the case class is built on elments that have a `Form[..]` instance, the form will be rendered correctly. | ||
|
||
## Supported types | ||
|
||
* `String`, `Int`, `Long`, `Double`, `Boolean` | ||
* `LocalDate` | ||
* `Option[A]` | ||
* `List[A]` | ||
* `Either[A, B]` | ||
* `IronType[T, C]` | ||
* `Positive` | ||
|
||
## Customizing the form rendering | ||
|
||
At anytime you can customize the form rendering by providing a `Form` instance for the type you want to render. | ||
|
||
* `opaque type` | ||
```scala sc:nocompile | ||
opaque type Password = String | ||
object Password: | ||
def apply(password: String): Password = password | ||
given Form[Password] = secretForm(apply) // (1) form instance | ||
|
||
``` | ||
* `IronType` | ||
|
||
```scala sc:nocompile | ||
doubleGreaterThanEight: Double :| GreaterEqual[8.0] | ||
|
||
given IronTypeValidator[Double, GreaterEqual[8.0]] = | ||
_.toDoubleOption match | ||
case None => Left("Not a number") | ||
case Some(double) => double.refineEither[GreaterEqual[8.0]] | ||
|
||
``` |
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,6 @@ | ||
index: index.html | ||
subsection: | ||
- title: Getting Started | ||
page: getting-started.html | ||
- title: Usage | ||
index: usage.html |
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 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 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 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
Oops, something went wrong.