Clack.Util.Route - Class for Sinatra-compatible URL rule.

SYNOPSIS

(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" 

DESCRIPTION

Clack.Util.Route provides a Sinatra-compatible routing class.

Named Parameter

(match (make-url-rule "/hello/:name") "/hello/fukamachi")  
;=> "/hello/fukamachi"  
    (:NAME "fukamachi") 

Wildcard Parameter

(match (make-url-rule "/say/*/to/*") "/say/hello/to/world")  
;=> "/say/hello/to/world"  
    (:SPLAT ("hello" "world")) 

Optional Parameter

(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) 

Regular Expression

(match (make-url-rule "/hello([\w]+)" :regexp t)  
       "/hello/world")  
;=> "/hello/world"  
    (:CAPTURES ("world")) 

AUTHOR

Note: compile-rule was originally written by Tomohiro Matsuyama as parse-url-rule in Clack.App.Route.

EXTERNAL SYMBOLS