Skip to content

Commit a075a87

Browse files
committed
Add title/description meta. Diff controller example
1 parent 911d178 commit a075a87

File tree

5 files changed

+69
-47
lines changed

5 files changed

+69
-47
lines changed

css/tailwind.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/controller.janet

+31-21
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
11
(use joy)
22

33

4-
(route :get "/todos/new" :new)
5-
(route :post "/todos" :create)
4+
(route :get "/posts" :index)
5+
(route :get "/posts/new" :new)
6+
(route :post "/posts" :create)
67

78

8-
(def todo
9-
(body :todos
10-
(validates :name :required true)
11-
(permit :name :finished)))
9+
(def body
10+
(body :posts
11+
(validates [:title :body] :required true)
12+
(permit :title :body)))
1213

1314

14-
(defn new [request &opt errors]
15-
(default errors {})
15+
(defn index [request]
16+
(let [posts (db/from :posts)]
17+
18+
[:ul
19+
(foreach [p posts]
20+
[:li
21+
[:h1 (p :title)]
22+
[:p (p :body)]])]))
1623

17-
(let [todo (todo request)]
1824

19-
(form-for [request :create]
20-
(text-field todo :name)
21-
[:div (errors :name)]
25+
(defn new [request &opt errors]
26+
(let [post (body request)]
27+
28+
[:form {:method :post :action "/posts"}
29+
[:input {:type "text" :name "name" :value (post :name)}]
30+
[:div
31+
(errors :name)]
2232

23-
(label-for :finished
24-
# generates hidden input for false/zero values
25-
(checkbox-field todo :finished)
26-
[:span " Finished"])
27-
[:div (errors :finished)]
33+
[:textarea {:name "body"}
34+
(post :body)]
35+
[:div
36+
(errors :body)]
2837

29-
(submit "Save"))))
38+
[:input {:type "submit" :value "Save"}]]))
3039

3140

3241
(defn create [request]
33-
(let [todo (-> request todo db/save)]
42+
(let [post (-> (body request)
43+
(db/save))]
3444

35-
(if (saved? todo)
45+
(if (saved? post)
3646
(redirect-to :home)
37-
(new request (errors todo)))))
47+
(new request (errors post)))))

index.html

+32-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE HTML><html dir="ltr" lang="en"><head><meta charset="utf-8" /><meta content="width=device-width, initial-scale=1" name="viewport" /><title>Joy Framework</title><link rel="stylesheet" href="css/atom-one-light.css" /><link rel="stylesheet" href="css/tailwind.min.css" /><link rel="stylesheet" href="css/app.css" /><link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /></head><body><div class="lg:mt-10"><div class="container p-4 mx-auto"><div class="self-stretch flex-row lg:flex sm:block md:block lg:space-x-4"><div class="flex-1"><div class="flex flex-col self-stretch flex-auto space-y-2"><h1 class="text-5xl text-gray-800">Joy</h1><h2 class="text-3xl tracking-tight text-gray-800">A maximalist web framework for lisp aficionados</h2><h4 class="text-l text-gray-800">Use the <a href="https://janet-lang.org" class="text-indigo-500 underline">janet</a> programming language to build web apps faster with less code and very low memory usage.</h4><div class="mt-4"><a href="https://github.com/joy-framework/joy/blob/master/docs/introduction.md" class="inline-block my-6 px-5 py-3 rounded-lg bg-indigo-500 text-white shadow-lg hover:bg-indigo-700">Read the docs</a></div></div></div><div class="flex-1"><pre><code class="rounded-lg p-6 clojure">(import joy :prefix &quot;&quot;)
1+
<!DOCTYPE HTML><html dir="ltr" lang="en"><head><meta charset="utf-8" /><meta content="width=device-width, initial-scale=1" name="viewport" /><meta content="Joy Web Framework" name="title" /><meta content="The full stack janet web framework" name="description" /><title>Joy Framework</title><link rel="stylesheet" href="css/atom-one-light.css" /><link rel="stylesheet" href="css/tailwind.min.css" /><link rel="stylesheet" href="css/app.css" /><link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /></head><body><div class="lg:mt-10"><div class="container p-4 mx-auto"><div class="self-stretch flex-row lg:flex sm:block md:block lg:space-x-4"><div class="flex-1"><div class="flex flex-col self-stretch flex-auto space-y-2"><h1 class="text-5xl text-gray-800">Joy</h1><h2 class="text-3xl tracking-tight text-gray-800">A maximalist web framework for lisp aficionados</h2><h4 class="text-l text-gray-800">Use the <a href="https://janet-lang.org" class="text-indigo-500 underline">janet</a> programming language to build web apps faster with less code and very low memory usage.</h4><div class="mt-4"><a href="https://github.com/joy-framework/joy/blob/master/docs/introduction.md" class="inline-block my-6 px-5 py-3 rounded-lg bg-indigo-500 text-white shadow-lg hover:bg-indigo-700">Read the docs</a></div></div></div><div class="flex-1"><pre><code class="rounded-lg p-6 clojure">(import joy :prefix &quot;&quot;)
22

