diff --git a/qlfile b/qlfile index ac01704..5974204 100644 --- a/qlfile +++ b/qlfile @@ -6,4 +6,4 @@ ql lack ql clack ql cl-jingle git piccolo https://github.com/skyizwhite/piccolo.git -ql cl-ppcre +git ningle-fbr https://github.com/skyizwhite/ningle-fbr.git diff --git a/qlfile.lock b/qlfile.lock index 1a9052c..e672ec2 100644 --- a/qlfile.lock +++ b/qlfile.lock @@ -34,7 +34,7 @@ (:class qlot/source/git:source-git :initargs (:remote-url "https://github.com/skyizwhite/piccolo.git") :version "git-1b617f75393df820cb1ba0546ced07d2fb1d02c3")) -("cl-ppcre" . - (:class qlot/source/ql:source-ql - :initargs (:%version :latest) - :version "ql-2023-10-21")) +("ningle-fbr" . + (:class qlot/source/git:source-git + :initargs (:remote-url "https://github.com/skyizwhite/ningle-fbr.git") + :version "git-366f2d80516548f620822ef7b0ab511300774728")) diff --git a/src/app.lisp b/src/app.lisp index f319d9f..c307174 100644 --- a/src/app.lisp +++ b/src/app.lisp @@ -1,8 +1,8 @@ (uiop:define-package #:hp/app (:use #:cl) (:local-nicknames (#:jg #:jingle)) + (:local-nicknames (#:fbr #:ningle-fbr)) (:import-from #:lack) - (:local-nicknames (#:utils #:hp/utils/*)) (:export #:*app* #:update-routes)) (in-package #:hp/app) @@ -10,10 +10,10 @@ (defparameter *raw-app* (jg:make-app)) (defun update-routes () - (utils:enable-file-based-routing *raw-app* - :dir "src/routes" - :system "hp" - :system-pathname "src")) + (fbr:enable-file-based-routing *raw-app* + :dir "src/routes" + :system "hp" + :system-pathname "src")) (update-routes) diff --git a/src/utils/routes.lisp b/src/utils/routes.lisp deleted file mode 100644 index 54cb32e..0000000 --- a/src/utils/routes.lisp +++ /dev/null @@ -1,69 +0,0 @@ -(uiop:define-package #:hp/utils/routes - (:use #:cl) - (:local-nicknames (#:alx #:alexandria)) - (:local-nicknames (#:re #:cl-ppcre)) - (:local-nicknames (#:jg #:jingle)) - (:export #:enable-file-based-routing)) -(in-package #:hp/utils/routes) - -(defun remove-file-type (namestr) - (re:regex-replace ".lisp" namestr "")) - -(defun remove-index (url) - (if (string= url "/index") - "/" - (re:regex-replace "/index" url ""))) - -(defun replace-dynamic-annotation (url) - (re:regex-replace "=" url ":")) - -(defun format-url (url) - (replace-dynamic-annotation (remove-index url))) - -(defun pathname->url (pathname dir) - (format-url - (re:regex-replace (concatenate 'string - (namestring (uiop/os:getcwd)) - dir) - (remove-file-type (namestring pathname)) - ""))) - -(defun pathname->package (pathname system system-pathname) - (alx:make-keyword - (string-upcase - (re:regex-replace (concatenate 'string - (namestring (uiop/os:getcwd)) - system-pathname) - (remove-file-type (namestring pathname)) - system)))) - -(defun dir->pathnames (dir) - (directory (concatenate 'string - dir - "/**/*.lisp"))) - -(defun dir->urls (dir) - (mapcar (lambda (pathname) - (pathname->url pathname dir)) - (dir->pathnames dir))) - -(defun dir->packages (dir system system-pathname) - (mapcar (lambda (pathname) - (pathname->package pathname system system-pathname)) - (dir->pathnames dir))) - -(defparameter *http-request-methods* - '(:GET :HEAD :POST :PUT :DELETE :CONNECT :OPTIONS :PATCH)) - -(defun enable-file-based-routing (app &key dir system system-pathname) - (let ((urls (dir->urls dir)) - (packages (dir->packages dir system system-pathname))) - (ql:quickload packages) - (loop - :for url :in urls - :for pkg :in packages - :do (loop - :for method :in *http-request-methods* - :do (let ((handler (find-symbol (string (alx:symbolicate 'on- method)) pkg))) - (when handler - (setf (jg:route app url :method method) handler)))))))