aboutsummaryrefslogtreecommitdiff
path: root/weeb/router.scm
diff options
context:
space:
mode:
Diffstat (limited to 'weeb/router.scm')
-rw-r--r--weeb/router.scm38
1 files changed, 38 insertions, 0 deletions
diff --git a/weeb/router.scm b/weeb/router.scm
new file mode 100644
index 0000000..8c4b502
--- /dev/null
+++ b/weeb/router.scm
@@ -0,0 +1,38 @@
+;;; Weeb --- Web microframework for GNU Guile
+;;; Copyright © 2026 Jakob Kreuze <zerodaysfordays@sdf.org>
+;;;
+;;; This file is part of Weeb.
+;;;
+;;; Weeb is free software: you can redistribute it and/or modify it
+;;; under the terms of the GNU Affero General Public License as
+;;; published by the Free Software Foundation, either version 3 of the
+;;; License, or (at your option) any later version.
+;;;
+;;; Weeb is distributed in the hope that it will be useful, but WITHOUT
+;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
+;;; Public License for more details.
+;;;
+;;; You should have received a copy of the GNU Affero General Public
+;;; License along with Weeb. If not, see <https://www.gnu.org/licenses/>.
+
+(define-module (weeb router)
+ #:use-module (ice-9 regex)
+ #:use-module (weeb struct)
+ #:export (define-router))
+
+(define (uri-template->regexp-string template)
+ ;; TODO: Assert that the first character is a slash.
+ (define trailing-slash? (string-match ".*/$" template))
+ (define components
+ (map (lambda (component)
+ (let ((variable-match (string-match ":(.*):" component)))
+ (if variable-match
+ (list (string->symbol (match:substring variable-match 1)) "([^/]+)")
+ (list #f component))))
+ (string-split (if trailing-slash?
+ (substring template 1 (- (string-length template) 1))
+ (substring template 1))
+ #\/)))
+ (values (string-append "/" (string-join (map cadr components) "/"))
+ (filter symbol? (map car components))))

© 2015 - 2026 Jakob L. Kreuze