Skip to content
This repository
Browse code

fixed Clack.App.Route. it seems it has been completely broken, not only

on CLISP. I fixed it, but it has lost the backward compatibility.
  • Loading branch information...
commit e0ffb146323a842d08466a55a2d5b83261c19877 1 parent 9630f76
Eitarow Fukamachi authored March 20, 2012
2  clack-app-route.asd
@@ -18,7 +18,7 @@
18 18
 (in-package :clack-app-route-asd)
19 19
 
20 20
 (defsystem clack-app-route
21  
-  :version "11.09"
  21
+  :version "12.03"
22 22
   :author "Eitarow Fukamachi"
23 23
   :license "LLGPL"
24 24
   :depends-on (:clack
44  src/contrib/app/route.lisp
@@ -68,15 +68,14 @@ Example:
68 68
          (or ,@(loop for (method path form) in routes
69 69
                      collect `(when (string= ,request-method ',method)
70 70
                                 (multiple-value-bind (,matched ,params)
71  
-                                    (match (make-url-rule ,path) ,request-path)
  71
+                                    (match (make-url-rule ,path :method ,request-method) ,request-method ,request-path)
72 72
                                   (declare (ignorable ,params))
73 73
                                   (when ,matched
74  
-                                    ,(if params
75  
-                                         `(let (,@(loop for (k v) on params by #'cddr
76  
-                                                        collect (list (intern (string k)) v)))
77  
-                                            (declare (ignorable ,@(loop for k in params by #'cddr collect k)))
78  
-                                            (call ,form ,env))
79  
-                                         `(call ,form ,env))))))
  74
+                                    (if ,params
  75
+                                        (call ,form
  76
+                                              (append ,env
  77
+                                                      (list :route.parameters ,params)))
  78
+                                        (call ,form ,env))))))
80 79
              ,(if otherwise
81 80
                   `(call ,(cadr otherwise) ,env)
82 81
                   '(list 404 nil nil)))))))
@@ -94,7 +93,7 @@ Clack.App.Route - URL dispatcher.
94 93
             :clack.app.route))
95 94
     (in-package :clack-sample)
96 95
     
97  
-    (defroutes app (env)
  96
+    (defroutes app
98 97
       (GET \"/\" #'index)
99 98
       (GET \"/login\" #'login)
100 99
       (POST \"/login\" #'authorize)
@@ -104,7 +103,34 @@ Clack.App.Route - URL dispatcher.
104 103
 "
105 104
 
106 105
 @doc:DESCRIPTION "
107  
-Clack.App.Route provides an URL based dispacher, inspired by Ruby's Sinatra.
  106
+Clack.App.Route provides an URL based dispacher, inspired by Ruby's Sinatra. Each routing rules contains three elements, REQUEST-METHOD, URI rule and Clack Application.
  107
+
  108
+Clack Application is a function or Clack.Component which takes exact one argument. It is a property list represents Environment.
  109
+
  110
+    (defroutes app
  111
+      (GET \"/\"
  112
+           (lambda (env)
  113
+             '(200
  114
+               (:content-type \"text/plain\")
  115
+               (\"Hello. This is an index page.\")))))
  116
+
  117
+Routing URI rules are also allowed to contain named parameters or wild cards. Then, Clack.App.Route adds `:route.parameters` to `env`.
  118
+
  119
+    (defroutes app
  120
+      (GET \"/member/:id\"
  121
+           (lambda (env)
  122
+             (destructuring-bind (&key id &allow-other-keys)
  123
+                 (getf env :route.parameters)
  124
+               `(200
  125
+                 (:content-type \"text/plain\")
  126
+                 (,(format nil \"Your member ID is ~D\" id))))))
  127
+      (GET \"/say/*/to/*\"
  128
+           (lambda (env)
  129
+             (destructuring-bind (who what)
  130
+                 (getf (getf env :route.parameters) :splat)
  131
+               `(200
  132
+                 (:content-type \"text/plain\")
  133
+                 (,(format nil \"You're saying ~A to ~A\" what who)))))))
108 134
 
109 135
 This package is using Clack.Util.Route to parse rule strings.
110 136
 

0 notes on commit e0ffb14

Please sign in to comment.
Something went wrong with that request. Please try again.