Skip to content

Commit

Permalink
Work in progress 0.2.4-SNAPSHOT: adding verb support to routes
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Aug 20, 2013
1 parent e7295fc commit 482ad46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject framework-one "0.2.3"
(defproject framework-one "0.2.4-SNAPSHOT"
:description "A lightweight, convention-based MVC web framework."
:url "https://github.com/framework-one/fw1-clj/"
:license {:name "Eclipse Public License"
Expand Down
24 changes: 15 additions & 9 deletions src/framework/one.clj
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,17 @@
(rest (.split req "/")))

(defn- compile-route [req]
(map (fn [part]
(if (.startsWith part ":")
(keyword (.substring part 1))
part))
(parts req)))
(let [verb? (.startsWith req "$")
verb (if verb?
(cond (.startsWith req "$GET") :get
(.startsWith req "$POST") :post
:else :any))]
[verb
(map (fn [part]
(if (.startsWith part ":")
(keyword (.substring part 1))
part))
(parts req))]))

(defn- match-part [p r]
(cond
Expand All @@ -124,7 +130,7 @@
part))
route) tail))

(defn- matches-route [compiled-url compiled-route]
(defn- matches-route [compiled-url [verb compiled-route]]
(if (empty? compiled-route)
[::empty]
(take-while identity
Expand All @@ -135,10 +141,10 @@
(defn- pre-compile-routes [routes]
(let [all-routes (apply concat routes)]
[(map compile-route (map first all-routes))
(map compile-route (map second all-routes))]))
(map (comp second compile-route) (map second all-routes))]))

(defn- process-routes [routes new-routes url]
(let [url (compile-route url)
(let [[_ url] (compile-route url)
matching (map (partial matches-route url) routes)
no-matches (count (take-while empty? matching))
matches (first (drop no-matches matching))
Expand Down Expand Up @@ -342,7 +348,7 @@
:reload-application-on-every-request false
:template :enlive ; or :selmer
:suffix "html" ; views / layouts would be .html
:version "0.2.3"}
:version "0.2.4-SNAPSHOT"}
my-config (framework-defaults (merge defaults (apply hash-map app-config)))]
(when (= :selmer (:template my-config))
(selmer.filters/add-filter! :empty? empty?))
Expand Down

0 comments on commit 482ad46

Please sign in to comment.