33
(route :get &quot;&#x2F;&quot; :home)
44

@@ -33,38 +33,48 @@
3333
[h1 &quot;You found joy!&quot;]</code></pre><pre><code class="rounded-lg p-6 html">&lt;h1 class=&quot;text-2xl text-gray-400&quot;&gt;You found joy!&lt;&#x2F;h1&gt;</code></pre></div></div></div></div></div><div class="lg:mt-16"><div class="container p-4 mx-auto"><div class="flex flex-col self-stretch flex-auto space-y-16"><div class="lg:grid lg:grid-flow-col lg:grid-cols-2 gap-10"><div class="flex-1"><div class="flex flex-col self-stretch flex-auto space-y-4"><h3 class="text-2xl text-gray-800">Everything is a function</h3><div class="text-gray-800">Joy doesn&#x27;t uses objects or classes. Everything is a function that takes a request and outputs a response</div></div></div><div class="flex-1"><div class="flex flex-col self-stretch flex-auto space-y-4"><pre><code class="rounded-lg p-6 clojure">(use joy)
3434

3535

36-
(route :get &quot;&#x2F;todos&#x2F;new&quot; :new)
37-
(route :post &quot;&#x2F;todos&quot; :create)
36+
(route :get &quot;&#x2F;posts&quot; :index)
37+
(route :get &quot;&#x2F;posts&#x2F;new&quot; :new)
38+
(route :post &quot;&#x2F;posts&quot; :create)
3839

3940

40-
(def todo
41-
(body :todos
42-
(validates :name :required true)
43-
(permit :name :finished)))
41+
(def body
42+
(body :posts
43+
(validates [:title :body] :required true)
44+
(permit :title :body)))
4445

4546

46-
(defn new [request &amp;opt errors]
47-
(default errors {})
47+
(defn index [request]
48+
(let [posts (db&#x2F;from :posts)]
49+
50+
[:ul
51+
(foreach [p posts]
52+
[:li
53+
[:h1 (p :title)]
54+
[:p (p :body)]])]))
4855

49-
(let [todo (todo request)]
5056

51-
(form-for [request :create]
52-
(text-field todo :name)
53-
[:div (errors :name)]
57+
(defn new [request &amp;opt errors]
58+
(let [post (body request)]
59+
60+
[:form {:method :post :action &quot;&#x2F;posts&quot;}
61+
[:input {:type &quot;text&quot; :name &quot;name&quot; :value (post :name)}]
62+
[:div
63+
(errors :name)]
5464

55-
(label-for :finished
56-
# generates hidden input for false&#x2F;zero values
57-
(checkbox-field todo :finished)
58-
[:span &quot; Finished&quot;])
59-
[:div (errors :finished)]
65+
[:textarea {:name &quot;body&quot;}
66+
(post :body)]
67+
[:div
68+
(errors :body)]
6069

61-
(submit &quot;Save&quot;))))
70+
[:input {:type &quot;submit&quot; :value &quot;Save&quot;}]]))
6271

6372

6473
(defn create [request]
65-
(let [todo (-&gt; request todo db&#x2F;save)]
74+
(let [post (-&gt; (body request)
75+
(db&#x2F;save))]
6676

67-
(if (saved? todo)
77+
(if (saved? post)
6878
(redirect-to :home)
69-
(new request (errors todo)))))
79+
(new request (errors post)))))
7080
</code></pre></div></div></div></div></div></div><script async="" src="//gc.zgo.at/count.js" data-goatcounter="https://joyframework.goatcounter.com/count"></script><script src="js/highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></body></html>

project.janet

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
:url "https://joyframework.com"
88
:repo "https://github.com/joy-framework/joy-framework.github.io")
99

10-
(phony "watch" []
10+
(phony "rebuild" []
1111
(os/shell "find . -name '*.janet' | entr -r speakeasy"))
1212

13-
(phony "tailwind" []
14-
(os/shell "find . -name 'src/html.janet' | entr -r gust -o css"))
13+
(phony "gust" []
14+
(os/shell "find . -name '*.html' | entr -r gust -o css"))
1515

0 commit comments

Comments
 (0)