Skip to content

Commit

Permalink
Version 1.1: breaking change on jow nested routes is handled
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrand committed Oct 6, 2011
1 parent c7d445a commit 3e13067
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGES
@@ -0,0 +1,2 @@
1.1.0
:uri is not altered anymore by nested routes. :path-info holds the remaining path..
13 changes: 8 additions & 5 deletions pom.xml
Expand Up @@ -3,15 +3,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.cgrand</groupId>
<artifactId>moustache</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<name>moustache</name>
<description>a micro web framework/internal DSL to wire Ring handlers and middlewares</description>
<url>http://github.com/cgrand/moustache/</url>
<scm>
<connection>scm:git:git://github.com/cgrand/moustache.git</connection>
<developerConnection>scm:git:ssh://git@github.com/cgrand/moustache.git</developerConnection>
<tag>c2a8adef899f08b0847b1e7feb9d2367efdbbbf7</tag>
<url>https://github.com/cgrand/moustache</url>
<tag>c7d445adaa233d3840b95d23716a7433a5648c96</tag>
</scm>
<build>
<sourceDirectory>src</sourceDirectory>
Expand Down Expand Up @@ -56,6 +53,12 @@
<artifactId>ring-core</artifactId>
<version>[0.2.0,)</version>
</dependency>
<dependency>
<groupId>ring</groupId>
<artifactId>ring</artifactId>
<version>[0.2.0,)</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Expand Down
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject net.cgrand/moustache "1.0.0"
(defproject net.cgrand/moustache "1.1.0"
:description "a micro web framework/internal DSL to wire Ring handlers and middlewares"
:url "http://github.com/cgrand/moustache/"
:dependencies [[org.clojure/clojure "[1.1.0,)"]
Expand Down
20 changes: 15 additions & 5 deletions src/net/cgrand/moustache.clj
Expand Up @@ -14,11 +14,21 @@

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn ^String path-info [req] (or (:path-info req) (:uri req)))

(defn- segments [^String path]
(rest (map #(java.net.URLDecoder/decode % "UTF-8") (.split path "/" -1))))

(defn uri-segments
"Splits the uri of the given request map around / and decode segments."
[{:keys [#^String uri]}]
(rest (map #(java.net.URLDecoder/decode % "UTF-8") (.split uri "/" -1))))

[req]
(segments (:uri req)))

(defn path-info-segments
"Splits the path-info of the given request map around / and decode segments."
[req]
(segments (path-info req)))

(defn uri
"Turns a seq of decoded segment into an uri."
[segments]
Expand Down Expand Up @@ -97,7 +107,7 @@
simple-fixed-route)
args (if tail-binding (conj args tail-binding) args)
handler (if (= tail-binding etc-sym)
`(alter-request ~handler assoc :uri (uri ~etc-sym))
`(alter-request ~handler assoc :path-info (uri ~etc-sym))
handler)
emit-validator (fn [body validator] `(when-let ~validator ~body))]
`(when-let [~args (match-route ~segments '~simple-route)]
Expand All @@ -115,7 +125,7 @@
`(when-let [handler# ~(compile-route segments route+form)]
(handler# ~req)))]
`(fn [~req]
(let [~segments (uri-segments ~req)]
(let [~segments (path-info-segments ~req)]
(or ~@(map emit-match routes+forms))))))

(defn- method-not-allowed-form [allowed-methods]
Expand Down

0 comments on commit 3e13067

Please sign in to comment.