https://github.com/qmoya/stimulus-clj
“A modest ClojureScript framework for the HTML you already have.”
https://github.com/qmoya/stimulus-clj
clojure clojurescript ssr stimulus turbo
Last synced: 3 months ago
JSON representation
“A modest ClojureScript framework for the HTML you already have.”
- Host: GitHub
- URL: https://github.com/qmoya/stimulus-clj
- Owner: qmoya
- License: mit
- Created: 2023-09-24T14:55:05.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-29T15:44:46.000Z (over 2 years ago)
- Last Synced: 2025-10-11T02:28:15.174Z (3 months ago)
- Topics: clojure, clojurescript, ssr, stimulus, turbo
- Language: Clojure
- Homepage:
- Size: 43.9 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stimulus ❤️ Clojure
[](https://clojars.org/com.github.qmoya/stimulus)
[Stimulus](https://stimulus.hotwired.dev) is “a modest JavaScript framework for the HTML you already have.”
It was created by 37signals as an alternative to heavier approaches
to client-side interactions.
This is an experimental library that lets you write Stimulus controllers
using Clojure.
## Usage
### Server-side
```clojure
(ns my.example
(:require [hiccup.page :as page]
[io.pedestal.http :as http]
[io.pedestal.http.route :as route])
(:gen-class))
(defn home [req]
{:status 200
:headers {"Content-Type" "text/html; charset=utf-8"}
:body (page/html5 [:head
[:title "Stimulus Examples"]
(page/include-js "/js/main.js")]
[:div {:data-controller "hello"}
[:input {:data-hello-target "name", :type "text"}]
[:button {:data-action "click->hello#greet"} "Greet"]
[:span {:data-hello-target "output"}]])})
(def routes
(route/expand-routes
#{["/" :get home :route-name :home]}))
(defn -main
[& args]
(-> {::http/routes routes
::http/port 3000
::http/resource-path "/public"
::http/secure-headers {:content-security-policy-settings {:object-src "none"}}
::http/type :jetty}
http/create-server
http/start))
```
### Client-side
```clojure
(ns stimulus.example.example
(:require [stimulus.controller :refer [->controller]]
["@hotwired/stimulus" :refer [Controller Application]]
[goog.dom :as gdom]))
(defn greet [controller event]
(let [name-target (get-name-target controller)
output-target (get-output-target controller)]
(gdom/setTextContent output-target (str "Hello, " (.-value name-target)))))
(def greet-controller (-> {:extends Controller
:targets ["output" "name"]
:actions {:greet greet}}
->controller))
(let [application (.start Application)]
(.register application "hello" greet-controller))
```