html_of_jsx can be used together with Reason's built-in JSX syntax for generating HTML on the server:
let greet = (~who, ()) =>
<html>
<head><title>"Home"</title></head>
<body>
<h1>{Jsx.txt("Good morning, " ++ who ++ "!")}</h1>
</body>
</html>;
let () =
Dream.run
@@ Dream.logger
@@ Dream.router([
Dream.get("/",
(_ => Dream.html(Jsx.render(<greet who="world" />))))),
]);$ cd example/r-tyxml
$ npm install esy && npx esy
$ npx esy startTo get this, we depend on package html_of_jsx in
esy.json:
{
"dependencies": {
"@opam/dream": "1.0.0~alpha4",
"@opam/dune": "^2.0",
"@opam/reason": "^3.8.0",
"@opam/html_of_jsx": "*",
"ocaml": "4.14.x"
},
"scripts": {
"start": "dune exec --root . ./html_of_jsx.exe"
}
}
and add html_of_jsx.ppx to our preprocessor list in
dune:
(executable
(name html_of_jsx)
(libraries dream html_of_jsx)
(preprocess (pps lwt_ppx html_of_jsx.ppx)))
See also: