Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: add w-mlx #330

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
]
Loading