Skip to content

Commit

Permalink
Examples: add w-mlx (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypopp authored Oct 14, 2024
1 parent 91b470d commit 6a1a2f0
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
35 changes: 35 additions & 0 deletions example/w-mlx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# `w-mlx`

<br>

[mlx](https://github.com/ocaml-mlx/mlx), an OCaml syntax dialect which adds JSX
expressions, can be used with Dream for generating HTML.

```ocaml
let greet ~who () =
<html>
<head>
<title>"Greeting"</title>
</head>
<body>
<h1>"Good morning, " (JSX.string who) "!"</h1>
</body>
</html>
let () =
Dream.run
@@ Dream.logger
@@ Dream.router [
Dream.get "/" (fun _ ->
let html = JSX.render <greet who="world" /> in
Dream.html html)
]
```

<pre><code><b>$ cd example/w-mlx</b>
<b>$ opam install --deps-only --yes .</b>
<b>$ dune exec --root . ./mlx.exe</b></code></pre>

<br>

[Up to the example index](../#examples)
4 changes: 4 additions & 0 deletions example/w-mlx/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(name mlx)
(libraries dream html_of_jsx)
(preprocess (pps html_of_jsx.ppx)))
10 changes: 10 additions & 0 deletions example/w-mlx/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(lang dune 3.16)

(dialect
(name mlx)
(implementation
(merlin_reader mlx)
(extension mlx)
(preprocess
(run mlx-pp %{input-file}))))

Empty file added example/w-mlx/dune-workspace
Empty file.
18 changes: 18 additions & 0 deletions example/w-mlx/mlx.mlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let greet ~who () =
<html>
<head>
<title>"Greeting"</title>
</head>
<body>
<h1>"Good morning, " (JSX.string who) "!"</h1>
</body>
</html>

let () =
Dream.run
@@ Dream.logger
@@ Dream.router [
Dream.get "/" (fun _ ->
let html = JSX.render <greet who="world" /> in
Dream.html html)
]
9 changes: 9 additions & 0 deletions example/w-mlx/w-mlx.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
opam-version: "2.0"

depends: [
"ocaml" {>= "4.08.0"}
"dream"
"dune" {>= "3.16.0"}
"mlx"
"html_of_jsx"
]

0 comments on commit 6a1a2f0

Please sign in to comment.