-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathui.clj
More file actions
47 lines (41 loc) · 1.36 KB
/
ui.clj
File metadata and controls
47 lines (41 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(ns <<ns-name>>.web.routes.ui
(:require
[<<ns-name>>.web.middleware.exception :as exception]
[<<ns-name>>.web.middleware.formats :as formats]
[<<ns-name>>.web.routes.utils :as utils]
[<<ns-name>>.web.htmx :refer [page fragment] :as htmx]
[integrant.core :as ig]
[reitit.ring.middleware.muuntaja :as muuntaja]
[reitit.ring.middleware.parameters :as parameters]))
(defn home [request]
(page {:lang "en"}
[:head
[:meta {:charset "UTF-8"}]
[:title "Htmx + Kit"]
[:script {:src "https://unpkg.com/htmx.org@2.0.8/dist/htmx.min.js" :defer true}]]
[:body
[:h1 "Welcome to Htmx + Kit module"]
[:button {:hx-post "/clicked" :hx-swap "outerHTML"} "Click me!"]]))
(defn clicked [request]
(fragment
[:div "Congratulations! You just clicked the button!"]))
;; Routes
(defn ui-routes [_opts]
[["/" {:get home}]
["/clicked" {:post clicked}]])
(def route-data
{:muuntaja formats/instance
:middleware
[;; Default middleware for ui
;; query-params & form-params
parameters/parameters-middleware
;; encoding response body
muuntaja/format-response-middleware
;; exception handling
exception/wrap-exception]})
(derive :reitit.routes/ui :reitit/routes)
(defmethod ig/init-key :reitit.routes/ui
[_ {:keys [base-path]
:or {base-path ""}
:as opts}]
(fn [] [base-path route-data (ui-routes opts)]))