Skip to content
Permalink
Browse files

Change site-routes layout docs

  • Loading branch information...
swlkr committed Mar 15, 2019
1 parent 15575c5 commit e4be3bb0ba6dca7e980264f2ebc3072f91b39990
Showing with 32 additions and 33 deletions.
  1. +2 −3 README.md
  2. +1 −2 docs/middleware.md
  3. +27 −26 docs/upgrading.md
  4. +2 −2 docs/views.md
@@ -184,12 +184,11 @@ One thing coast doesn't do yet is update the routes file, let's do that now:
```clojure
(ns routes)
(:require [coast]
[components])
(:require [coast]))
(def routes
(coast/routes
(coast/site-routes components/layout
(coast/site-routes :components/layout
[:get "/" :home/index]
[:resource :todo] ; add this line
@@ -81,7 +81,7 @@ Coast calls four functions on every route defined underneath `site-routes`:
```clojure
(def routes
(coast/routes
(coast/site-routes option-layout-fn
(coast/site-routes :option-layout-fn
[:get "/posts" :post/index]
[:post "/posts" :post/create]
[:404 :home/not-found]
@@ -96,7 +96,6 @@ Coast calls four functions on every route defined underneath `site-routes`:
#### `wrap-layout`
This function wraps any [hiccup](https://github.com/weavejester/hiccup) vector returned from functions that you write in the `function` you specify as the fist argument to `site-routes`.
#### `wrap-site-defaults`
This function wraps common website options, csrf protection, content-type headers, etc. from [ring's own defaults](https://github.com/ring-clojure/ring-defaults)
@@ -211,22 +211,23 @@ There was quite a bit of postgres specific code related to raise/rescue, that is
## Routing
Routing hasn't changed really, old routing code will still work and continue to work, there have only been syntactic improvements.
Routing has changed in a few ways, old routing code will still work and continue to work, but there have been some improvements surrounding nested vectors.
```clojure
(ns routes
(:require [coast]
[components]))
(:require [coast]))
(def routes
(coast/site-routes components/layout
[:get "/" :home/index]
[:get "/posts" :post/index]
[:get "/posts/:id" :post/view]
[:get "/posts/build" :post/build]
[:post "/posts" :post/create]
[:get "/posts/:id/edit" :post/edit]
[:post "/posts/:id/edit" :post/change]
[:post "/posts/:id/delete" :post/delete]
(coast/routes
(coast/site-routes :components/layout
[:get "/" :home/index]
[:get "/posts" :post/index]
[:get "/posts/:id" :post/view]
[:get "/posts/build" :post/build]
[:post "/posts" :post/create]
[:get "/posts/:id/edit" :post/edit]
[:post "/posts/:id/edit" :post/change]
[:post "/posts/:id/delete" :post/delete])))
```
Before you had to wrap all vectors in another vector, that's now optional, it makes things a little cleaner. Also multiple layout support per batch of routes is easier as well since you no longer have to pass layout in `app`.
@@ -236,22 +237,22 @@ Since the vector of vectors confusion is gone now, routes more naturally lend th
```clojure
(ns routes
(:require [coast]
[components]))
(:require [coast]))
(def routes
(coast/site-routes components/layout
[:resource :posts]
; is equal to all of the below routes
[:get "/posts" :post/index]
[:get "/posts/build" :post/build]
[:get "/posts/:id" :post/view]
[:post "/posts" :post/create]
[:get "/posts/:id/edit" :post/edit]
[:post "/posts/:id/edit" :post/change]
[:post "/posts/:id/delete" :post/delete]
(coast/routes
(coast/site-routes :components/layout
[:resource :posts]
; is equal to all of the below routes
[:get "/posts" :post/index]
[:get "/posts/build" :post/build]
[:get "/posts/:id" :post/view]
[:post "/posts" :post/create]
[:get "/posts/:id/edit" :post/edit]
[:post "/posts/:id/edit" :post/change]
[:post "/posts/:id/delete" :post/delete])))
```
## Views
@@ -286,11 +286,11 @@ Here's an example:
(def routes
(coast/routes
(coast/site-routes my-layout-function
(coast/site-routes :my-layout-function
[:get "/" :home/index]
[:resource :customer]
(coast/site-routes my-other-layout-function
(coast/site-routes :my-other-layout-function
[:get "/other-route" :other/route]))))
```

0 comments on commit e4be3bb

Please sign in to comment.
You can’t perform that action at this time.