From 6caa2da8aea969664d1feb69b2404dc662a5801c Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Sun, 9 Jun 2024 00:09:14 +0200 Subject: [PATCH 1/4] Add html_of_jsx template --- example/r-html_of_jsx/README.md | 67 ++++++++++++++++++++++++++++ example/r-html_of_jsx/dune | 6 +++ example/r-html_of_jsx/dune-project | 1 + example/r-html_of_jsx/esy.json | 20 +++++++++ example/r-html_of_jsx/html_of_jsx.re | 17 +++++++ 5 files changed, 111 insertions(+) create mode 100644 example/r-html_of_jsx/README.md create mode 100644 example/r-html_of_jsx/dune create mode 100644 example/r-html_of_jsx/dune-project create mode 100644 example/r-html_of_jsx/esy.json create mode 100644 example/r-html_of_jsx/html_of_jsx.re diff --git a/example/r-html_of_jsx/README.md b/example/r-html_of_jsx/README.md new file mode 100644 index 00000000..30a6a319 --- /dev/null +++ b/example/r-html_of_jsx/README.md @@ -0,0 +1,67 @@ +# `r-html_of_jsx` + +
+ +[html_of_jsx](https://github.com/davesnx/html_of_jsx/) can be used together with Reason's built-in JSX syntax for generating HTML on the server: + +```reason +let greet = (~who, ()) => + + "Home" + +

{Jsx.txt("Good morning, " ++ who ++ "!")}

+ + ; + +let () = + Dream.run + @@ Dream.logger + @@ Dream.router([ + + Dream.get("/", + (_ => Dream.html(Jsx.render())))), + + ]); +``` + +
$ cd example/r-tyxml
+$ npm install esy && npx esy
+$ npx esy start
+ +
+ +To get this, we depend on package `html_of_jsx` in +[`esy.json`](https://github.com/aantron/dream/blob/master/example/r-html_of_jsx/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`](https://github.com/aantron/dream/blob/master/example/r-html_of_jsx/dune): + +
(executable
+ (name html_of_jsx)
+ (libraries dream html_of_jsx)
+ (preprocess (pps lwt_ppx html_of_jsx.ppx)))
+
+ +
+ +**See also:** + +- [**`html_of_jsx`](https://github.com/davesnx/html_of_jsx/) + +
+ +[Up to the example index](../#reason) diff --git a/example/r-html_of_jsx/dune b/example/r-html_of_jsx/dune new file mode 100644 index 00000000..fac3553d --- /dev/null +++ b/example/r-html_of_jsx/dune @@ -0,0 +1,6 @@ +(executable + (name html_of_jsx) + (libraries dream html_of_jsx) + (preprocess (pps lwt_ppx html_of_jsx.ppx))) + +(data_only_dirs _esy esy.lock lib node_modules) diff --git a/example/r-html_of_jsx/dune-project b/example/r-html_of_jsx/dune-project new file mode 100644 index 00000000..929c696e --- /dev/null +++ b/example/r-html_of_jsx/dune-project @@ -0,0 +1 @@ +(lang dune 2.0) diff --git a/example/r-html_of_jsx/esy.json b/example/r-html_of_jsx/esy.json new file mode 100644 index 00000000..2d5b0e61 --- /dev/null +++ b/example/r-html_of_jsx/esy.json @@ -0,0 +1,20 @@ +{ + "dependencies": { + "@opam/conf-libssl": "3", + "@opam/dream": "1.0.0~alpha5", + "@opam/dune": "^3.0", + "@opam/reason": "^3.8.0", + "@opam/html_of_jsx": "*", + "ocaml": "^4.14.0" + }, + "devDependencies": { + "@opam/ocaml-lsp-server": "*" + }, + "resolutions": { + "@opam/conf-libev": "esy-packages/libev:package.json#0b5eb6685b688649045aceac55dc559f6f21b829", + "esy-openssl": "esy-packages/esy-openssl#619ae2d46ca981ec26ab3287487ad98b157a01d1" + }, + "scripts": { + "start": "dune exec --root . ./html_of_jsx.exe" + } +} diff --git a/example/r-html_of_jsx/html_of_jsx.re b/example/r-html_of_jsx/html_of_jsx.re new file mode 100644 index 00000000..83dbabb0 --- /dev/null +++ b/example/r-html_of_jsx/html_of_jsx.re @@ -0,0 +1,17 @@ +let greet = (~who, ()) => + + "Home" + +

{Jsx.txt("Good morning, " ++ who ++ "!")}

+ + ; + +let () = + Dream.run + @@ Dream.logger + @@ Dream.router([ + + Dream.get("/", + (_ => Dream.html(Jsx.render())))), + + ]); From 77649bcc18e8c1f8ae9fbed7027d9c74d87272db Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Thu, 27 Jun 2024 16:32:09 +0100 Subject: [PATCH 2/4] Use html_of_jsx 0.0.4 --- example/r-html_of_jsx/esy.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/r-html_of_jsx/esy.json b/example/r-html_of_jsx/esy.json index 2d5b0e61..89c700aa 100644 --- a/example/r-html_of_jsx/esy.json +++ b/example/r-html_of_jsx/esy.json @@ -4,7 +4,7 @@ "@opam/dream": "1.0.0~alpha5", "@opam/dune": "^3.0", "@opam/reason": "^3.8.0", - "@opam/html_of_jsx": "*", + "@opam/html_of_jsx": "0.0.4", "ocaml": "^4.14.0" }, "devDependencies": { From b484424336aebe600fb31bac683b095a9c241f44 Mon Sep 17 00:00:00 2001 From: David Sancho Date: Wed, 24 Jul 2024 13:31:12 +0200 Subject: [PATCH 3/4] Remove `~` from props in r-html_of_jsx --- example/r-html_of_jsx/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/r-html_of_jsx/README.md b/example/r-html_of_jsx/README.md index 30a6a319..28d27647 100644 --- a/example/r-html_of_jsx/README.md +++ b/example/r-html_of_jsx/README.md @@ -19,7 +19,7 @@ let () = @@ Dream.router([ Dream.get("/", - (_ => Dream.html(Jsx.render())))), + (_ => Dream.html(Jsx.render())))), ]); ``` From de0a86d304a15e149971a11602f2b5a65e6ab41c Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Wed, 24 Jul 2024 15:36:30 +0300 Subject: [PATCH 4/4] Make example/r-html_of_jsx compile --- example/r-html_of_jsx/html_of_jsx.re | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/r-html_of_jsx/html_of_jsx.re b/example/r-html_of_jsx/html_of_jsx.re index 83dbabb0..ec6f7684 100644 --- a/example/r-html_of_jsx/html_of_jsx.re +++ b/example/r-html_of_jsx/html_of_jsx.re @@ -2,7 +2,7 @@ let greet = (~who, ()) => "Home" -

{Jsx.txt("Good morning, " ++ who ++ "!")}

+

{JSX.string("Good morning, " ++ who ++ "!")}

; @@ -12,6 +12,6 @@ let () = @@ Dream.router([ Dream.get("/", - (_ => Dream.html(Jsx.render())))), + (_ => Dream.html(JSX.render()))), ]);