(defvar *url-rule* (make-url-rule "/hello/:name"))
(match *url-rule* "/hello/fukamachi")
;=> (NAME "fukamachi")
(match *url-rule* "/bye/fukamachi")
;=> NIL
(url-for *url-rule* '(:name "fukamachi"))
;=> "/hello/fukamachi" Clack.Util.Route provides a Sinatra-compatible routing class.
(match (make-url-rule "/hello/:name") "/hello/fukamachi")
;=> "/hello/fukamachi"
(:NAME "fukamachi") (match (make-url-rule "/say/*/to/*") "/say/hello/to/world")
;=> "/say/hello/to/world"
(:SPLAT ("hello" "world")) (match (make-url-rule "/?:foo?/?:bar?") "/hello/world")
;=> "/hello/world"
(:FOO "hello" :BAR "world")
(match (make-url-rule "/?:foo?/?:bar?") "/hello")
;=> "/hello"
(:FOO "hello" :BAR NIL)
(match (make-url-rule "/?:foo?/?:bar?") "/")
;=> "/"
(:FOO NIL :BAR NIL) (match (make-url-rule "/hello([\w]+)" :regexp t)
"/hello/world")
;=> "/hello/world"
(:CAPTURES ("world")) Note: compile-rule was originally written by Tomohiro Matsuyama as parse-url-rule in Clack.App.Route.
Construct `` and return it. You must always use this function when you need ` `.
Check whether the `url-string` matches to `this`. This method is for ``. Return two values, matched URL and Rule parameters as a plist. If the url-rule is containing Wildcard rules, they will be collected as :splat. Example: (match (make-url-rule "/hello/:name") :GET "/hello/fukamachi") ;=> "/hello/fukamachi" (:NAME "fukamachi") (match (make-url-rule "/say/*/to/*") :ANY "/say/hello/to/world") ;=> "/say/hello/to/world" (:SPLAT ("hello" "world"))
Check whether the `url-string` matches to `this`. This method is for ``. Return two values, matched URL and Rule parameters as a plist. Captured strings in `url-string` are collected as :captures. Example: (match (make-url-rule "/hello([\w]+)" :regexp t) "/hello/world") ;=> "/hello/world" (:CAPTURES ("world"))
Return an URL from a rule and parameters.
Example:
(url-for (make-url-rule "/hello/:name")
'(:name "fukamachi"))
;=> "/hello/fukamachi"
Return an URL from a rule and parameters.
Example:
(url-for (make-url-rule "/hello/:name")
'(:name "fukamachi"))
;=> "/hello/fukamachi"