gudu
所属分类:collect
开发工具:Clojure
文件大小:0KB
下载次数:0
上传日期:2013-04-15 13:10:14
上 传 者:
sh-1993
说明: gudu:“Generate URL,Degenerate URL”——一个用于环网应用程序的clojure路由库,
(gudu: "Generate URL, Degenerate URL" - a clojure routing library for ring web apps,)
文件列表:
TODO.org (2151, 2023-12-11)
dev/ (0, 2023-12-11)
dev/scratch/ (0, 2023-12-11)
dev/scratch/scratch.clj (1307, 2023-12-11)
project.clj (579, 2023-12-11)
src/ (0, 2023-12-11)
src/gudu/ (0, 2023-12-11)
src/gudu/core.cljc (1014, 2023-12-11)
src/gudu/middleware.cljc (700, 2023-12-11)
src/gudu/segment.cljc (4276, 2023-12-11)
test/ (0, 2023-12-11)
test/gudu/ (0, 2023-12-11)
test/gudu/core_test.clj (3348, 2023-12-11)
# gudu
*"Generate URL, Degenerate URL"*
A bi-directional routing and URL generation library, where routes are configured as simple Clojure data structures.
Routes are defined as a data structure that is used at runtime to route requests and construct URLs. As the routes are
just a data structure they can be easily inspected by other functions to produce related data, e.g. navigation,
breadcrumbs.
## Usage
```clojure
(require '[gudu.core :as gd]
'[gudu.segment :as gds]
'[gudu.middleware :as gdm])
(def my-routes
{:home gds/root
:blog ["blog" {:latest gds/root
:post [gds/string]}]})
;; URL Generation
(def gu (gd/gu my-routes))
(gu :home) ;; => "/"
(gu :blog) ;; => "/blog"
(gu :blog :post "great-post") ;; => "/blog/great-post"
;; URL Degeneration
(def du (gd/du my-routes))
(du "/") ;; => [:home]
(du "/blog") ;; => [:blog :latest]
(du "/blog/another-post") ;; => [:blog :post "another-post"]
;; du is normally accessed indirectly via the gudu ring middleware
(defn get-handler [route]
;; ... return handler function based on route ...
(case (first route)
:home (fn [req] {:handler :home :uri (:uri req) :route route})
:blog (fn [req] {:handler :blog :uri (:uri req) :route route})))
(def app
(-> (gdm/router get-handler (fn [_req] {:handler :404}))
(gdm/wrap-route my-routes)))
(app {:uri "/"}) ;; {:handler :home, :uri "/", :route [:home]}
(app {:uri "/blog"}) ;; {:handler :blog, :uri "/blog", :route [:blog :latest]}
(app {:uri "/blog/3"}) ;; {:handler :blog, :uri "/blog/post-3", :route [:blog :post "3"]}
(app {:uri "/404"}) ;; {:handler :404}
```
## Documentation
* [API Docs](http://thatismatt.github.io/gudu/doc/)
## Examples
See the [gudu-examples](https://github.com/thatismatt/gudu-examples) project, in particular take a look at
[blog.clj](https://github.com/thatismatt/gudu-examples/blob/master/src/gudu_examples/blog.clj).
## License
Copyright 2013 Matt Lee
Distributed under the Eclipse Public License, the same as Clojure.
近期下载者:
相关文件:
收藏者: