cripslock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 104c2d2b296de6f813e2cf54029aeb40f73ab546
parent 41a06422056e9f59e231adf5c417815312bebae5
Author: Daniel Barlow <dan@telent.net>
Date:   Sat,  9 Aug 2025 13:31:57 +0100

rename handlers as route-matchers

* they don't handle the request, they just return a specification
of the route.

Diffstat:
Mmain.fnl | 28++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/main.fnl b/main.fnl @@ -14,13 +14,13 @@ (local { : view } (require :fennel)) -(fn route-request [method path handlers] +(fn route-request [method path matchers] (accumulate [matched nil - _ pred (ipairs handlers) + _ pred (ipairs matchers) &until matched] (pred method path))) -(local handlers +(local route-matchers [ #(if (= $2 "/") [ :home { :limit 5 } ]) #(if (= $2 "/refresh") [ :refresh {} ]) @@ -46,31 +46,31 @@ ]) (define-tests :route-request - (expect= (route-request :get "/" handlers) + (expect= (route-request :get "/" route-matchers) [:home {:limit 5}]) - (expect= (route-request :get "/pagename" handlers) + (expect= (route-request :get "/pagename" route-matchers) [ :show { :slug "pagename" } ]) - (expect= (route-request :get "/2004/7/" handlers) + (expect= (route-request :get "/2004/7/" route-matchers) [ :month {:year 2004 :month 7 } ]) - (expect= (route-request :get "/static/cripslock.png" handlers) + (expect= (route-request :get "/static/cripslock.png" route-matchers) [ :static {:path "/static/cripslock.png" } ]) - (expect= (route-request :get "/static/README" handlers) + (expect= (route-request :get "/static/README" route-matchers) [ :static {:path "/static/README" } ]) - (expect= (route-request :get "/foo/static/README" handlers) nil) - (expect= (route-request :get "foo/static/README" handlers) nil) + (expect= (route-request :get "/foo/static/README" route-matchers) nil) + (expect= (route-request :get "foo/static/README" route-matchers) nil) - (expect= (route-request :get "/topic/cripslock" handlers) + (expect= (route-request :get "/topic/cripslock" route-matchers) [ :topic {:slug "cripslock" } ]) - (expect= (route-request :get "/topic/cripslock" handlers) + (expect= (route-request :get "/topic/cripslock" route-matchers) [ :topic {:slug "cripslock" } ]) - (expect= (route-request :get "/topic/cripslock?order=date_ascending" handlers) + (expect= (route-request :get "/topic/cripslock?order=date_ascending" route-matchers) [ :topic {:slug "cripslock" :order { :date :ascending }} ]) ) @@ -321,7 +321,7 @@ href=\"https://axillae.telent.net/\">@dan@axillae.telent.net</a> (let [req-headers (assert (stream:get_headers)) path (req-headers:get ":path") method (req-headers:get ":method") - route (route-request method path handlers)] + route (route-request method path route-matchers)] (server.log-request req-headers stream) (if route (dispatch route stream collection)