Tuesday, August 25, 2009

Make the Not Found Path Optional

Currently you'll have to supply the not-found path for the app to work, this slows down the creation of the site, so we'll try to make it optional.

The idea is simple - since the package includes a not-found script, we should use that by default when it is not specified.

(define (*make-shp-handler path
#:default (default "index")
#:not-found (not-found #f)
#:required (required "required")
#:topfilter (topfilter #f)
#:chrome (chrome #f))
(make-shp-handler path
(if (not not-found)
(make-script (build-path (this-expression-source-directory) "example" "shp" "notfound") 0)

(init-script required path) topfilter chrome))

we'll also have to change the segment->path and segment->partial-path function to ensure make them play well with having a script struct as the value of not-found:

(define (not-found-path base)
(let ((not-found (shp-handler-not-found ($server))))
(if (script? not-found)
(script-path not-found)
(build-path base not-found))))

;; partially matching the path from the beginning of the path
(define (segments->partial-path segments)
(define (helper rest path default)
;; if we did not find any match return not-found
(cond ((null? rest)
(not-found-path (shp-handler-path ($server)))) ...)

(define (segments->path segments (partial? #t))
(not-found-path script)))))

So now if you decide not to specify the not-found script path, the code will still work.

No comments:

Post a Comment