Hello, World!
-``` - -Webs: - -```ocaml -open Webs_html -open El -open At - -let greeting = p ~at:[class' "text-lg"; id "hello"] [txt "Hello, World!"] -``` - -Dream-html: - -```ocaml -open Dream_html -open Tag -open Attr - -let greeting = p[class_ "text-lg"; id "hello"][txt "Hello, World!"] -``` - -Note, this is not meant to be a demonstration of how many characters you're -saving. It's just a different style which I have found we can take advantage of -thanks to OCaml being whitespace-insensitive. Normally you wouldn't format OCaml -code like this, but I feel that the domain justifies it. - -## Details - -Attribute and text values are escaped using -[`Dream.html_escape`](https://aantron.github.io/dream/#val-html_escape): - -``` -utop # open Dream_html;; -utop # let user_input = "";; -utop # open Tag;; -utop # let safe = p[][txt "%s" user_input];; -utop # to_string safe;; -- : string = -"<script>alert('You have been pwned')</script>
" -``` - -## Usage - -A convenience is provided to respond with an HTML node from a handler: - -```ocaml -Dream_html.respond greeting -``` - -You can compose multiple HTML nodes together into a single node without an extra -DOM node, like [React fragments](https://react.dev/reference/react/Fragment): - -```ocaml -let view = Tag.null[ - p[][txt "Hello"]; - p[][txt "World"]] -``` - -You can do string interpolation using the `txt` node constructor and of any -attribute which takes a string value: - -```ocaml -let greet name = p[id "greet-%s" name][txt "Hello, %s!" name] -``` - -You can conditionally render an attribute, and -[void elements](https://developer.mozilla.org/en-US/docs/Glossary/Void_element) -are statically enforced as childless: - -```ocaml -let entry = input[ - if should_focus then autofocus else null; - id "email"; - name "email"; - value "Email address"] -``` - -You can also embed HTML comments in the generated document: - -```ocaml -div[][ - comment "TODO: xyz."; - p[][txt "Hello!"]] -``` - -## Explore in the REPL - -``` -$ utop -utop # #require "dream_html";; -utop # open Dream_html;; -utop # open Tag;; -utop # open Attr;; -utop # #install_printer pp;; -utop # p[class_ "hello"][txt "world"];; -- : node =world
-``` - -## Test - -Run the test and print out diff if it fails: - - dune runtest # Will also exit 1 on failure - -Set the new version of the output as correct: - - dune promote - -## Prior art/design notes - -Surface design obviously lifted straight from -[elm-html](https://package.elm-lang.org/packages/elm/html/latest/). - -Similar to [Webs](https://erratique.ch/software/webs/doc/Webs_html/index.html) as -mentioned earlier (it turns out there are only a limited number of ways to do -this kind of library). - -Implementation inspired by both elm-html and -[Scalatags](https://com-lihaoyi.github.io/scalatags/). diff --git a/dream-html/Dream_html/.dummy b/dream-html/Dream_html/.dummy deleted file mode 100644 index e69de29..0000000 diff --git a/dream-html/Dream_html/Aria/index.html b/dream-html/Dream_html/Aria/index.html index 7c76acf..70099a0 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 | `polite ] to_attr
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 | `polite ] to_attr
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.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.
val ensure :
+ string ->
+ ('b -> bool) ->
+ ('a ty -> string -> 'b t) ->
+ 'a ty ->
+ string ->
+ 'b t
ensure message condition field ty name
is a form field which imposes an additional condition
on top of the existing field
. If the condition fails, the result is an error message
. It is suggested that the message
be a translation key so that the application can be localized to different languages.
let* start_date = required unix_tm "start-date"
decodes a form field and allows accessing it in the subsequent decoders. Eg:
let* start_date = required unix_tm "start-date" in
+let+ end_date = required (unix_tm ~min:start_date) "end-date" in
+...
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.
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.
Basic complete example:
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! *)
+ { 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")]
Decode list of values from form:
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.
Add further requirements to field values:
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")]
Complex validation rules with multiple fields:
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 *)
+ let* days = optional int "days" in
+ let* weeks = optional int "weeks" in
+ let* months = optional int "months" in
+ let* years = optional int "years" in
+ match days, weeks, months, years with
+ | None, None, None, None -> error "years" "Please enter a period"
+ (* 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")]
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] [
+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 async : attr
val autocapitalize :
diff --git a/dream-html/Dream_html/Hx/index.html b/dream-html/Dream_html/Hx/index.html
index 15e01db..d0e2442 100644
--- a/dream-html/Dream_html/Hx/index.html
+++ b/dream-html/Dream_html/Hx/index.html
@@ -1,2 +1,2 @@
-Hx (dream-html.Dream_html.Hx) Module Dream_html.Hx
htmx support https://htmx.org/reference/
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 boost : bool to_attr
val confirm : _ string_attr
val delete : _ string_attr
val disable : attr
val disinherit : _ string_attr
val encoding_formdata : attr
Hardcoding of the hx-encoding
attribute to multipart/form-data
.
val ext : _ string_attr
val get : _ 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 on : _ string_attr
Note that the value of this attribute is not escaped.
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 params : _ string_attr
val patch : _ string_attr
val post : _ string_attr
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val preserve : attr
val prompt : _ string_attr
val push_url : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ 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 sse_connect : _ string_attr
val sse_swap : _ string_attr
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 sync : _ string_attr
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 validate : attr
val vals : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
+Hx (dream-html.Dream_html.Hx) Module Dream_html.Hx
htmx support https://htmx.org/reference/
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 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 get : _ 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 on : _ string_attr
Note that the value of this attribute is not escaped.
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 params : _ string_attr
val patch : _ string_attr
val post : _ string_attr
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val preserve : attr
val prompt : _ string_attr
val push_url : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ 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 sse_close : _ string_attr
val sse_connect : _ string_attr
val sse_swap : _ string_attr
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 sync : _ string_attr
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 validate : attr
val vals : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
diff --git a/dream-html/Dream_html/Livereload/index.html b/dream-html/Dream_html/Livereload/index.html
index b24b4d2..312bfe4 100644
--- a/dream-html/Dream_html/Livereload/index.html
+++ b/dream-html/Dream_html/Livereload/index.html
@@ -1,10 +1,8 @@
-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
+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.
+ ]
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.
diff --git a/dream-html/Dream_html/MathML/index.html b/dream-html/Dream_html/MathML/index.html
index 4e13382..d4da082 100644
--- a/dream-html/Dream_html/MathML/index.html
+++ b/dream-html/Dream_html/MathML/index.html
@@ -1,2 +1,2 @@
-MathML (dream-html.Dream_html.MathML) Module 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
+MathML (dream-html.Dream_html.MathML) Module 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
diff --git a/dream-html/Dream_html/Path/index.html b/dream-html/Dream_html/Path/index.html
new file mode 100644
index 0000000..c445a33
--- /dev/null
+++ b/dream-html/Dream_html/Path/index.html
@@ -0,0 +1,5 @@
+
+Path (dream-html.Dream_html.Path) Module Dream_html.Path
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. Refer to Path.make for the syntax of the route strings.
val make :
+ ('r, unit, Dream.response Dream.promise) Stdlib.format ->
+ ('p, unit, string, attr) Stdlib.format4 ->
+ ('r, 'p) t
make request_fmt attr_fmt
is a route path. The dream-html.ppx
provides a more convenient way.
Without PPX: let order = Path.make "/orders/%s" "/orders/%s"
With PPX: let order = [%path "/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. Eg, /foo/%s/bar/%d
is valid, but /foo/%s.%s
(note the dot character) is not a valid capture.
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
val pp : (_, _) t Fmt.t
pp
is a pretty-printer for path values. For a path like Path.make "/foo", "/foo"
, it will print out /foo
.
diff --git a/dream-html/Dream_html/Route/index.html b/dream-html/Dream_html/Route/index.html
new file mode 100644
index 0000000..7e0627d
--- /dev/null
+++ b/dream-html/Dream_html/Route/index.html
@@ -0,0 +1,27 @@
+
+Route (dream-html.Dream_html.Route) Module Dream_html.Route
Bidirectional routes with type-safe path segment parsing and printing using OCaml's built-in format strings, and support for scoped middleware.
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 route path. The ppx_dream_html
PPX provides a more convenient way.
Without PPX: let order = path "/orders/%s" "/orders/%s"
With PPX: let order = [%route_path "/orders/%s"]
link path
is a dream-html attribute value that prints out the filled path
given its parameters. Use this instead of hard-coding your route URLs throughout your app, to make it easy to refactor routes with minimal effort.
Eg:
open Dream_html
+open HTML
+
+a [href (Route.link order) "yzxyzc"] [txt "My Order"]
Renders: <a href="/orders/yzxyzc">My Order</a>
make ?meth path handler
is a route which handles requests with meth
if specified, or any method otherwise.
The following are convenience functions for creating routes.
val format : t -> string
format route
is the template string used to match request paths against the route
.
val handler : t -> Dream.handler
handler route
converts the route
into a Dream handler.
route1 >> route2
joins together route1
and route2
into a new route so that requests targeting either of them will match. Use this to build your app's routes. Eg, in Dream your routes might look like:
Dream.router [
+ Dream.get "/echo/:word" Echo.get;
+ Dream.post "/echo/:word" Echo.post;
+]
With ( >> )
it would look like:
let echo = [%route_path "/echo/%s"]
+...
+Route.handler (
+ Route.get echo Echo.get >>
+ Route.post echo Echo.post
+)
middleware1 && middleware2
joins together two Dream middlewares so that middleware1
is applied first, then middleware2
.
with_ middleware route
is a route that matches any of the paths handled in route
, and handles those requests by applying the middleware
and the route
handler. Eg:
let add_header prev req =
+ let open Lwt.Syntax in
+ let+ resp = prev req in
+ Dream.add_header resp "X-Api-Server" "Dream";
+ resp
+
+let get_order_v2 =
+ with_ add_header (get [%route_path "/v2/orders/%s"] (fun _ id -> Dream.html id))
In the example above, get_order_v2
will match against requests with paths like "/v2/orders/%s", apply the add_header
middleware, and handle the request.
val pp : t Fmt.t
pp
is a formatter that prints out a simple summary of the route, eg GET /foo/%s
or just /foo/%s
if the route matches any method.
diff --git a/dream-html/Dream_html/SVG/index.html b/dream-html/Dream_html/SVG/index.html
index d6f0f61..4c422e5 100644
--- a/dream-html/Dream_html/SVG/index.html
+++ b/dream-html/Dream_html/SVG/index.html
@@ -1,3 +1,3 @@
-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 :
+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 12b3162..b1561a4 100644
--- a/dream-html/Dream_html/index.html
+++ b/dream-html/Dream_html/index.html
@@ -1,5 +1,24 @@
-Dream_html (dream-html.Dream_html) Module Dream_html
include module type of Pure_html
Core types
These are the types of the final values which get rendered.
Output
val to_string : node -> string
val to_xml : 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 -> 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"]
+Dream_html (dream-html.Dream_html) Module Dream_html
Input
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 ->
+ [> 'a Dream.form_result | `Invalid of (string * string) list ] Dream.promise
Type-safe wrapper for Dream.form
. Similarly to that, you can match on the result:
type new_user = { name : string; email : string }
+let new_user =
+ let open Dream_html.Form in
+ let+ name = required string "name"
+ and+ email = required string "email" in
+ { name; email }
+
+(* POST /users *)
+let post_users req =
+ match%lwt Dream_html.form new_user req with
+ | `Ok { name; email } -> (* ... *)
+ | `Invalid errors -> Dream.json ~code:422 ( (* ...render errors... *) )
+ | _ -> Dream.empty `Bad_Request
val query :
+ 'a Form.t ->
+ Dream.request ->
+ [> `Ok of 'a | `Invalid of (string * string) list ]
Type-safe wrapper for Dream.all_queries
. Can be used to decode the query parameters into a typed value.
Output
include module type of Pure_html
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>
@@ -8,7 +27,7 @@
<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 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.
Standard attributes and tags
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.
module SVG : sig ... end
module MathML : sig ... end
ARIA support
module Aria : sig ... end
htmx support
module Hx : sig ... end
htmx support https://htmx.org/reference/
Output
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.
Standard attributes and tags
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.
module SVG : sig ... end
module MathML : sig ... end
ARIA support
module Aria : sig ... end
htmx support
module Hx : sig ... end
htmx support https://htmx.org/reference/
val respond :
?status:[< Dream.status ] ->
?code:int ->
?headers:(string * string) list ->
@@ -18,6 +37,22 @@
?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 wrapper for Dream.csrf_tag
.
form
- [action "/foo"]
- [csrf_tag req; input [name "bar"]; input [type_ "submit"]]
Live reload support
module Livereload : sig ... end
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.
+ unit Dream.promiseType-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 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 order = [%path "/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. Eg, /foo/%s/bar/%d
is valid, but /foo/%s.%s
(note the dot character) is not a valid capture.
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
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 order = [%path "/orders/%s"]
+
+open Dream_html
+open HTML
+
+a [path_attr href order "yzxyzc"] [txt "My Order"]
Renders: <a href="/orders/yzxyzc">My Order</a>
Use this instead of hard-coding your route URLs throughout your app, to make it easy to refactor routes with minimal effort.
val pp_path : (_, _) path Fmt.t
pp_path
is a pretty-printer for path values. For a path like path "/foo" "/foo"
, it will print out /foo
.
val get : (_, _) route
Type-safe wrappers for Dream.get
and so on. Using the PPX, eg:
let order = [%path "/orders/%s"]
+
+let get_order = get order (fun request order_id ->
+ ...
+ 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.
Live reload support
module Livereload : sig ... end
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.
diff --git a/dream-html/Dream_html_test/Form_tests/index.html b/dream-html/Dream_html_test/Form_tests/index.html
new file mode 100644
index 0000000..f21460f
--- /dev/null
+++ b/dream-html/Dream_html_test/Form_tests/index.html
@@ -0,0 +1,5 @@
+
+Form_tests (dream-html.Dream_html_test.Form_tests) Module Dream_html_test.Form_tests
val pp_user : user Fmt.t
val pp :
+ Stdlib.Format.formatter ->
+ (user, (string * string) list) Stdlib.result ->
+ unit
val user_form : user Dream_html.Form.t
diff --git a/dream-html/Dream_html_test/index.html b/dream-html/Dream_html_test/index.html
new file mode 100644
index 0000000..d7a8877
--- /dev/null
+++ b/dream-html/Dream_html_test/index.html
@@ -0,0 +1,8 @@
+
+Dream_html_test (dream-html.Dream_html_test) Module Dream_html_test
val pp_user : user Fmt.t
val pp :
+ Stdlib.Format.formatter ->
+ (user, (string * string) list) Stdlib.result ->
+ unit
val user_form : user Dream_html.Form.t
diff --git a/dream-html/Ppx/index.html b/dream-html/Ppx/index.html
new file mode 100644
index 0000000..7aebc50
--- /dev/null
+++ b/dream-html/Ppx/index.html
@@ -0,0 +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 orders = [%path "/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 "example.ml", line 1, characters 10-23:
+1 | let bad = [%path "foo"]
+ ^^^^^^^^^^^^^
+Error: Invalid path: 'foo'. Paths must start with a '/' character
diff --git a/dream-html/Ppx_dream_html/index.html b/dream-html/Ppx_dream_html/index.html
new file mode 100644
index 0000000..0ccc4a4
--- /dev/null
+++ b/dream-html/Ppx_dream_html/index.html
@@ -0,0 +1,2 @@
+
+Ppx_dream_html (dream-html.Ppx_dream_html) Module Ppx_dream_html
This PPX provides an extension point to create route paths.
You can add it to your dune
file in the usual way: (preprocess (pps ppx_dream_html))
.
Then create a path: let orders = [%route_path "/orders"]
.
And use it in a route: Route.get orders (fun req -> ...)
.
This provides a convenient way to create route paths and reuse them throughout your app. The way it works is by just duplicating the format string literal argument. However, this naturally means that both the route parser and attribute printer format strings are identical. If you need different formatting for the two, you can use the underlying path
function.
diff --git a/dream-html/index.html b/dream-html/index.html
index b4ff5c1..78a45d8 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
.
+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 71148de..15240b5 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.2 */
+ odoc 2.4.3 */
/* Fonts */
/* noticia-text-regular - latin */
diff --git a/pure-html/Pure_html/Aria/index.html b/pure-html/Pure_html/Aria/index.html
index 54ebf1c..9e48cae 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 | `polite ] to_attr
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 | `polite ] to_attr
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/HTML/index.html b/pure-html/Pure_html/HTML/index.html
index 998fede..abddb8f 100644
--- a/pure-html/Pure_html/HTML/index.html
+++ b/pure-html/Pure_html/HTML/index.html
@@ -1,5 +1,5 @@
-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] [
+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 async : attr
val autocapitalize :
diff --git a/pure-html/Pure_html/Hx/index.html b/pure-html/Pure_html/Hx/index.html
index c4638a0..9a38edb 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 https://htmx.org/reference/
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 boost : bool to_attr
val confirm : _ string_attr
val delete : _ string_attr
val disable : attr
val disinherit : _ string_attr
val encoding_formdata : attr
Hardcoding of the hx-encoding
attribute to multipart/form-data
.
val ext : _ string_attr
val get : _ 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 on : _ string_attr
Note that the value of this attribute is not escaped.
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 params : _ string_attr
val patch : _ string_attr
val post : _ string_attr
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val preserve : attr
val prompt : _ string_attr
val push_url : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ 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 sse_connect : _ string_attr
val sse_swap : _ string_attr
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 sync : _ string_attr
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 validate : attr
val vals : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
+Hx (pure-html.Pure_html.Hx) Module Pure_html.Hx
htmx support https://htmx.org/reference/
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 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 get : _ 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 on : _ string_attr
Note that the value of this attribute is not escaped.
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 params : _ string_attr
val patch : _ string_attr
val post : _ string_attr
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val preserve : attr
val prompt : _ string_attr
val push_url : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ 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 sse_close : _ string_attr
val sse_connect : _ string_attr
val sse_swap : _ string_attr
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 sync : _ string_attr
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 validate : attr
val vals : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
diff --git a/pure-html/Pure_html/MathML/index.html b/pure-html/Pure_html/MathML/index.html
index 7dafdb2..53664e0 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/SVG/index.html b/pure-html/Pure_html/SVG/index.html
index b632bf1..ecc69b2 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 b3be775..20777fe 100644
--- a/pure-html/Pure_html/index.html
+++ b/pure-html/Pure_html/index.html
@@ -1,5 +1,5 @@
-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 : 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 -> 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>
diff --git a/pure-html/Pure_html_test/Html_tests/index.html b/pure-html/Pure_html_test/Html_tests/index.html
new file mode 100644
index 0000000..0a45a16
--- /dev/null
+++ b/pure-html/Pure_html_test/Html_tests/index.html
@@ -0,0 +1,2 @@
+
+Html_tests (pure-html.Pure_html_test.Html_tests) Module Pure_html_test.Html_tests
diff --git a/pure-html/Pure_html_test/Mathml_tests/index.html b/pure-html/Pure_html_test/Mathml_tests/index.html
new file mode 100644
index 0000000..628ebc4
--- /dev/null
+++ b/pure-html/Pure_html_test/Mathml_tests/index.html
@@ -0,0 +1,2 @@
+
+Mathml_tests (pure-html.Pure_html_test.Mathml_tests) Module Pure_html_test.Mathml_tests
diff --git a/pure-html/Pure_html_test/index.html b/pure-html/Pure_html_test/index.html
new file mode 100644
index 0000000..4db78eb
--- /dev/null
+++ b/pure-html/Pure_html_test/index.html
@@ -0,0 +1,2 @@
+
+Pure_html_test (pure-html.Pure_html_test) Module Pure_html_test
module Html_tests : sig ... end
module Mathml_tests : sig ... end
diff --git a/pure-html/index.html b/pure-html/index.html
index a4dbecd..940eb24 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
.