Permalink
Please sign in to comment.
Browse files
Pull back on ring.branch, needs some proving in other apps before bei…
…ng merged into Ring core
- Loading branch information...
Showing
with
0 additions
and 41 deletions.
- +0 −1 README.textile
- +0 −24 src/ring/branch.clj
- +0 −15 test/ring/branch_test.clj
- +0 −1 test/run.clj
1
README.textile
24
src/ring/branch.clj
| @@ -1,24 +0,0 @@ | ||
| -(ns ring.branch) | ||
| - | ||
| -(defn wrap | ||
| - "Returns an app that proxies to one of several possible backing apps depending | ||
| - on the beginning of the request uri. | ||
| - Should be passed an odd number of arguments - the inital pairs of arguments | ||
| - indicate the branching conditions and corresponding apps, and the last | ||
| - argument the fallback app that will be invoked if none of the branching | ||
| - conditions are met: | ||
| - | ||
| - (wrap [\"/javascripts\" \"stylesheets\"] static-app | ||
| - [\"/blog\"] blog-app | ||
| - dynamic-app)" | ||
| - [& branching] | ||
| - (let [fallback (last branching) | ||
| - branch-logic | ||
| - (map (fn [[prefixes branch]] | ||
| - (fn [req] | ||
| - (let [uri (:uri req)] | ||
| - (if (some #(.startsWith uri %) prefixes) (branch req))))) | ||
| - (partition 2 branching))] | ||
| - (fn [req] | ||
| - (or (some #(% req) branch-logic) | ||
| - (fallback req))))) |
15
test/ring/branch_test.clj
| @@ -1,15 +0,0 @@ | ||
| -(ns ring.branch-test | ||
| - (:use clj-unit.core ring.branch)) | ||
| - | ||
| -(def wrapped | ||
| - (wrap ["/javascripts" "/stylesheets"] (fn [req] [req :static]) | ||
| - ["/blog"] (fn [req] [req :blog]) | ||
| - (fn [req] [req :dynamic]))) | ||
| - | ||
| -(deftest "wrap" | ||
| - (let [req {:uri "/stylesheets"}] | ||
| - (assert= [req :static] (wrapped req))) | ||
| - (let [req {:uri "/blog/foo"}] | ||
| - (assert= [req :blog] (wrapped req))) | ||
| - (let [req {:uri "/foo/blog"}] | ||
| - (assert= [req :dynamic] (wrapped req)))) |
1
test/run.clj
0 comments on commit
eae70f9