diff --git a/.gitignore b/.gitignore index e35d885..a233446 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ _build +todos/ + diff --git a/dream-html/Dream_html/Aria/index.html b/dream-html/Dream_html/Aria/index.html index 380744e..f2bffc1 100644 --- a/dream-html/Dream_html/Aria/index.html +++ b/dream-html/Dream_html/Aria/index.html @@ -1,2 +1,2 @@ -
Dream_html.Aria
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/
val activedescendant : _ string_attr
val atomic : attr
val autocomplete : [ `inline | `list | `both ] to_attr
val braillelabel : _ string_attr
val brailleroledescription : _ string_attr
val busy : attr
val checked : [ `false_ | `true_ | `mixed ] to_attr
val colcount : int to_attr
val colindextext : _ string_attr
val colspan : int to_attr
val controls : _ string_attr
val current : [ `page | `step | `location | `date | `time | `true_ ] to_attr
val describedby : _ string_attr
val description : _ string_attr
val details : _ string_attr
val disabled : attr
val errormessage : _ string_attr
val expanded : bool to_attr
val flowto : _ string_attr
val haspopup : [ `true_ | `menu | `listbox | `tree | `grid | `dialog ] to_attr
val invalid : [ `grammar | `spelling | `true_ ] to_attr
val keyshortcuts : _ string_attr
val label : _ string_attr
val labelledby : _ string_attr
val level : int to_attr
val live : [ `assertive | `off | `polite ] to_attr
⚠️ Screen readers want a live region to be defined statically from page load on a visible element, eg p [id "toast"; Aria.live `polite] []
. The element must not be hidden initially, otherwise the screen reader will continue to ignore it even when its content is changed.
val modal : attr
val multiline : attr
val multiselectable : attr
val orientation : [ `horizontal | `vertical ] to_attr
val owns : _ string_attr
val placeholder : _ string_attr
val posinset : int to_attr
val pressed : [ `false_ | `mixed | `true_ ] to_attr
val readonly : attr
val relevant : [ `additions | `all | `removals | `text ] to_attr
val required : attr
val roledescription : _ string_attr
val rowcount : int to_attr
val rowindex : int to_attr
val rowindextext : _ string_attr
val rowspan : int to_attr
val selected : bool to_attr
val setsize : int to_attr
val sort : [ `ascending | `descending | `other ] to_attr
val valuemax : float to_attr
val valuemin : float to_attr
val valuenow : float to_attr
val valuetext : _ string_attr
Dream_html.Aria
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/
val activedescendant : _ string_attr
val atomic : attr
val autocomplete : [ `inline | `list | `both ] to_attr
val braillelabel : _ string_attr
val brailleroledescription : _ string_attr
val busy : attr
val checked : [ `false_ | `true_ | `mixed ] to_attr
val colcount : int to_attr
val colindextext : _ string_attr
val colspan : int to_attr
val controls : _ string_attr
val current : [ `page | `step | `location | `date | `time | `true_ ] to_attr
val describedby : _ string_attr
val description : _ string_attr
val details : _ string_attr
val disabled : attr
val errormessage : _ string_attr
val expanded : bool to_attr
val flowto : _ string_attr
val haspopup : [ `true_ | `menu | `listbox | `tree | `grid | `dialog ] to_attr
val invalid : [ `grammar | `spelling | `true_ ] to_attr
val keyshortcuts : _ string_attr
val label : _ string_attr
val labelledby : _ string_attr
val level : int to_attr
val live : [ `assertive | `off | `polite ] to_attr
⚠️ Screen readers want a live region to be defined statically from page load on a visible element, eg p [id "toast"; Aria.live `polite] []
. The element must not be hidden initially, otherwise the screen reader will continue to ignore it even when its content is changed.
`off
since 3.10.0
val modal : attr
val multiline : attr
val multiselectable : attr
val orientation : [ `horizontal | `vertical ] to_attr
val owns : _ string_attr
val placeholder : _ string_attr
val posinset : int to_attr
val pressed : [ `false_ | `mixed | `true_ ] to_attr
val readonly : attr
val relevant : [ `additions | `all | `removals | `text ] to_attr
val required : attr
val roledescription : _ string_attr
val rowcount : int to_attr
val rowindex : int to_attr
val rowindextext : _ string_attr
val rowspan : int to_attr
val selected : bool to_attr
val setsize : int to_attr
val sort : [ `ascending | `descending | `other ] to_attr
val valuemax : float to_attr
val valuemin : float to_attr
val valuenow : float to_attr
val valuetext : _ string_attr
Dream_html.Atom
val link : std_tag
Dream_html.Atom
Dream_html.Form
Typed, extensible HTML form decoder with error reporting for form field validation failures. Powerful chained decoding functionality–the validation of one field can depend on the values of other decoded fields.
See the bottom of the page for complete examples.
The type of a decoder for a single form field value of type 'a
which can successfully decode the field value or fail with an error message key.
In the following type decoders, the minimum and maximum values are all inclusive.
val bool : bool ty
val char : ?min:char -> ?max:char -> char ty
val float : ?min:float -> ?max:float -> float ty
val int : ?min:int -> ?max:int -> int ty
val int32 : ?min:int32 -> ?max:int32 -> int32 ty
val int64 : ?min:int64 -> ?max:int64 -> int64 ty
val string : ?min_length:int -> ?max_length:int -> string ty
val unix_tm : ?min:Unix.tm -> ?max:Unix.tm -> Unix.tm ty
This can parse strings with the formats 2024-01-01
or 2024-01-01T00:00:00
into a timestamp.
Note that this is not timezone-aware.
The type of a form (a form field by itself is also considered a form) which can decode values of type 'a
or fail with a list of error message keys.
val ok : 'a -> 'a t
ok value
is a form field that always successfully returns value
.
val error : string -> string -> 'a t
error name message
is a form field that always errors the field name
with the message
.
These allow adding adding further checks to the entire form using all decoded field values and then attaching more errors to specific fields (or not).
list ?min_length ?max_length ty name
is a form field which can decode a list of values which can each be decoded by ty
. The list must have at least min_length
and at most max_length
(inclusive).
optional ty name
is a form field which can decode an optional value from the form.
required ?default ty name
is a form field which can decode a required value from the form. If at least one value corresponding to the given name
does not appear in the form, and if a default
value is not specified, the decoding fails with an error.
multiple n form
is a form which can decode a list of nested form values. It tries to decode exactly n
values and fails if it can't find all of them. Assumes that the items are 0-indexed. See Multiple structured values for a complete example.
val ensure :
+Form (dream-html.Dream_html.Form) Module Dream_html.Form
Typed, extensible HTML form decoder with error reporting for form field validation failures. Powerful chained decoding functionality–the validation of one field can depend on the values of other decoded fields.
See the bottom of the page for complete examples.
Basic type decoders
The type of a decoder for a single form field value of type 'a
which can successfully decode the field value or fail with an error message key.
In the following type decoders, the minimum and maximum values are all inclusive.
val bool : bool ty
val char : ?min:char -> ?max:char -> char ty
val float : ?min:float -> ?max:float -> float ty
val int : ?min:int -> ?max:int -> int ty
val int32 : ?min:int32 -> ?max:int32 -> int32 ty
val int64 : ?min:int64 -> ?max:int64 -> int64 ty
val string : ?min_length:int -> ?max_length:int -> string ty
val unix_tm : ?min:Unix.tm -> ?max:Unix.tm -> Unix.tm ty
This can parse strings with the formats 2024-01-01
or 2024-01-01T00:00:00
into a timestamp.
Note that this is not timezone-aware.
Forms and fields
The type of a form (a form field by itself is also considered a form) which can decode values of type 'a
or fail with a list of error message keys.
val ok : 'a -> 'a t
ok value
is a form field that always successfully returns value
.
val error : string -> string -> 'a t
error name message
is a form field that always errors the field name
with the message
.
These allow adding adding further checks to the entire form using all decoded field values and then attaching more errors to specific fields (or not).
list ?min_length ?max_length ty name
is a form field which can decode a list of values which can each be decoded by ty
. The list must have at least min_length
and at most max_length
(inclusive).
optional ty name
is a form field which can decode an optional value from the form.
required ?default ty name
is a form field which can decode a required value from the form. If at least one value corresponding to the given name
does not appear in the form, and if a default
value is not specified, the decoding fails with an error.
multiple n form
is a form which can decode a list of nested form values. It tries to decode exactly n
values and fails if it can't find all of them. Assumes that the items are 0-indexed. See Multiple structured values for a complete example.
val ensure :
string ->
('b -> bool) ->
('a ty -> string -> 'b t) ->
@@ -10,39 +10,44 @@
...
However, note that let*
uses a 'fail-fast' decoding strategy. If there is a decoding error, it immediately returns the error without decoding the subsequent fields. (Which makes sense if you think about the example above.) So, in order to ensure complete error reporting for all fields, you would need to use let+
and and+
.
let+ email = required string "email"
decodes a form field named email
as a string
.
and+ password = required string "password"
continues decoding in an existing form declaration and decodes a form field password
as a string
.
val validate :
'a t ->
(string * string) list ->
- ('a, (string * string) list) Stdlib.result
validate form values
is a result of validating the given form
's values
. It may be either some value of type 'a
or a list of form field names and the corresponding error message keys.
pp_error
is a helper pretty-printer for debugging/troubleshooting form validation errors.
Error keys
When errors are reported, the following keys are used instead of English strings. These keys can be used for localizing the error messages. The suggested default English translations are given below.
These keys are modelled after Play Framework.
Examples
Basic functionality
type user = { name : string; age : int option }
+ ('a, (string * string) list) Stdlib.result
validate form values
is a result of validating the given form
's values
. It may be either some value of type 'a
or a list of form field names and the corresponding error message keys.
pp_error
is a helper pretty-printer for debugging/troubleshooting form validation errors.
When errors are reported, the following keys are used instead of English strings. These keys can be used for localizing the error messages. The suggested default English translations are given below.
These keys are modelled after Play Framework.
type user =
+ { name : string;
+ age : int option
+ }
open Dream_html.Form
let user_form =
let+ name = required string "name"
- and+ age = optional (int ~min:16) "age" in (* Thanks, Australia! *)
+ and+ age = optional (int ~min:16) "age" in
+ (* Thanks, Australia! *)
{ name; age }
let dream_form = ["age", "42"; "name", "Bob"]
-let user_result = validate user_form dream_form
Result: Ok { name = "Bob"; age = Some 42 }
Sad path:
validate user_form ["age", "none"]
Result: Error [("age", "error.expected.int"); ("name", "error.required")]
type plan = { id : string; features : string list }
+let user_result = validate user_form dream_form
Result: Ok { name = "Bob"; age = Some 42 }
Sad path:
validate user_form ["age", "none"]
Result: Error [("age", "error.expected.int"); ("name", "error.required")]
type plan =
+ { id : string;
+ features : string list
+ }
let plan_form =
let+ id = required string "id"
and+ features = list string "features" in
- { id; features }
-
-validate plan_form ["id", "foo"]
Result: Ok {id = "foo"; features = []}
validate plan_form ["id", "foo"; "features", "f1"; "features", "f2"]
Result: Ok {id = "foo"; features = ["f1"; "f2"]}
Note that the names can be anything, eg "features[]"
if you prefer.
let plan_form =
- let+ id = ensure "error.expected.nonempty" (( <> ) "") required string "id"
+ { id; features } validate plan_form ["id", "foo"]
Result: Ok {id = "foo"; features = []}
validate plan_form ["id", "foo"; "features", "f1"; "features", "f2"]
Result: Ok {id = "foo"; features = ["f1"; "f2"]}
Note that the names can be anything, eg "features[]"
if you prefer.
let plan_form =
+ let+ id =
+ ensure "error.expected.nonempty" (( <> ) "") required string "id"
and+ features = list string "features" in
- { id; features }
-
-validate plan_form ["id", ""]
Result: Error [("id", "error.expected.nonempty")]
Using chained validation rules where some fields depend on others:
type req = {
- id : string;
- years : int option;
- months : int option;
- weeks : int option;
- days : int option;
-}
+ { id; features } validate plan_form ["id", ""]
Result: Error [("id", "error.expected.nonempty")]
Using chained validation rules where some fields depend on others:
type req =
+ { id : string;
+ years : int option;
+ months : int option;
+ weeks : int option;
+ days : int option
+ }
let req_form =
let+ id = required string "id" (* Both id... *)
- and+ days, weeks, months, years = (* ...and period are required *)
+ and+ days, weeks, months, years =
+ (* ...and period are required *)
let* days = optional int "days" in
let* weeks = optional int "weeks" in
let* months = optional int "months" in
@@ -52,15 +57,21 @@
(* Only one period component is required *)
| _ -> ok (days, weeks, months, years)
in
- { id; days; weeks; months; years }
-
-validate req []
Result: Error [("years", "Please enter a period"); ("id", "error.required")]
Suppose you have the following form data submitted:
item-count: 2
+ { id; days; weeks; months; years } validate req []
Result: Error [("years", "Please enter a period"); ("id", "error.required")]
Suppose you have the following form data submitted:
item-count: 2
item[0].id: abc
item[0].qty: 1
item[1].id: def
item[1].qty: 10
-item[1].discount: 25
And you want to decode it into the following types:
type item = { id : string; qty : int; discount : int }
-type invoice = { item_count : int; items : item list }
First create the indexed invoice item decoder and invoice decoder:
let item n =
+item[1].discount: 25
And you want to decode it into the following types:
type item =
+ { id : string;
+ qty : int;
+ discount : int
+ }
+
+type invoice =
+ { item_count : int;
+ items : item list
+ }
First create the indexed invoice item decoder and invoice decoder:
let item n =
let nth name = "item[" ^ string_of_int n ^ "]." ^ name in
let+ id = required string (nth "id")
and+ qty = required int (nth "qty")
@@ -70,20 +81,21 @@
let invoice =
let* item_count = required int "item-count" in
let+ items = multiple item_count item in
- { item_count; items }
Try it:
validate invoice [
- "item[0].id", "abc"; "item[0].qty", "1";
- "item[1].id", "def"; "item[1].qty", "10"; "item[1].discount", "25";
- "item-count", "2";
-]
Result:
Ok {
- item_count = 2;
- items = [
- {id = "def"; qty = 10; discount = 25};
- {id = "abc"; qty = 1; discount = 0};
- ];
-}
Validation error:
validate invoice [
- "item[0].qty", "1";
- "item[1].id", "def"; "item[1].discount", "25";
- "item-count", "2";
-]
-
-Error [item[0].id, error.required; item[1].qty, error.required]
Try it:
validate invoice
+ [ "item[0].id", "abc";
+ "item[0].qty", "1";
+ "item[1].id", "def";
+ "item[1].qty", "10";
+ "item[1].discount", "25";
+ "item-count", "2" ]
Result:
Ok
+ { item_count = 2;
+ items =
+ [ { id = "def"; qty = 10; discount = 25 };
+ { id = "abc"; qty = 1; discount = 0 } ]
+ }
Validation error:
validate invoice
+ [ "item[0].qty", "1";
+ "item[1].id", "def";
+ "item[1].discount", "25";
+ "item-count", "2" ]
+ Error
+ [item [0].id, error.required; item [1].qty, error.required]
Dream_html.HTML
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
Standard, most non-deprecated attributes from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. Where an attribute name conflicts with an OCaml keyword, the name is suffixed with _
. Most attributes are constructed by passing in a value of some type.
All string-valued attributes allow formatting (interpolation):
div [id "section-%d" section_id] []
Or plain strings:
p [id "toast"] []
Most boolean attributes are plain values and don't need to be constructed with function calls:
input [required]
However, boolean attributes which may be inherited and toggled on/off in children, are constructed by passing in a value:
div [contenteditable true] [
- p [] [txt "Edit me!"];
- p [contenteditable false] [txt "Can't edit me!"];
-]
Enumerated attributes accept specific values:
input [inputmode `tel]
val null_ : attr
An attribute that will not be rendered in the markup. Useful for conditional logic where you sometimes want to render an attribute and sometimes not.
p [if should_show then null_ else style_ "display:none"] [txt "Show and tell"]
val accept : _ string_attr
val accept_charset : _ string_attr
val accesskey : _ string_attr
val action : _ string_attr
val align : _ string_attr
val allow : _ string_attr
val alt : _ string_attr
val as_ : _ string_attr
val async : attr
val autocapitalize :
+HTML (dream-html.Dream_html.HTML) Module Dream_html.HTML
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
Attributes
Standard, most non-deprecated attributes from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. Where an attribute name conflicts with an OCaml keyword, the name is suffixed with _
. Most attributes are constructed by passing in a value of some type.
All string-valued attributes allow formatting (interpolation):
div [id "section-%d" section_id] []
Or plain strings:
p [id "toast"] []
Most boolean attributes are plain values and don't need to be constructed with function calls:
input [required]
However, boolean attributes which may be inherited and toggled on/off in children, are constructed by passing in a value:
div
+ [contenteditable true]
+ [ p [] [txt "Edit me!"];
+ p [contenteditable false] [txt "Can't edit me!"] ]
Enumerated attributes accept specific values:
input [inputmode `tel]
val null_ : attr
An attribute that will not be rendered in the markup. Useful for conditional logic where you sometimes want to render an attribute and sometimes not.
p
+ [(if should_show then null_ else style_ "display:none")]
+ [txt "Show and tell"]
val accept : _ string_attr
val accept_charset : _ string_attr
val accesskey : _ string_attr
val action : _ string_attr
val align : _ string_attr
val allow : _ string_attr
val alt : _ string_attr
val as_ : _ string_attr
val async : attr
val autocapitalize :
[< `off | `none | `on | `sentences | `words | `characters ] to_attr
val autocomplete :
[< `off
| `on
@@ -64,10 +66,10 @@
| `default_style
| `x_ua_compatible
| `refresh ]
- to_attr
val id : _ string_attr
val integrity : _ string_attr
val inputmode :
+ to_attr
val id : _ string_attr
val inert : attr
val integrity : _ string_attr
val inputmode :
[< `none | `text | `decimal | `numeric | `tel | `search | `email | `url ]
to_attr
val ismap : attr
val itemprop : _ string_attr
val kind :
- [< `subtitles | `captions | `descriptions | `chapters | `metadata ] to_attr
val label_ : _ string_attr
val lang : _ string_attr
val list : _ string_attr
val loading_lazy : attr
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#loading. loading=eager
is the default so no need for specifically that value.
val loop : attr
val low : float to_attr
val max : _ string_attr
val maxlength : int to_attr
val media : _ string_attr
val min : _ string_attr
val minlength : int to_attr
val multiple : attr
val muted : attr
val name : _ string_attr
val novalidate : attr
val onblur : _ string_attr
Note that the value of this attribute is not escaped.
val onclick : _ string_attr
Note that the value of this attribute is not escaped.
val open_ : attr
val optimum : float to_attr
val pattern : _ string_attr
val ping : _ string_attr
val placeholder : _ string_attr
val playsinline : attr
val poster : _ string_attr
val preload : [< `none | `metadata | `auto ] to_attr
val readonly : attr
val referrerpolicy :
+ [< `subtitles | `captions | `descriptions | `chapters | `metadata ] to_attr
val label_ : _ string_attr
val lang : _ string_attr
val list : _ string_attr
val loading_lazy : attr
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#loading. loading=eager
is the default so no need for specifically that value.
val loop : attr
val low : float to_attr
val max : _ string_attr
val maxlength : int to_attr
val media : _ string_attr
val min : _ string_attr
val minlength : int to_attr
val multiple : attr
val muted : attr
val name : _ string_attr
val novalidate : attr
val onblur : _ string_attr
Note that the value of this attribute is not escaped.
val onclick : _ string_attr
Note that the value of this attribute is not escaped.
val open_ : attr
val optimum : float to_attr
val pattern : _ string_attr
val ping : _ string_attr
val placeholder : _ string_attr
val playsinline : attr
val popover : [< `auto | `manual ] to_attr
val popovertarget : _ string_attr
val popovertargetaction : [< `hide | `show ] to_attr
toggle
is the default.
val poster : _ string_attr
val preload : [< `none | `metadata | `auto ] to_attr
val readonly : attr
val referrerpolicy :
[< `no_referrer
| `no_referrer_when_downgrade
| `origin
@@ -150,12 +152,11 @@
| `tree
| `treegrid
| `treeitem ]
- to_attr
val rows : int to_attr
val rowspan : int to_attr
val sandbox : _ string_attr
val scope : _ string_attr
val selected : attr
val shape : _ string_attr
val size : _ string_attr
val sizes : _ string_attr
val slot_ : _ string_attr
val span_ : int to_attr
val spellcheck : bool to_attr
val src : _ string_attr
val srcdoc : _ string_attr
val srclang : _ string_attr
val srcset : _ string_attr
val start : int to_attr
val step : _ string_attr
val style_ : _ string_attr
Note that the value of this attribute is not escaped.
val tabindex : int to_attr
val target : _ string_attr
val title_ : _ string_attr
val translate : [< `yes | `no ] to_attr
val type_ : _ string_attr
Note: this can't be restricted to just the allowed values for <input type>
, because it's used in other elements e.g. <link type>
.
val usemap : _ string_attr
val value : _ string_attr
val width : _ string_attr
val wrap : [< `hard | `soft ] to_attr
Tags
HTML tags. Most (standard tags) are constructed by passing a list of attributes and a list of children:
div [id "my-div"] [p [] [txt "Hello"]]
Some (void elements) are constructed only with a list of attributes:
input [required; type_ "email"; name "email-addr"]
Finally, a few (text elements) are constructed with a list of attributes and a single format string child:
title [] "Document title"
-
-title [] "My App ・ %s" page_name
-
-script [] {|alert('Careful, this is not escaped :-)');|}
A tag that will not be rendered in the markup. Useful for containing a bunch of child nodes inside a single node without having to litter the DOM with an actual node. Also may be called 'splicing'.
null [
- p [] [txt "This paragraph."];
- p [] [txt "And this paragraph."];
- p [] [txt "Are spliced directly into the document without a containing node."];
-]
Also useful for constructing a completely empty node that is erased when printing:
null []
val a : std_tag
val address : std_tag
val area : void_tag
val abbr : std_tag
val article : std_tag
val aside : std_tag
val audio : std_tag
val b : std_tag
val base : void_tag
val bdi : std_tag
val bdo : std_tag
val blockquote : std_tag
val body : std_tag
val br : void_tag
val button : std_tag
val canvas : std_tag
val cite : std_tag
val code : std_tag
val col : void_tag
val colgroup : std_tag
val data : std_tag
val datalist : std_tag
val dd : std_tag
val del : std_tag
val details : std_tag
val dfn : std_tag
val dialog : std_tag
val div : std_tag
val dl : std_tag
val dt : std_tag
val em : std_tag
val embed : void_tag
val fieldset : std_tag
val figure : std_tag
val form : std_tag
val h1 : std_tag
val h2 : std_tag
val h3 : std_tag
val h4 : std_tag
val h5 : std_tag
val h6 : std_tag
val head : std_tag
val header : std_tag
val hgroup : std_tag
val hr : void_tag
val html : std_tag
A <!DOCTYPE html>
declaration is automatically prefixed when this tag is printed.
val i : std_tag
val iframe : std_tag
val img : void_tag
val input : void_tag
val ins : std_tag
val kbd : std_tag
val label : std_tag
val legend : std_tag
val li : std_tag
val link : void_tag
val main : std_tag
val map : std_tag
val mark : std_tag
val meta : void_tag
val meter : std_tag
val noscript : std_tag
val object_ : std_tag
val ol : std_tag
val optgroup : std_tag
val option : _ text_tag
val output : std_tag
val p : std_tag
val picture : std_tag
val pre : std_tag
val progress : std_tag
val q : std_tag
val rp : std_tag
val rt : std_tag
val ruby : std_tag
val s : std_tag
val samp : std_tag
val script : _ text_tag
Note that the content of this tag is not escaped.
val section : std_tag
val select : std_tag
val slot : std_tag
val small : std_tag
val source : void_tag
val span : std_tag
val strong : std_tag
val style : _ text_tag
Note that the content of this tag is not escaped.
val sub : std_tag
val summary : std_tag
val sup : std_tag
val table : std_tag
val tbody : std_tag
val td : std_tag
val template : std_tag
val textarea : _ text_tag
val tfoot : std_tag
val th : std_tag
val thead : std_tag
val time : std_tag
val title : _ text_tag
val tr : std_tag
val track : void_tag
val u : std_tag
val ul : std_tag
val var : std_tag
val video : std_tag
val wbr : void_tag
+ to_attr
val rows : int to_attr
val rowspan : int to_attr
val sandbox : _ string_attr
val scope : _ string_attr
val selected : attr
val shadowrootclonable : attr
val shadowrootdelegatesfocus : attr
val shadowrootmode : [ `open_ | `closed ] to_attr
val shape : _ string_attr
val size : _ string_attr
val sizes : _ string_attr
val slot_ : _ string_attr
val span_ : int to_attr
val spellcheck : bool to_attr
val src : _ string_attr
val srcdoc : _ string_attr
val srclang : _ string_attr
val srcset : _ string_attr
val start : int to_attr
val step : _ string_attr
val style_ : _ string_attr
Note that the value of this attribute is not escaped.
val tabindex : int to_attr
val target : _ string_attr
val title_ : _ string_attr
val translate : [< `yes | `no ] to_attr
val type_ : _ string_attr
Note: this can't be restricted to just the allowed values for <input type>
, because it's used in other elements e.g. <link type>
.
val usemap : _ string_attr
val value : _ string_attr
val width : _ string_attr
val wrap : [< `hard | `soft ] to_attr
HTML tags. Most (standard tags) are constructed by passing a list of attributes and a list of children:
div [id "my-div"] [p [] [txt "Hello"]]
Some (void elements) are constructed only with a list of attributes:
input [required; type_ "email"; name "email-addr"]
Finally, a few (text elements) are constructed with a list of attributes and a single format string child:
title [] "Document title" title [] "My App ・ %s" page_name script []
+ {|alert('Careful, this is not escaped :-)');|}
A tag that will not be rendered in the markup. Useful for containing a bunch of child nodes inside a single node without having to litter the DOM with an actual node. Also may be called 'splicing'.
null
+ [ p [] [txt "This paragraph."];
+ p [] [txt "And this paragraph."];
+ p []
+ [ txt
+ "Are spliced directly into the document without a containing node."
+ ] ]
Also useful for constructing a completely empty node that is erased when printing: null []
.
val a : std_tag
val address : std_tag
val area : void_tag
val abbr : std_tag
val article : std_tag
val aside : std_tag
val audio : std_tag
val b : std_tag
val base : void_tag
val bdi : std_tag
val bdo : std_tag
val blockquote : std_tag
val body : std_tag
val br : void_tag
val button : std_tag
val canvas : std_tag
val cite : std_tag
val code : std_tag
val col : void_tag
val colgroup : std_tag
val data : std_tag
val datalist : std_tag
val dd : std_tag
val del : std_tag
val details : std_tag
val dfn : std_tag
val dialog : std_tag
val div : std_tag
val dl : std_tag
val dt : std_tag
val em : std_tag
val embed : void_tag
val fieldset : std_tag
val figure : std_tag
val form : std_tag
val h1 : std_tag
val h2 : std_tag
val h3 : std_tag
val h4 : std_tag
val h5 : std_tag
val h6 : std_tag
val head : std_tag
val header : std_tag
val hgroup : std_tag
val hr : void_tag
val html : std_tag
A <!DOCTYPE html>
declaration is automatically prefixed when this tag is printed.
val i : std_tag
val iframe : std_tag
val img : void_tag
val input : void_tag
val ins : std_tag
val kbd : std_tag
val label : std_tag
val legend : std_tag
val li : std_tag
val link : void_tag
val main : std_tag
val map : std_tag
val mark : std_tag
val meta : void_tag
val meter : std_tag
val noscript : std_tag
val object_ : std_tag
val ol : std_tag
val optgroup : std_tag
val option : _ text_tag
val output : std_tag
val p : std_tag
val picture : std_tag
val pre : std_tag
val progress : std_tag
val q : std_tag
val rp : std_tag
val rt : std_tag
val ruby : std_tag
val s : std_tag
val samp : std_tag
val script : _ text_tag
Note that the content of this tag is not escaped.
val search : std_tag
val section : std_tag
val select : std_tag
val selectedoption : std_tag
val slot : std_tag
val small : std_tag
val source : void_tag
val span : std_tag
val strong : std_tag
val style : _ text_tag
Note that the content of this tag is not escaped.
val sub : std_tag
val summary : std_tag
val sup : std_tag
val table : std_tag
val tbody : std_tag
val td : std_tag
val template : std_tag
val textarea : _ text_tag
val tfoot : std_tag
val th : std_tag
val thead : std_tag
val time : std_tag
val title : _ text_tag
val tr : std_tag
val track : void_tag
val u : std_tag
val ul : std_tag
val var : std_tag
val video : std_tag
val wbr : void_tag
Dream_html.Hx
htmx support
The attributes in this module are arranged in the same order as on the reference page linked above.
Remember that you will also need the htmx script itself. The recommended way to get it is to download a copy and place it in your static assets directory, managed by dreamwork so that it is properly cached and version-hashed by its contents.
val get : _ string_attr
val post : _ string_attr
val on_ : event:string -> _ string_attr
The hx-on:*
set of attributes, where *
represents DOM events: https://htmx.org/attributes/hx-on/.
Note that the value of this attribute is not escaped.
val push_url : _ string_attr
val select : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val select_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val target : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val trigger : _ string_attr
Note that the value of this attribute is not escaped.
val vals : _ string_attr
val boost : bool to_attr
val confirm : _ string_attr
val delete : _ string_attr
val disable : attr
val disabled_elt : _ string_attr
val disinherit : _ string_attr
val encoding_formdata : attr
Hardcoding of the hx-encoding
attribute to multipart/form-data
.
val ext : _ string_attr
val headers : _ string_attr
val history_false : attr
Hardcoding of the hx-history
attribute to false
.
val history_elt : attr
val include_ : _ string_attr
val indicator : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val inherit_ : _ string_attr
val params : _ string_attr
val patch : _ string_attr
val preserve : attr
val prompt : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ string_attr
val sync : _ string_attr
val validate : attr
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val sse_close : _ string_attr
val sse_connect : _ string_attr
val sse_swap : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
val __ : _ string_attr
This attribute serves as the _ attribute, which is used by Hyperscript. Note that the value of this attribute is not escaped.
val on : _ string_attr
Note that the value of this attribute is not escaped.
Dream_html.Hx
htmx support
The attributes in this module are arranged in the same order as on the reference page linked above.
Remember that you will also need the htmx script itself. The recommended way to get it is to download a copy and place it in your static assets directory, managed by dreamwork so that it is properly cached and version-hashed by its contents.
val get : _ string_attr
val post : _ string_attr
val on_ : event:string -> _ string_attr
The hx-on:*
set of attributes, where *
represents DOM events: https://htmx.org/attributes/hx-on/.
Note that the value of this attribute is not escaped.
val push_url : _ string_attr
val select : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val select_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val target : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val trigger : _ string_attr
Note that the value of this attribute is not escaped.
val vals : _ string_attr
val boost : bool to_attr
val confirm : _ string_attr
val delete : _ string_attr
val disable : attr
val disabled_elt : _ string_attr
val disinherit : _ string_attr
val encoding_formdata : attr
Hardcoding of the hx-encoding
attribute to multipart/form-data
.
val ext : _ string_attr
val headers : _ string_attr
val history_false : attr
Hardcoding of the hx-history
attribute to false
.
val history_elt : attr
val include_ : _ string_attr
val indicator : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val inherit_ : _ string_attr
val params : _ string_attr
val patch : _ string_attr
val preserve : attr
val prompt : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ string_attr
val sync : _ string_attr
val validate : attr
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val sse_close : _ string_attr
val sse_connect : _ string_attr
val sse_swap : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
val __ : _ string_attr
This attribute serves as the _ attribute, which is used by Hyperscript. Note that the value of this attribute is not escaped.
val on : _ string_attr
Note that the value of this attribute is not escaped.
Dream_html.Livereload
Live reload script injection and handling. Adapted from Dream.livereload
middleware. This version is not a middleware so it's not as plug-and-play as that, but on the other hand it's much simpler to implement because it uses type-safe dream-html nodes rather than parsing and printing raw HTML. See below for the 3-step process to use it.
This module is adapted from Dream, released under the MIT license. For details, visit https://github.com/aantron/dream.
Copyright 2021-2023 Thibaut Mattio, Anton Bachin.
(1) Put this in your top-level router:
let () =
+Livereload (dream-html.Dream_html.Livereload) Module Dream_html.Livereload
Live reload script injection and handling. Adapted from Dream.livereload
middleware. This version is not a middleware so it's not as plug-and-play as that, but on the other hand it's much simpler to implement because it uses type-safe dream-html nodes rather than parsing and printing raw HTML. See below for the 3-step process to use it.
This module is adapted from Dream, released under the MIT license. For details, visit https://github.com/aantron/dream.
Copyright 2021-2023 Thibaut Mattio, Anton Bachin.
(1) Put this in your top-level router:
let () =
Dream.run
@@ Dream.logger
- @@ Dream.router [
- Dream_html.Livereload.route;
- (* ...other routes... *)
- ]
val script : node
(2) Put this inside your head
:
head [] [Livereload.script (* ... *)]
(3) And run the server with environment variable LIVERELOAD=1
.
⚠️ If this env var is not set, then livereload is turned off. This means that the route
will respond with 404
status and the script will be omitted from the rendered HTML.
+ @@ Dream.router [Dream_html.Livereload.route (* ...other routes... *)]
val script : node
(2) Put this inside your head
:
head [] [Livereload.script (* ... *)]
(3) And run the server with environment variable LIVERELOAD=1
.
⚠️ If this env var is not set, then livereload is turned off. This means that the route
will respond with 404
status and the script will be omitted from the rendered HTML.
Dream_html.MathML
val accent : bool to_attr
val accentunder : bool to_attr
val columnspan : int to_attr
val depth : _ string_attr
val dir : [ `ltr | `rtl ] to_attr
val display_block : attr
See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#display. display=inline
is the default, so there is no need to bind its value.
val displaystyle : bool to_attr
val fence : bool to_attr
val height : _ string_attr
val largeop : bool to_attr
val linethickness : _ string_attr
val lspace : _ string_attr
val mathvariant : _ string_attr
val maxsize : _ string_attr
val minsize : _ string_attr
val movablelimits : bool to_attr
val rowspan : int to_attr
val rspace : _ string_attr
val scriptlevel : _ string_attr
val separator : bool to_attr
val stretchy : bool to_attr
val symmetric : bool to_attr
val voffset : _ string_attr
val xmlns : attr
val annotation : std_tag
val annotation_xml : std_tag
val math : std_tag
val merror : std_tag
val mfrac : std_tag
val mi : std_tag
val mmultiscripts : std_tag
val mn : std_tag
val mo : std_tag
val mover : std_tag
val mpadded : std_tag
val mphantom : std_tag
val mroot : std_tag
val mrow : std_tag
val ms : std_tag
val mspace : std_tag
val msqrt : std_tag
val mstyle : std_tag
val msub : std_tag
val msubsup : std_tag
val msup : std_tag
val mtable : std_tag
val mtd : std_tag
val mtext : std_tag
val mtr : std_tag
val munder : std_tag
val munderover : std_tag
val semantics : std_tag
Dream_html.MathML
val accent : bool to_attr
val accentunder : bool to_attr
val columnspan : int to_attr
val depth : _ string_attr
val dir : [ `ltr | `rtl ] to_attr
val display_block : attr
See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#display. display=inline
is the default, so there is no need to bind its value.
val displaystyle : bool to_attr
val fence : bool to_attr
val height : _ string_attr
val largeop : bool to_attr
val linethickness : _ string_attr
val lspace : _ string_attr
val mathvariant : _ string_attr
val maxsize : _ string_attr
val minsize : _ string_attr
val movablelimits : bool to_attr
val rowspan : int to_attr
val rspace : _ string_attr
val scriptlevel : _ string_attr
val separator : bool to_attr
val stretchy : bool to_attr
val symmetric : bool to_attr
val voffset : _ string_attr
val xmlns : attr
val annotation : std_tag
val annotation_xml : std_tag
val math : std_tag
val merror : std_tag
val mfrac : std_tag
val mi : std_tag
val mmultiscripts : std_tag
val mn : std_tag
val mo : std_tag
val mover : std_tag
val mpadded : std_tag
val mphantom : std_tag
val mroot : std_tag
val mrow : std_tag
val ms : std_tag
val mspace : std_tag
val msqrt : std_tag
val mstyle : std_tag
val msub : std_tag
val msubsup : std_tag
val msup : std_tag
val mtable : std_tag
val mtd : std_tag
val mtext : std_tag
val mtr : std_tag
val munder : std_tag
val munderover : std_tag
val semantics : std_tag
Dream_html.RSS
RSS support
val domain : _ string_attr
val version_2 : attr
val xmlns_atom : attr
val author : _ text_tag
val channel : std_tag
val category : _ text_tag
val comments : _ text_tag
val copyright : _ text_tag
val description : _ text_tag
val docs : _ text_tag
val generator : _ text_tag
val guid : _ text_tag
val item : std_tag
val language : _ text_tag
val last_build_date : _ text_tag
val link : _ text_tag
val managing_editor : _ text_tag
val pub_date : _ text_tag
val rss : std_tag
val title : _ text_tag
val ttl : _ text_tag
val web_master : _ text_tag
Dream_html.RSS
RSS support
val domain : _ string_attr
val length : int to_attr
val path : _ string_attr
val port : int to_attr
val protocol : _ string_attr
val register_procedure : _ string_attr
val type_ : _ string_attr
val url_ : _ string_attr
val version_2 : attr
val author : _ text_tag
val channel : std_tag
val category : _ text_tag
val cloud : void_tag
val comments : _ text_tag
val copyright : _ text_tag
val description : _ text_tag
val docs : _ text_tag
val enclosure : std_tag
val generator : _ text_tag
val guid : _ text_tag
val height : _ text_tag
val image : std_tag
val item : std_tag
val language : _ text_tag
val last_build_date : _ text_tag
val link : _ text_tag
val managing_editor : _ text_tag
val pub_date : _ text_tag
val rss : std_tag
val title : _ text_tag
val ttl : _ text_tag
val url : _ text_tag
val web_master : _ text_tag
val width : _ text_tag
Dream_html.SVG
val d : _ string_attr
val fill : _ string_attr
val stroke : _ string_attr
val stroke_linecap : [< `butt | `round | `square ] to_attr
val stroke_linejoin :
+SVG (dream-html.Dream_html.SVG) Module Dream_html.SVG
val d : _ string_attr
val fill : _ string_attr
val stroke : _ string_attr
val stroke_linecap : [< `butt | `round | `square ] to_attr
val stroke_linejoin :
[< `arcs | `bevel | `miter | `miter_clip | `round ] to_attr
val stroke_width : _ string_attr
val viewbox : min_x:int -> min_y:int -> width:int -> height:int -> attr
val xmlns : attr
val path : std_tag
val svg : std_tag
diff --git a/dream-html/Dream_html/index.html b/dream-html/Dream_html/index.html
index 5ddb33a..706ca02 100644
--- a/dream-html/Dream_html/index.html
+++ b/dream-html/Dream_html/index.html
@@ -1,5 +1,5 @@
-Dream_html (dream-html.Dream_html) Module Dream_html
Form handling
module Form : sig ... end
Typed, extensible HTML form decoder with error reporting for form field validation failures. Powerful chained decoding functionality–the validation of one field can depend on the values of other decoded fields.
val form :
+Dream_html (dream-html.Dream_html) Module Dream_html
Form handling
module Form : sig ... end
Typed, extensible HTML form decoder with error reporting for form field validation failures. Powerful chained decoding functionality–the validation of one field can depend on the values of other decoded fields.
val form :
'a Form.t ->
?csrf:bool ->
Dream.request ->
@@ -24,7 +24,7 @@
a [href "/foo?a=1&b=2 3&c=4<5&d=6>5"] [txt "Test"]
==>
-<a href="/foo?a=1&b=2%203&c=4%3C5&d=6%3E5">Test</a>
val bool_attr : string -> bool to_attr
val float_attr : string -> float to_attr
val int_attr : string -> int to_attr
val std_tag : string -> std_tag
val void_tag : string -> void_tag
val text_tag : string -> ?raw:bool -> _ text_tag
Build a tag which can contain only text.
val uri_tag : string -> _ text_tag
Build a tag which can contain only a URI. The URI is scaped with the same rules as a uri_attr
.
val txt : ?raw:bool -> ('a, unit, string, node) Stdlib.format4 -> 'a
A text node inside the DOM e.g. the 'hi' in <b>hi</b>
. Allows string interpolation using the same formatting features as Printf.sprintf
:
b [] [txt "Hello, %s!" name]
Or without interpolation:
b [] [txt "Bold of you."]
HTML-escapes the text value. You can use the ~raw
param to bypass escaping:
let user_input = "<script>alert('I like HTML injection')</script>" in
+<a href="/foo?a=1&b=2%203&c=4%3C5&d=6%3E5">Test</a>
val bool_attr : string -> bool to_attr
val float_attr : string -> float to_attr
val int_attr : string -> int to_attr
val std_tag : string -> std_tag
val void_tag : string -> void_tag
val text_tag : string -> ?raw:bool -> _ text_tag
Build a tag which can contain only text.
val uri_tag : string -> _ text_tag
Build a tag which can contain only a URI. The URI is escaped with the same rules as a uri_attr
.
val txt : ?raw:bool -> ('a, unit, string, node) Stdlib.format4 -> 'a
A text node inside the DOM e.g. the 'hi' in <b>hi</b>
. Allows string interpolation using the same formatting features as Printf.sprintf
:
b [] [txt "Hello, %s!" name]
Or without interpolation:
b [] [txt "Bold of you."]
HTML-escapes the text value. You can use the ~raw
param to bypass escaping:
let user_input = "<script>alert('I like HTML injection')</script>" in
txt ~raw:true "%s" user_input
val comment : string -> node
A comment that will be embedded in the rendered HTML, i.e. <!-- comment -->
. The text is HTML-escaped.
Accessors for tags
Add an attribute to a tag.
let toast msg = p [id "toast"] [txt "%s" msg]
let toast_oob = toast "ok." +@ Hx.swap_oob "true"
val (.@[]) : node -> string -> string
Get the value of an existing attribute.
let toast = p [id "toast"] [txt "OK."]
let toast_id = toast.@["id"]
val is_null : node -> bool
Get whether a node is null (empty) or not. Useful for conditional rendering of UIs when you are passed in a node and you don't know if it's empty or not.
val is_null_ : attr -> bool
Get whether an attribute is null (empty) or not.
HTML
module HTML : sig ... end
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
SVG
module SVG : sig ... end
MathML
module MathML : sig ... end
ARIA
module Aria : sig ... end
RSS and Atom
module Atom : sig ... end
htmx
val respond :
@@ -37,14 +37,12 @@
?end_of_message:[< Dream.end_of_message ] ->
Dream.websocket ->
node ->
- unit Dream.promise
Type-safe wrapper for Dream.send
.
val set_body : Dream.response -> node -> unit
Type-safe wrapper for Dream.set_body
. Sets the body to the given node
and sets the Content-Type
header to text/html
.
val write : Dream.stream -> node -> unit Dream.promise
Type-safe wrapper for Dream.write
.
val csrf_tag : Dream.request -> node
Convenience to add a CSRF token generated by Dream into your form. Type-safe equivalent of Dream.csrf_tag
.
form [action "/foo"] [
- csrf_tag req;
- input [name "bar"];
- input [type_ "submit"];
-]
Type-safe routing
Bidirectional paths with type-safe path segment parsing and printing using OCaml's built-in format strings, and fully plug-and-play compatible with Dream routes.
type ('r, 'p) route = ('r, 'p) path -> (Dream.request -> 'r) -> Dream.route
Wrapper for a Dream route that represents the ability to parse path parameters and pass them to the handler function with the correct types.
val set_body : Dream.response -> node -> unit
Type-safe wrapper for Dream.set_body
. Sets the body to the given node
and sets the Content-Type
header to text/html
.
val write : Dream.stream -> node -> unit Dream.promise
Type-safe wrapper for Dream.write
.
val csrf_tag : Dream.request -> node
Convenience to add a CSRF token generated by Dream into your form. Type-safe equivalent of Dream.csrf_tag
.
form
+ [action "/foo"]
+ [csrf_tag req; input [name "bar"]; input [type_ "submit"]]
Type-safe routing
Bidirectional paths with type-safe path segment parsing and printing using OCaml's built-in format strings, and fully plug-and-play compatible with Dream routes.
type ('r, 'p) route = ('r, 'p) path -> (Dream.request -> 'r) -> Dream.route
Wrapper for a Dream route that represents the ability to parse path parameters and pass them to the handler function with the correct types.
val path :
('r, unit, Dream.response Dream.promise) Stdlib.format ->
('p, unit, string, attr) Stdlib.format4 ->
- ('r, 'p) path
path request_fmt attr_fmt
is a router path. The dream-html.ppx
provides a more convenient way.
Without PPX: let order = path "/orders/%s" "/orders/%s"
With PPX: let%path order = "/orders/%s"
Refer to the PPX documentation for instructions on using it.
⚠️ Due to the way Dream's router works, all parameter captures happens between /
characters and the end of the path (or the ?
character, whichever comes first). Eg, /foo/%s/bar/%d
is valid, but /foo/%s.%s
(note the dot character) is not a valid capture.
⚠️ If a route is matched but the data type does not match, a 400 Bad Request
response will be returned. The following type conversion specs are supported:
%s
capture a string
and pass it to the handler
%*s
capture the rest of the path and pass the captured length and string to the handler
%c
capture a char
%d
or %i
capture an int
%x
capture a hexadecimal int
%X
capture an uppercase hexadecimal int
%o
capture an octal int
%ld
capture an int32
%Ld
capture an int64
%f
capture a float
%B
capture a bool
⚠️ We are actually using Dream's built-in router, not our own, and Dream's router doesn't distinguish between parameter types. So, to Dream both /%s
and /%d
are the same path. It will route the request to whichever happens to be first in the route list, and that one will succeed or fail depending on its type and the request target.
val path_attr : 'p string_attr -> (_, 'p) path -> 'p
path_attr attr path
is an HTML attribute with the path parameters filled in from the given values. Eg,
let%path order = "/orders/%s"
+ ('r, 'p) path
path request_fmt attr_fmt
is a router path. The dream-html.ppx
provides a more convenient way.
Without PPX: let order = path "/orders/%s" "/orders/%s"
With PPX: let%path order = "/orders/%s"
Refer to the PPX documentation for instructions on using it.
⚠️ Due to the way Dream's router works, all parameter captures happen between /
characters and the end of the path (or the ?
character, whichever comes first). Eg, /foo/%s/bar/%d
is valid, but /foo/%s.%s
(note the dot character) is not a valid capture.
⚠️ If a route is matched but the data type does not match, a 400 Bad Request
response will be returned. The following type conversion specs are supported:
%s
capture a string
and pass it to the handler
%*s
capture the rest of the path and pass the captured length and string to the handler
%c
capture a char
%d
or %i
capture an int
%x
capture a hexadecimal int
%X
capture an uppercase hexadecimal int
%o
capture an octal int
%ld
capture an int32
%Ld
capture an int64
%f
capture a float
%B
capture a bool
⚠️ We are actually using Dream's built-in router, not our own, and Dream's router doesn't distinguish between parameter types. So, to Dream both /%s
and /%d
are the same path. It will route the request to whichever happens to be first in the route list, and that one will succeed or fail depending on its type and the request target.
val path_attr : 'p string_attr -> (_, 'p) path -> 'p
path_attr attr path
is an HTML attribute with the path parameters filled in from the given values. Eg,
let%path order = "/orders/%s"
open Dream_html
open HTML
@@ -55,13 +53,7 @@
...
a [path_attr href order order_id] [txt "Your order"]
...
-)
val post : (_, _) route
val put : (_, _) route
val delete : (_, _) route
val head : (_, _) route
val connect : (_, _) route
val options : (_, _) route
val trace : (_, _) route
val patch : (_, _) route
val any : (_, _) route
use middlewares routes
is a route that is composed of all the given routes
with the middlewares
attached to them.
val static_asset : (Dream.response Dream.promise, _) path -> Dream.route
static_asset path
is a route that handles serving the static file at the path
. Importantly, it sets an immutable cache header which remains valid for a year.
⚠️ Be sure that the resource has a unique identifier because it will be cached immutably. The dreamwork
CLI tool automates this for you. See Dreamwork.
Dreamwork
TL;DR:
- Run
dreamwork setup
- Populate the
static/assets/
subdirectory with files - Run
dune build
- Add
Static.routes
to the app's main Dream router - Use eg
img [path_attr src Static.Assets.icon_png]
which will render with a revision hash based on the file contents, calculated at build time
dreamwork
is a CLI tool that helps set up and manage static file paths and routes with proper content-based version hashes. The static files will live inside a dune component called static
and in the static/assets
subdirectory. Suppose you have the following directory tree:
static/
- dune
- assets/
- css/
- app.css
- js/
- app.js
The dune
file defines a library
component that will make the following module available:
module Static : sig
+)
val post : (_, _) route
val put : (_, _) route
val delete : (_, _) route
val head : (_, _) route
val connect : (_, _) route
val options : (_, _) route
val trace : (_, _) route
val patch : (_, _) route
val any : (_, _) route
use middlewares routes
is a route that is composed of all the given routes
with the middlewares
attached to them.
val static_asset : (Dream.response Dream.promise, _) path -> Dream.route
static_asset path
is a route that handles serving the static file at the path
. Importantly, it sets an immutable cache header which remains valid for a year.
⚠️ Be sure that the resource has a unique identifier because it will be cached immutably. The dreamwork
CLI tool automates this for you. See Dreamwork.
Dreamwork
TL;DR:
- Run
dreamwork setup
- Populate the
static/assets/
subdirectory with files - Run
dune build
- Add
Static.routes
to the app's main Dream router - Use eg
img [path_attr src Static.Assets.icon_png]
which will render with a revision hash based on the file contents, calculated at build time
dreamwork
is a CLI tool that helps set up and manage static file paths and routes with proper content-based version hashes. The static files will live inside a dune component called static
and in the static/assets
subdirectory. Suppose you have the following directory tree:
static / dune assets / css / app.css js / app.js
The dune
file defines a library
component that will make the following module available:
module Static : sig
val routes : Dream.route
(** This route will serve all of the following paths. *)
diff --git a/dream-html/Ppx/index.html b/dream-html/Ppx/index.html
index c8e3760..b4ac800 100644
--- a/dream-html/Ppx/index.html
+++ b/dream-html/Ppx/index.html
@@ -1,5 +1,5 @@
-Ppx (dream-html.Ppx) Module Ppx
This PPX provides an extension point to create route paths.
You can add it to your dune
file in the usual way: (preprocess (pps dream-html.ppx))
.
Then create a path: let%path orders = "/orders"
.
And use it in a route: Dream_html.get orders (fun req -> ...)
.
The PPX expands the above path to:
let orders = Dream_html.path "/orders" "/orders"
Ie, it just duplicates the path string to use as two separate format strings with different types for parsing and printing. If you need to actually have a different format string for printing (eg if you need to print the path with query parameters), you can use the underlying Dream_html.path
function directly: path "/orders/%s" "/orders/%s?utm_src=%s&utm_campaign=%s"
.
The PPX also has the benefit that it checks that the path is well-formed at compile time. If you pass in an invalid path you get a compile error:
File "test/route_test.ml", line 1, characters 0-20:
+Ppx (dream-html.Ppx) Module Ppx
This PPX provides an extension point to create route paths.
You can add it to your dune
file in the usual way: (preprocess (pps dream-html.ppx))
.
Then create a path: let%path orders = "/orders"
.
And use it in a route: Dream_html.get orders (fun req -> ...)
.
The PPX expands the above path to:
let orders = Dream_html.path "/orders" "/orders"
Ie, it just duplicates the path string to use as two separate format strings with different types for parsing and printing. If you need to actually have a different format string for printing (eg if you need to print the path with query parameters), you can use the underlying Dream_html.path
function directly: path "/orders/%s" "/orders/%s?utm_src=%s&utm_campaign=%s"
.
The PPX also has the benefit that it checks that the path is well-formed at compile time. If you pass in an invalid path you get a compile error:
File "test/route_test.ml", line 1, characters 0-20:
1 | let%path bad = "foo"
^^^^^^^^^^^^^^^^^^^^
Error: Invalid path: 'foo'. Paths must start with a '/' character
diff --git a/dream-html/index.html b/dream-html/index.html
index 78a45d8..5b03d5d 100644
--- a/dream-html/index.html
+++ b/dream-html/index.html
@@ -1,2 +1,2 @@
-index (dream-html.index) dream-html index
Library dream-html
The entry point of this library is the module: Dream_html
.
Library dream-html.ppx
The entry point of this library is the module: Ppx
.
+index (dream-html.index) dream-html index
Library dream-html
The entry point of this library is the module: Dream_html
.
Library dream-html.ppx
The entry point of this library is the module: Ppx
.
diff --git a/odoc.support/odoc.css b/odoc.support/odoc.css
index 15240b5..f0f22a1 100644
--- a/odoc.support/odoc.css
+++ b/odoc.support/odoc.css
@@ -1,7 +1,7 @@
@charset "UTF-8";
/* Copyright (c) 2016 The odoc contributors. All rights reserved.
Distributed under the ISC license, see terms at the end of the file.
- odoc 2.4.3 */
+ odoc 2.4.4 */
/* Fonts */
/* noticia-text-regular - latin */
diff --git a/pure-html/Pure_html/Aria/index.html b/pure-html/Pure_html/Aria/index.html
index 0347fd1..bb4017d 100644
--- a/pure-html/Pure_html/Aria/index.html
+++ b/pure-html/Pure_html/Aria/index.html
@@ -1,2 +1,2 @@
-Aria (pure-html.Pure_html.Aria) Module Pure_html.Aria
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/
val activedescendant : _ string_attr
val atomic : attr
val autocomplete : [ `inline | `list | `both ] to_attr
val braillelabel : _ string_attr
val brailleroledescription : _ string_attr
val busy : attr
val checked : [ `false_ | `true_ | `mixed ] to_attr
val colcount : int to_attr
val colindextext : _ string_attr
val colspan : int to_attr
val controls : _ string_attr
val current : [ `page | `step | `location | `date | `time | `true_ ] to_attr
val describedby : _ string_attr
val description : _ string_attr
val details : _ string_attr
val disabled : attr
val errormessage : _ string_attr
val expanded : bool to_attr
val flowto : _ string_attr
val haspopup : [ `true_ | `menu | `listbox | `tree | `grid | `dialog ] to_attr
val invalid : [ `grammar | `spelling | `true_ ] to_attr
val keyshortcuts : _ string_attr
val label : _ string_attr
val labelledby : _ string_attr
val level : int to_attr
val live : [ `assertive | `off | `polite ] to_attr
⚠️ Screen readers want a live region to be defined statically from page load on a visible element, eg p [id "toast"; Aria.live `polite] []
. The element must not be hidden initially, otherwise the screen reader will continue to ignore it even when its content is changed.
val modal : attr
val multiline : attr
val multiselectable : attr
val orientation : [ `horizontal | `vertical ] to_attr
val owns : _ string_attr
val placeholder : _ string_attr
val posinset : int to_attr
val pressed : [ `false_ | `mixed | `true_ ] to_attr
val readonly : attr
val relevant : [ `additions | `all | `removals | `text ] to_attr
val required : attr
val roledescription : _ string_attr
val rowcount : int to_attr
val rowindex : int to_attr
val rowindextext : _ string_attr
val rowspan : int to_attr
val selected : bool to_attr
val setsize : int to_attr
val sort : [ `ascending | `descending | `other ] to_attr
val valuemax : float to_attr
val valuemin : float to_attr
val valuenow : float to_attr
val valuetext : _ string_attr
+Aria (pure-html.Pure_html.Aria) Module Pure_html.Aria
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/
val activedescendant : _ string_attr
val atomic : attr
val autocomplete : [ `inline | `list | `both ] to_attr
val braillelabel : _ string_attr
val brailleroledescription : _ string_attr
val busy : attr
val checked : [ `false_ | `true_ | `mixed ] to_attr
val colcount : int to_attr
val colindextext : _ string_attr
val colspan : int to_attr
val controls : _ string_attr
val current : [ `page | `step | `location | `date | `time | `true_ ] to_attr
val describedby : _ string_attr
val description : _ string_attr
val details : _ string_attr
val disabled : attr
val errormessage : _ string_attr
val expanded : bool to_attr
val flowto : _ string_attr
val haspopup : [ `true_ | `menu | `listbox | `tree | `grid | `dialog ] to_attr
val invalid : [ `grammar | `spelling | `true_ ] to_attr
val keyshortcuts : _ string_attr
val label : _ string_attr
val labelledby : _ string_attr
val level : int to_attr
val live : [ `assertive | `off | `polite ] to_attr
⚠️ Screen readers want a live region to be defined statically from page load on a visible element, eg p [id "toast"; Aria.live `polite] []
. The element must not be hidden initially, otherwise the screen reader will continue to ignore it even when its content is changed.
`off
since 3.10.0
val modal : attr
val multiline : attr
val multiselectable : attr
val orientation : [ `horizontal | `vertical ] to_attr
val owns : _ string_attr
val placeholder : _ string_attr
val posinset : int to_attr
val pressed : [ `false_ | `mixed | `true_ ] to_attr
val readonly : attr
val relevant : [ `additions | `all | `removals | `text ] to_attr
val required : attr
val roledescription : _ string_attr
val rowcount : int to_attr
val rowindex : int to_attr
val rowindextext : _ string_attr
val rowspan : int to_attr
val selected : bool to_attr
val setsize : int to_attr
val sort : [ `ascending | `descending | `other ] to_attr
val valuemax : float to_attr
val valuemin : float to_attr
val valuenow : float to_attr
val valuetext : _ string_attr
diff --git a/pure-html/Pure_html/Atom/index.html b/pure-html/Pure_html/Atom/index.html
index 41a7c15..097f710 100644
--- a/pure-html/Pure_html/Atom/index.html
+++ b/pure-html/Pure_html/Atom/index.html
@@ -1,2 +1,2 @@
-Atom (pure-html.Pure_html.Atom) Module Pure_html.Atom
val link : std_tag
+Atom (pure-html.Pure_html.Atom) Module Pure_html.Atom
diff --git a/pure-html/Pure_html/HTML/index.html b/pure-html/Pure_html/HTML/index.html
index ff7d3d4..b217217 100644
--- a/pure-html/Pure_html/HTML/index.html
+++ b/pure-html/Pure_html/HTML/index.html
@@ -1,8 +1,10 @@
-HTML (pure-html.Pure_html.HTML) Module Pure_html.HTML
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
Attributes
Standard, most non-deprecated attributes from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. Where an attribute name conflicts with an OCaml keyword, the name is suffixed with _
. Most attributes are constructed by passing in a value of some type.
All string-valued attributes allow formatting (interpolation):
div [id "section-%d" section_id] []
Or plain strings:
p [id "toast"] []
Most boolean attributes are plain values and don't need to be constructed with function calls:
input [required]
However, boolean attributes which may be inherited and toggled on/off in children, are constructed by passing in a value:
div [contenteditable true] [
- p [] [txt "Edit me!"];
- p [contenteditable false] [txt "Can't edit me!"];
-]
Enumerated attributes accept specific values:
input [inputmode `tel]
val null_ : attr
An attribute that will not be rendered in the markup. Useful for conditional logic where you sometimes want to render an attribute and sometimes not.
p [if should_show then null_ else style_ "display:none"] [txt "Show and tell"]
val accept : _ string_attr
val accept_charset : _ string_attr
val accesskey : _ string_attr
val action : _ string_attr
val align : _ string_attr
val allow : _ string_attr
val alt : _ string_attr
val as_ : _ string_attr
val async : attr
val autocapitalize :
+HTML (pure-html.Pure_html.HTML) Module Pure_html.HTML
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
Attributes
Standard, most non-deprecated attributes from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. Where an attribute name conflicts with an OCaml keyword, the name is suffixed with _
. Most attributes are constructed by passing in a value of some type.
All string-valued attributes allow formatting (interpolation):
div [id "section-%d" section_id] []
Or plain strings:
p [id "toast"] []
Most boolean attributes are plain values and don't need to be constructed with function calls:
input [required]
However, boolean attributes which may be inherited and toggled on/off in children, are constructed by passing in a value:
div
+ [contenteditable true]
+ [ p [] [txt "Edit me!"];
+ p [contenteditable false] [txt "Can't edit me!"] ]
Enumerated attributes accept specific values:
input [inputmode `tel]
val null_ : attr
An attribute that will not be rendered in the markup. Useful for conditional logic where you sometimes want to render an attribute and sometimes not.
p
+ [(if should_show then null_ else style_ "display:none")]
+ [txt "Show and tell"]
val accept : _ string_attr
val accept_charset : _ string_attr
val accesskey : _ string_attr
val action : _ string_attr
val align : _ string_attr
val allow : _ string_attr
val alt : _ string_attr
val as_ : _ string_attr
val async : attr
val autocapitalize :
[< `off | `none | `on | `sentences | `words | `characters ] to_attr
val autocomplete :
[< `off
| `on
@@ -64,10 +66,10 @@
| `default_style
| `x_ua_compatible
| `refresh ]
- to_attr
val id : _ string_attr
val integrity : _ string_attr
val inputmode :
+ to_attr
val id : _ string_attr
val inert : attr
val integrity : _ string_attr
val inputmode :
[< `none | `text | `decimal | `numeric | `tel | `search | `email | `url ]
to_attr
val ismap : attr
val itemprop : _ string_attr
val kind :
- [< `subtitles | `captions | `descriptions | `chapters | `metadata ] to_attr
val label_ : _ string_attr
val lang : _ string_attr
val list : _ string_attr
val loading_lazy : attr
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#loading. loading=eager
is the default so no need for specifically that value.
val loop : attr
val low : float to_attr
val max : _ string_attr
val maxlength : int to_attr
val media : _ string_attr
val min : _ string_attr
val minlength : int to_attr
val multiple : attr
val muted : attr
val name : _ string_attr
val novalidate : attr
val onblur : _ string_attr
Note that the value of this attribute is not escaped.
val onclick : _ string_attr
Note that the value of this attribute is not escaped.
val open_ : attr
val optimum : float to_attr
val pattern : _ string_attr
val ping : _ string_attr
val placeholder : _ string_attr
val playsinline : attr
val poster : _ string_attr
val preload : [< `none | `metadata | `auto ] to_attr
val readonly : attr
val referrerpolicy :
+ [< `subtitles | `captions | `descriptions | `chapters | `metadata ] to_attr
val label_ : _ string_attr
val lang : _ string_attr
val list : _ string_attr
val loading_lazy : attr
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#loading. loading=eager
is the default so no need for specifically that value.
val loop : attr
val low : float to_attr
val max : _ string_attr
val maxlength : int to_attr
val media : _ string_attr
val min : _ string_attr
val minlength : int to_attr
val multiple : attr
val muted : attr
val name : _ string_attr
val novalidate : attr
val onblur : _ string_attr
Note that the value of this attribute is not escaped.
val onclick : _ string_attr
Note that the value of this attribute is not escaped.
val open_ : attr
val optimum : float to_attr
val pattern : _ string_attr
val ping : _ string_attr
val placeholder : _ string_attr
val playsinline : attr
val popover : [< `auto | `manual ] to_attr
val popovertarget : _ string_attr
val popovertargetaction : [< `hide | `show ] to_attr
toggle
is the default.
val poster : _ string_attr
val preload : [< `none | `metadata | `auto ] to_attr
val readonly : attr
val referrerpolicy :
[< `no_referrer
| `no_referrer_when_downgrade
| `origin
@@ -150,12 +152,11 @@
| `tree
| `treegrid
| `treeitem ]
- to_attr
val rows : int to_attr
val rowspan : int to_attr
val sandbox : _ string_attr
val scope : _ string_attr
val selected : attr
val shape : _ string_attr
val size : _ string_attr
val sizes : _ string_attr
val slot_ : _ string_attr
val span_ : int to_attr
val spellcheck : bool to_attr
val src : _ string_attr
val srcdoc : _ string_attr
val srclang : _ string_attr
val srcset : _ string_attr
val start : int to_attr
val step : _ string_attr
val style_ : _ string_attr
Note that the value of this attribute is not escaped.
val tabindex : int to_attr
val target : _ string_attr
val title_ : _ string_attr
val translate : [< `yes | `no ] to_attr
val type_ : _ string_attr
Note: this can't be restricted to just the allowed values for <input type>
, because it's used in other elements e.g. <link type>
.
val usemap : _ string_attr
val value : _ string_attr
val width : _ string_attr
val wrap : [< `hard | `soft ] to_attr
Tags
HTML tags. Most (standard tags) are constructed by passing a list of attributes and a list of children:
div [id "my-div"] [p [] [txt "Hello"]]
Some (void elements) are constructed only with a list of attributes:
input [required; type_ "email"; name "email-addr"]
Finally, a few (text elements) are constructed with a list of attributes and a single format string child:
title [] "Document title"
-
-title [] "My App ・ %s" page_name
-
-script [] {|alert('Careful, this is not escaped :-)');|}
A tag that will not be rendered in the markup. Useful for containing a bunch of child nodes inside a single node without having to litter the DOM with an actual node. Also may be called 'splicing'.
null [
- p [] [txt "This paragraph."];
- p [] [txt "And this paragraph."];
- p [] [txt "Are spliced directly into the document without a containing node."];
-]
Also useful for constructing a completely empty node that is erased when printing:
null []
val a : std_tag
val address : std_tag
val area : void_tag
val abbr : std_tag
val article : std_tag
val aside : std_tag
val audio : std_tag
val b : std_tag
val base : void_tag
val bdi : std_tag
val bdo : std_tag
val blockquote : std_tag
val body : std_tag
val br : void_tag
val button : std_tag
val canvas : std_tag
val cite : std_tag
val code : std_tag
val col : void_tag
val colgroup : std_tag
val data : std_tag
val datalist : std_tag
val dd : std_tag
val del : std_tag
val details : std_tag
val dfn : std_tag
val dialog : std_tag
val div : std_tag
val dl : std_tag
val dt : std_tag
val em : std_tag
val embed : void_tag
val fieldset : std_tag
val figure : std_tag
val form : std_tag
val h1 : std_tag
val h2 : std_tag
val h3 : std_tag
val h4 : std_tag
val h5 : std_tag
val h6 : std_tag
val head : std_tag
val header : std_tag
val hgroup : std_tag
val hr : void_tag
val html : std_tag
A <!DOCTYPE html>
declaration is automatically prefixed when this tag is printed.
val i : std_tag
val iframe : std_tag
val img : void_tag
val input : void_tag
val ins : std_tag
val kbd : std_tag
val label : std_tag
val legend : std_tag
val li : std_tag
val link : void_tag
val main : std_tag
val map : std_tag
val mark : std_tag
val meta : void_tag
val meter : std_tag
val noscript : std_tag
val object_ : std_tag
val ol : std_tag
val optgroup : std_tag
val option : _ text_tag
val output : std_tag
val p : std_tag
val picture : std_tag
val pre : std_tag
val progress : std_tag
val q : std_tag
val rp : std_tag
val rt : std_tag
val ruby : std_tag
val s : std_tag
val samp : std_tag
val script : _ text_tag
Note that the content of this tag is not escaped.
val section : std_tag
val select : std_tag
val slot : std_tag
val small : std_tag
val source : void_tag
val span : std_tag
val strong : std_tag
val style : _ text_tag
Note that the content of this tag is not escaped.
val sub : std_tag
val summary : std_tag
val sup : std_tag
val table : std_tag
val tbody : std_tag
val td : std_tag
val template : std_tag
val textarea : _ text_tag
val tfoot : std_tag
val th : std_tag
val thead : std_tag
val time : std_tag
val title : _ text_tag
val tr : std_tag
val track : void_tag
val u : std_tag
val ul : std_tag
val var : std_tag
val video : std_tag
val wbr : void_tag
+ to_attr
val rows : int to_attr
val rowspan : int to_attr
val sandbox : _ string_attr
val scope : _ string_attr
val selected : attr
val shadowrootclonable : attr
val shadowrootdelegatesfocus : attr
val shadowrootmode : [ `open_ | `closed ] to_attr
val shape : _ string_attr
val size : _ string_attr
val sizes : _ string_attr
val slot_ : _ string_attr
val span_ : int to_attr
val spellcheck : bool to_attr
val src : _ string_attr
val srcdoc : _ string_attr
val srclang : _ string_attr
val srcset : _ string_attr
val start : int to_attr
val step : _ string_attr
val style_ : _ string_attr
Note that the value of this attribute is not escaped.
val tabindex : int to_attr
val target : _ string_attr
val title_ : _ string_attr
val translate : [< `yes | `no ] to_attr
val type_ : _ string_attr
Note: this can't be restricted to just the allowed values for <input type>
, because it's used in other elements e.g. <link type>
.
val usemap : _ string_attr
val value : _ string_attr
val width : _ string_attr
val wrap : [< `hard | `soft ] to_attr
Tags
HTML tags. Most (standard tags) are constructed by passing a list of attributes and a list of children:
div [id "my-div"] [p [] [txt "Hello"]]
Some (void elements) are constructed only with a list of attributes:
input [required; type_ "email"; name "email-addr"]
Finally, a few (text elements) are constructed with a list of attributes and a single format string child:
title [] "Document title" title [] "My App ・ %s" page_name script []
+ {|alert('Careful, this is not escaped :-)');|}
A tag that will not be rendered in the markup. Useful for containing a bunch of child nodes inside a single node without having to litter the DOM with an actual node. Also may be called 'splicing'.
null
+ [ p [] [txt "This paragraph."];
+ p [] [txt "And this paragraph."];
+ p []
+ [ txt
+ "Are spliced directly into the document without a containing node."
+ ] ]
Also useful for constructing a completely empty node that is erased when printing: null []
.
val a : std_tag
val address : std_tag
val area : void_tag
val abbr : std_tag
val article : std_tag
val aside : std_tag
val audio : std_tag
val b : std_tag
val base : void_tag
val bdi : std_tag
val bdo : std_tag
val blockquote : std_tag
val body : std_tag
val br : void_tag
val button : std_tag
val canvas : std_tag
val cite : std_tag
val code : std_tag
val col : void_tag
val colgroup : std_tag
val data : std_tag
val datalist : std_tag
val dd : std_tag
val del : std_tag
val details : std_tag
val dfn : std_tag
val dialog : std_tag
val div : std_tag
val dl : std_tag
val dt : std_tag
val em : std_tag
val embed : void_tag
val fieldset : std_tag
val figure : std_tag
val form : std_tag
val h1 : std_tag
val h2 : std_tag
val h3 : std_tag
val h4 : std_tag
val h5 : std_tag
val h6 : std_tag
val head : std_tag
val header : std_tag
val hgroup : std_tag
val hr : void_tag
val html : std_tag
A <!DOCTYPE html>
declaration is automatically prefixed when this tag is printed.
val i : std_tag
val iframe : std_tag
val img : void_tag
val input : void_tag
val ins : std_tag
val kbd : std_tag
val label : std_tag
val legend : std_tag
val li : std_tag
val link : void_tag
val main : std_tag
val map : std_tag
val mark : std_tag
val meta : void_tag
val meter : std_tag
val noscript : std_tag
val object_ : std_tag
val ol : std_tag
val optgroup : std_tag
val option : _ text_tag
val output : std_tag
val p : std_tag
val picture : std_tag
val pre : std_tag
val progress : std_tag
val q : std_tag
val rp : std_tag
val rt : std_tag
val ruby : std_tag
val s : std_tag
val samp : std_tag
val script : _ text_tag
Note that the content of this tag is not escaped.
val search : std_tag
val section : std_tag
val select : std_tag
val selectedoption : std_tag
val slot : std_tag
val small : std_tag
val source : void_tag
val span : std_tag
val strong : std_tag
val style : _ text_tag
Note that the content of this tag is not escaped.
val sub : std_tag
val summary : std_tag
val sup : std_tag
val table : std_tag
val tbody : std_tag
val td : std_tag
val template : std_tag
val textarea : _ text_tag
val tfoot : std_tag
val th : std_tag
val thead : std_tag
val time : std_tag
val title : _ text_tag
val tr : std_tag
val track : void_tag
val u : std_tag
val ul : std_tag
val var : std_tag
val video : std_tag
val wbr : void_tag
diff --git a/pure-html/Pure_html/Hx/index.html b/pure-html/Pure_html/Hx/index.html
index 04c81c6..2ece9c5 100644
--- a/pure-html/Pure_html/Hx/index.html
+++ b/pure-html/Pure_html/Hx/index.html
@@ -1,2 +1,2 @@
-Hx (pure-html.Pure_html.Hx) Module Pure_html.Hx
htmx support
The attributes in this module are arranged in the same order as on the reference page linked above.
Remember that you will also need the htmx script itself. The recommended way to get it is to download a copy and place it in your static assets directory, managed by dreamwork so that it is properly cached and version-hashed by its contents.
Core attributes
val get : _ string_attr
val post : _ string_attr
val on_ : event:string -> _ string_attr
The hx-on:*
set of attributes, where *
represents DOM events: https://htmx.org/attributes/hx-on/.
Note that the value of this attribute is not escaped.
val push_url : _ string_attr
val select : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val select_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val target : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val trigger : _ string_attr
Note that the value of this attribute is not escaped.
val vals : _ string_attr
Additional attributes
val boost : bool to_attr
val confirm : _ string_attr
val delete : _ string_attr
val disable : attr
val disabled_elt : _ string_attr
val disinherit : _ string_attr
val encoding_formdata : attr
Hardcoding of the hx-encoding
attribute to multipart/form-data
.
val ext : _ string_attr
val headers : _ string_attr
val history_false : attr
Hardcoding of the hx-history
attribute to false
.
val history_elt : attr
val include_ : _ string_attr
val indicator : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val inherit_ : _ string_attr
val params : _ string_attr
val patch : _ string_attr
val preserve : attr
val prompt : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ string_attr
val sync : _ string_attr
val validate : attr
Extensions
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val sse_close : _ string_attr
val sse_connect : _ string_attr
val sse_swap : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
Other
val __ : _ string_attr
This attribute serves as the _ attribute, which is used by Hyperscript. Note that the value of this attribute is not escaped.
val on : _ string_attr
Note that the value of this attribute is not escaped.
+Hx (pure-html.Pure_html.Hx) Module Pure_html.Hx
htmx support
The attributes in this module are arranged in the same order as on the reference page linked above.
Remember that you will also need the htmx script itself. The recommended way to get it is to download a copy and place it in your static assets directory, managed by dreamwork so that it is properly cached and version-hashed by its contents.
Core attributes
val get : _ string_attr
val post : _ string_attr
val on_ : event:string -> _ string_attr
The hx-on:*
set of attributes, where *
represents DOM events: https://htmx.org/attributes/hx-on/.
Note that the value of this attribute is not escaped.
val push_url : _ string_attr
val select : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val select_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val target : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val trigger : _ string_attr
Note that the value of this attribute is not escaped.
val vals : _ string_attr
Additional attributes
val boost : bool to_attr
val confirm : _ string_attr
val delete : _ string_attr
val disable : attr
val disabled_elt : _ string_attr
val disinherit : _ string_attr
val encoding_formdata : attr
Hardcoding of the hx-encoding
attribute to multipart/form-data
.
val ext : _ string_attr
val headers : _ string_attr
val history_false : attr
Hardcoding of the hx-history
attribute to false
.
val history_elt : attr
val include_ : _ string_attr
val indicator : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val inherit_ : _ string_attr
val params : _ string_attr
val patch : _ string_attr
val preserve : attr
val prompt : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ string_attr
val sync : _ string_attr
val validate : attr
Extensions
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val sse_close : _ string_attr
val sse_connect : _ string_attr
val sse_swap : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
Other
val __ : _ string_attr
This attribute serves as the _ attribute, which is used by Hyperscript. Note that the value of this attribute is not escaped.
val on : _ string_attr
Note that the value of this attribute is not escaped.
diff --git a/pure-html/Pure_html/MathML/index.html b/pure-html/Pure_html/MathML/index.html
index 53664e0..3790e34 100644
--- a/pure-html/Pure_html/MathML/index.html
+++ b/pure-html/Pure_html/MathML/index.html
@@ -1,2 +1,2 @@
-MathML (pure-html.Pure_html.MathML) Module Pure_html.MathML
val accent : bool to_attr
val accentunder : bool to_attr
val columnspan : int to_attr
val depth : _ string_attr
val dir : [ `ltr | `rtl ] to_attr
val display_block : attr
See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#display. display=inline
is the default, so there is no need to bind its value.
val displaystyle : bool to_attr
val fence : bool to_attr
val height : _ string_attr
val largeop : bool to_attr
val linethickness : _ string_attr
val lspace : _ string_attr
val mathvariant : _ string_attr
val maxsize : _ string_attr
val minsize : _ string_attr
val movablelimits : bool to_attr
val rowspan : int to_attr
val rspace : _ string_attr
val scriptlevel : _ string_attr
val separator : bool to_attr
val stretchy : bool to_attr
val symmetric : bool to_attr
val voffset : _ string_attr
val xmlns : attr
val annotation : std_tag
val annotation_xml : std_tag
val math : std_tag
val merror : std_tag
val mfrac : std_tag
val mi : std_tag
val mmultiscripts : std_tag
val mn : std_tag
val mo : std_tag
val mover : std_tag
val mpadded : std_tag
val mphantom : std_tag
val mroot : std_tag
val mrow : std_tag
val ms : std_tag
val mspace : std_tag
val msqrt : std_tag
val mstyle : std_tag
val msub : std_tag
val msubsup : std_tag
val msup : std_tag
val mtable : std_tag
val mtd : std_tag
val mtext : std_tag
val mtr : std_tag
val munder : std_tag
val munderover : std_tag
val semantics : std_tag
+MathML (pure-html.Pure_html.MathML) Module Pure_html.MathML
val accent : bool to_attr
val accentunder : bool to_attr
val columnspan : int to_attr
val depth : _ string_attr
val dir : [ `ltr | `rtl ] to_attr
val display_block : attr
See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#display. display=inline
is the default, so there is no need to bind its value.
val displaystyle : bool to_attr
val fence : bool to_attr
val height : _ string_attr
val largeop : bool to_attr
val linethickness : _ string_attr
val lspace : _ string_attr
val mathvariant : _ string_attr
val maxsize : _ string_attr
val minsize : _ string_attr
val movablelimits : bool to_attr
val rowspan : int to_attr
val rspace : _ string_attr
val scriptlevel : _ string_attr
val separator : bool to_attr
val stretchy : bool to_attr
val symmetric : bool to_attr
val voffset : _ string_attr
val xmlns : attr
val annotation : std_tag
val annotation_xml : std_tag
val math : std_tag
val merror : std_tag
val mfrac : std_tag
val mi : std_tag
val mmultiscripts : std_tag
val mn : std_tag
val mo : std_tag
val mover : std_tag
val mpadded : std_tag
val mphantom : std_tag
val mroot : std_tag
val mrow : std_tag
val ms : std_tag
val mspace : std_tag
val msqrt : std_tag
val mstyle : std_tag
val msub : std_tag
val msubsup : std_tag
val msup : std_tag
val mtable : std_tag
val mtd : std_tag
val mtext : std_tag
val mtr : std_tag
val munder : std_tag
val munderover : std_tag
val semantics : std_tag
diff --git a/pure-html/Pure_html/RSS/index.html b/pure-html/Pure_html/RSS/index.html
index af41ddc..dde8eb6 100644
--- a/pure-html/Pure_html/RSS/index.html
+++ b/pure-html/Pure_html/RSS/index.html
@@ -1,2 +1,2 @@
-RSS (pure-html.Pure_html.RSS) Module Pure_html.RSS
RSS support
Attributes
val domain : _ string_attr
val version_2 : attr
val xmlns_atom : attr
Tags
val author : _ text_tag
val channel : std_tag
val category : _ text_tag
val comments : _ text_tag
val copyright : _ text_tag
val description : _ text_tag
val docs : _ text_tag
val generator : _ text_tag
val guid : _ text_tag
val item : std_tag
val language : _ text_tag
val last_build_date : _ text_tag
val link : _ text_tag
val managing_editor : _ text_tag
val pub_date : _ text_tag
val rss : std_tag
val title : _ text_tag
val ttl : _ text_tag
val web_master : _ text_tag
+RSS (pure-html.Pure_html.RSS) Module Pure_html.RSS
RSS support
Attributes
val domain : _ string_attr
val length : int to_attr
val path : _ string_attr
val port : int to_attr
val protocol : _ string_attr
val register_procedure : _ string_attr
val type_ : _ string_attr
val url_ : _ string_attr
val version_2 : attr
Tags
val author : _ text_tag
val channel : std_tag
val category : _ text_tag
val cloud : void_tag
val comments : _ text_tag
val copyright : _ text_tag
val description : _ text_tag
val docs : _ text_tag
val enclosure : std_tag
val generator : _ text_tag
val guid : _ text_tag
val height : _ text_tag
val image : std_tag
val item : std_tag
val language : _ text_tag
val last_build_date : _ text_tag
val link : _ text_tag
val managing_editor : _ text_tag
val pub_date : _ text_tag
val rss : std_tag
val title : _ text_tag
val ttl : _ text_tag
val url : _ text_tag
val web_master : _ text_tag
val width : _ text_tag
diff --git a/pure-html/Pure_html/SVG/index.html b/pure-html/Pure_html/SVG/index.html
index ecc69b2..370df0e 100644
--- a/pure-html/Pure_html/SVG/index.html
+++ b/pure-html/Pure_html/SVG/index.html
@@ -1,3 +1,3 @@
-SVG (pure-html.Pure_html.SVG) Module Pure_html.SVG
val d : _ string_attr
val fill : _ string_attr
val stroke : _ string_attr
val stroke_linecap : [< `butt | `round | `square ] to_attr
val stroke_linejoin :
+SVG (pure-html.Pure_html.SVG) Module Pure_html.SVG
val d : _ string_attr
val fill : _ string_attr
val stroke : _ string_attr
val stroke_linecap : [< `butt | `round | `square ] to_attr
val stroke_linejoin :
[< `arcs | `bevel | `miter | `miter_clip | `round ] to_attr
val stroke_width : _ string_attr
val viewbox : min_x:int -> min_y:int -> width:int -> height:int -> attr
val xmlns : attr
val path : std_tag
val svg : std_tag
diff --git a/pure-html/Pure_html/index.html b/pure-html/Pure_html/index.html
index 1abe8fd..37ed21b 100644
--- a/pure-html/Pure_html/index.html
+++ b/pure-html/Pure_html/index.html
@@ -1,11 +1,11 @@
-Pure_html (pure-html.Pure_html) Module Pure_html
Use this module for constructing HTML without any dependency on the Dream web framework.
Core types
These are the types of the final values which get rendered.
Output
val to_string : node -> string
val to_xml : ?header:bool -> node -> string
Same as to_string
but render void tags as XML-style self-closing tags.
val pp : Stdlib.Format.formatter -> node -> unit
val pp_xml : Stdlib.Format.formatter -> ?header:bool -> node -> unit
Same as pp
but render void tags as XML-style self-closing tags.
Constructing nodes and attributes
type 'a to_attr = 'a -> attr
Attributes can be created from typed values.
type 'a string_attr = ('a, unit, string, attr) Stdlib.format4 -> 'a
Special handling for string-value attributes so they can use format strings i.e. string interpolation.
A 'void element': https://developer.mozilla.org/en-US/docs/Glossary/Void_element with no children.
Tags which can have attributes but can contain only text. The text can be formatted.
val attr : string -> attr
attr name
is a new attribute which does not carry any payload. E.g.
let required = attr "required"
val string_attr : string -> ?raw:bool -> _ string_attr
string_attr name fmt
is a new string-valued attribute which allows formatting i.e. string interpolation of the value. Note, the fmt
argument is required due to the value restriction.
val uri_attr : string -> _ string_attr
Convenience for attributes whose values should be URIs. Takes care of both URI-encoding and attribute escaping, as recommended in https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#common-mistake.
Examples
a [href "/blog?tags=iamsafe\"></a><script>alert('Pwned')</script>"] [txt "Tags: tag1 | tag2"]
+Pure_html (pure-html.Pure_html) Module Pure_html
Use this module for constructing HTML without any dependency on the Dream web framework.
Core types
These are the types of the final values which get rendered.
Output
val to_string : node -> string
val to_xml : ?header:bool -> node -> string
Same as to_string
but render void tags as XML-style self-closing tags.
val pp : Stdlib.Format.formatter -> node -> unit
val pp_xml : Stdlib.Format.formatter -> ?header:bool -> node -> unit
Same as pp
but render void tags as XML-style self-closing tags.
Constructing nodes and attributes
type 'a to_attr = 'a -> attr
Attributes can be created from typed values.
type 'a string_attr = ('a, unit, string, attr) Stdlib.format4 -> 'a
Special handling for string-value attributes so they can use format strings i.e. string interpolation.
A 'void element': https://developer.mozilla.org/en-US/docs/Glossary/Void_element with no children.
Tags which can have attributes but can contain only text. The text can be formatted.
val attr : string -> attr
attr name
is a new attribute which does not carry any payload. E.g.
let required = attr "required"
val string_attr : string -> ?raw:bool -> _ string_attr
string_attr name fmt
is a new string-valued attribute which allows formatting i.e. string interpolation of the value. Note, the fmt
argument is required due to the value restriction.
val uri_attr : string -> _ string_attr
Convenience for attributes whose values should be URIs. Takes care of both URI-encoding and attribute escaping, as recommended in https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#common-mistake.
Examples
a [href "/blog?tags=iamsafe\"></a><script>alert('Pwned')</script>"] [txt "Tags: tag1 | tag2"]
==>
<a href="/blog?tags=iamsafe%22%3E%3C/a%3E%3Cscript%3Ealert('Pwned')%3C/script%3E">Tags: tag1 | tag2</a>
a [href "/foo?a=1&b=2 3&c=4<5&d=6>5"] [txt "Test"]
==>
-<a href="/foo?a=1&b=2%203&c=4%3C5&d=6%3E5">Test</a>
val bool_attr : string -> bool to_attr
val float_attr : string -> float to_attr
val int_attr : string -> int to_attr
val std_tag : string -> std_tag
val void_tag : string -> void_tag
val text_tag : string -> ?raw:bool -> _ text_tag
Build a tag which can contain only text.
val uri_tag : string -> _ text_tag
Build a tag which can contain only a URI. The URI is scaped with the same rules as a uri_attr
.
val txt : ?raw:bool -> ('a, unit, string, node) Stdlib.format4 -> 'a
A text node inside the DOM e.g. the 'hi' in <b>hi</b>
. Allows string interpolation using the same formatting features as Printf.sprintf
:
b [] [txt "Hello, %s!" name]
Or without interpolation:
b [] [txt "Bold of you."]
HTML-escapes the text value. You can use the ~raw
param to bypass escaping:
let user_input = "<script>alert('I like HTML injection')</script>" in
+<a href="/foo?a=1&b=2%203&c=4%3C5&d=6%3E5">Test</a>
val bool_attr : string -> bool to_attr
val float_attr : string -> float to_attr
val int_attr : string -> int to_attr
val std_tag : string -> std_tag
val void_tag : string -> void_tag
val text_tag : string -> ?raw:bool -> _ text_tag
Build a tag which can contain only text.
val uri_tag : string -> _ text_tag
Build a tag which can contain only a URI. The URI is escaped with the same rules as a uri_attr
.
val txt : ?raw:bool -> ('a, unit, string, node) Stdlib.format4 -> 'a
A text node inside the DOM e.g. the 'hi' in <b>hi</b>
. Allows string interpolation using the same formatting features as Printf.sprintf
:
b [] [txt "Hello, %s!" name]
Or without interpolation:
b [] [txt "Bold of you."]
HTML-escapes the text value. You can use the ~raw
param to bypass escaping:
let user_input = "<script>alert('I like HTML injection')</script>" in
txt ~raw:true "%s" user_input
val comment : string -> node
A comment that will be embedded in the rendered HTML, i.e. <!-- comment -->
. The text is HTML-escaped.
Accessors for tags
Add an attribute to a tag.
let toast msg = p [id "toast"] [txt "%s" msg]
let toast_oob = toast "ok." +@ Hx.swap_oob "true"
val (.@[]) : node -> string -> string
Get the value of an existing attribute.
let toast = p [id "toast"] [txt "OK."]
let toast_id = toast.@["id"]
val is_null : node -> bool
Get whether a node is null (empty) or not. Useful for conditional rendering of UIs when you are passed in a node and you don't know if it's empty or not.
val is_null_ : attr -> bool
Get whether an attribute is null (empty) or not.
HTML
module HTML : sig ... end
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
SVG
module SVG : sig ... end
MathML
module MathML : sig ... end
ARIA
module Aria : sig ... end
RSS and Atom
module Atom : sig ... end
htmx
diff --git a/pure-html/index.html b/pure-html/index.html
index 940eb24..d557822 100644
--- a/pure-html/index.html
+++ b/pure-html/index.html
@@ -1,2 +1,2 @@
-index (pure-html.index) pure-html index
Library pure-html
The entry point of this library is the module: Pure_html
.
+index (pure-html.index) pure-html index
Library pure-html
The entry point of this library is the module: Pure_html
.
diff --git a/sql.txt b/sql.txt
deleted file mode 100644
index 53431a0..0000000
--- a/sql.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-open Caqti_type.Std
-
-(* type prepared = Caqti_type.t * (Caqti_driver_info.t -> Caqti_query.t) *)
-
-let rec arg_type' :
- type r t.
- ?tuple_size:int ->
- (r, _, _, _, _, t Caqti_type.t) CamlinternalFormatBasics.fmt ->
- r ->
- t Caqti_type.t =
- fun ?(tuple_size = 0) fmt ->
- match fmt with
- | String (No_padding, fmt) -> assert false
- | _ -> assert false
-
-let arg_type (CamlinternalFormatBasics.Format (fmt, _)) = arg_type' fmt proj_end
-let row_type _ = assert false
-let query _ = assert false
-
-let all afmt rfmt =
- Caqti_request.create (arg_type afmt) (row_type rfmt) Caqti_mult.zero_or_more
- (query afmt)
diff --git a/todos/1 b/todos/1
deleted file mode 100644
index 79a88bd..0000000
--- a/todos/1
+++ /dev/null
@@ -1 +0,0 @@
-1 false abba
\ No newline at end of file
diff --git a/todos/2 b/todos/2
deleted file mode 100644
index 723c148..0000000
--- a/todos/2
+++ /dev/null
@@ -1 +0,0 @@
-2 false aa
\ No newline at end of file
diff --git a/todos/3 b/todos/3
deleted file mode 100644
index 13e8d50..0000000
--- a/todos/3
+++ /dev/null
@@ -1 +0,0 @@
-3 false aaa
\ No newline at end of file
diff --git a/todos/4 b/todos/4
deleted file mode 100644
index b6785fa..0000000
--- a/todos/4
+++ /dev/null
@@ -1 +0,0 @@
-4 false milk
\ No newline at end of file
diff --git a/todos/5 b/todos/5
deleted file mode 100644
index 1865a4b..0000000
--- a/todos/5
+++ /dev/null
@@ -1 +0,0 @@
-5 false eggs
\ No newline at end of file
diff --git a/todos/6 b/todos/6
deleted file mode 100644
index 72c954e..0000000
--- a/todos/6
+++ /dev/null
@@ -1 +0,0 @@
-6 true bananas
\ No newline at end of file
diff --git a/todos/7 b/todos/7
deleted file mode 100644
index 23c0de9..0000000
--- a/todos/7
+++ /dev/null
@@ -1 +0,0 @@
-7 true laundry
\ No newline at end of file