(import joy :prefix "")
(route :get "/" :home)
(defn home [request]
(text/plain "You found joy!"))
(def app (app))
(server app 9001)
[:form
[:input {:type "text" :placeholder "Your name"}]
[:input {:type "email" :placeholder "Your email"}]
[:input {:type "submit" :value "Submit"}]]
<form>
<input type="text" placeholder="Your name" />
<input type="email" placeholder="Your email" />
<input type="submit" value="Submit" />
</form>
(let [groceries [{:name "eggs"}
{:name "milk"}
{:name "tomatoes"}]]
[:ul
(foreach [g groceries]
[:li (g :name)])])
<ul>
<li>eggs</li>
<li>milk</li>
<li>tomatoes</li>
</ul>
[:h1.text-2xl.text-gray-400
"You found joy!"]
<h1 class="text-2xl text-gray-400">You found joy!</h1>
(def h1 :h1.text-2xl.text-gray-400)
[h1 "You found joy!"]
<h1 class="text-2xl text-gray-400">You found joy!</h1>
(use joy)
(route :get "/posts" :index)
(route :get "/posts/new" :new)
(route :post "/posts" :create)
(def body
(body :posts
(validates [:title :body] :required true)
(permit :title :body)))
(defn index [request]
(let [posts (db/from :posts)]
[:ul
(foreach [p posts]
[:li
[:h1 (p :title)]
[:p (p :body)]])]))
(defn new [request &opt errors]
(let [post (body request)]
[:form {:method :post :action "/posts"}
[:input {:type "text" :name "name" :value (post :name)}]
[:div
(errors :name)]
[:textarea {:name "body"}
(post :body)]
[:div
(errors :body)]
[:input {:type "submit" :value "Save"}]]))
(defn create [request]
(let [post (-> (body request)
(db/save))]
(if (saved? post)
(redirect-to :home)
(new request (errors post)))))