Skip to content

Commit

Permalink
Merge pull request #13 from ellipsoid/patch-3
Browse files Browse the repository at this point in the history
Separated code blocks
  • Loading branch information
bmaddy committed May 15, 2014
2 parents 073aa8f + 29b9333 commit cc68b67
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions outline/web-app-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ Add a new item in ```:require```

Add a new route for rendering a form that calls a function to make the page
```clojure
; add a function (Note: this must be before the defroutes section
; add a function (Note: this must be before the defroutes section)
(defn who []
(page/html5
(form/form-to [:post "/iam"]
[:label "Who are you?"]
(form/text-field "name")
(form/submit-button "Submit"))))
```

```clojure
; add a route to the defroutes section
(GET "/who" [] (who))
```
Expand All @@ -114,7 +116,9 @@ View your page at http://localhost:3000/who. If you submit the form, you'll get
(defn iam [params]
(page/html5
[:div "You are " (:name params) "!"]))
```

```clojure
; add a route to handle the request
(POST "/iam" {params :params} (iam params))
```
Expand Down Expand Up @@ -180,9 +184,6 @@ We can look at our params map by printing it out. Change the ```iam``` function
## Post a name and message

```clojure
; change our default route to this (be sure to not leave the old version around - it will cause problems)
(ANY "/" {params :params} (chat (:name params) (:msg params)))

; add a chat function
(defn chat [name msg]
(page/html5
Expand All @@ -192,6 +193,11 @@ We can look at our params map by printing it out. Change the ```iam``` function
(form/submit-button "Submit"))))
```

```clojure
; change our default route to this (be sure to not leave the old version around - it will cause problems)
(ANY "/" {params :params} (chat (:name params) (:msg params)))
```

View your app and submit a name and a message. Notice that the name is still there when you
submit the page.

Expand Down Expand Up @@ -233,7 +239,9 @@ Add some code to make Bootstrap work in your ```src/chat/handler.clj``` file:
; Add these two lines to use Bootstrap middleware. Put them at the top after the hiccup.form line:
[hiccup.bootstrap.middleware :as middleware]
[hiccup.bootstrap.page :as boot]
```

```clojure
; modify our chat function to use Bootstrap
(defn chat [name msg]
(when-not (empty? msg)
Expand All @@ -250,7 +258,9 @@ Add some code to make Bootstrap work in your ```src/chat/handler.clj``` file:
[:post "/"]
[:div "Name:" (form/text-field "name" name) " Message:" (form/text-field "msg")]
(form/submit-button "Submit"))])) ;changed
```

```clojure
; add the Bootstrap specific routes by wrapping our routes with them
(def app
(handler/site (middleware/wrap-bootstrap-resources app-routes)))
Expand Down

0 comments on commit cc68b67

Please sign in to comment.