Refactor
This commit is contained in:
parent
bc01c7b5c7
commit
82d05f436a
1 changed files with 20 additions and 16 deletions
|
@ -21,18 +21,18 @@
|
||||||
(defun format-url (url)
|
(defun format-url (url)
|
||||||
(replace-dynamic-annotation (remove-index url)))
|
(replace-dynamic-annotation (remove-index url)))
|
||||||
|
|
||||||
(defun pathname->url (pathname dir system)
|
(defun pathname->url (pathname dir-namestring)
|
||||||
(format-url
|
(format-url
|
||||||
(re:regex-replace (namestring (asdf:system-relative-pathname system dir))
|
(re:regex-replace dir-namestring
|
||||||
(remove-file-type (namestring pathname))
|
(remove-file-type (namestring pathname))
|
||||||
"")))
|
"")))
|
||||||
|
|
||||||
(defun pathname->package (pathname system system-pathname)
|
(defun pathname->package (pathname system-path-namestring system-prefix)
|
||||||
(alx:make-keyword
|
(alx:make-keyword
|
||||||
(string-upcase
|
(string-upcase
|
||||||
(re:regex-replace (namestring system-pathname)
|
(re:regex-replace system-path-namestring
|
||||||
(remove-file-type (namestring pathname))
|
(remove-file-type (namestring pathname))
|
||||||
(concatenate 'string system "/")))))
|
system-prefix))))
|
||||||
|
|
||||||
(defun dir->pathnames (dir)
|
(defun dir->pathnames (dir)
|
||||||
(directory (concatenate 'string
|
(directory (concatenate 'string
|
||||||
|
@ -40,23 +40,27 @@
|
||||||
"/**/*.lisp")))
|
"/**/*.lisp")))
|
||||||
|
|
||||||
(defun dir->urls (dir system)
|
(defun dir->urls (dir system)
|
||||||
|
(let ((dir-namestring (namestring
|
||||||
|
(asdf:system-relative-pathname system dir))))
|
||||||
(mapcar (lambda (pathname)
|
(mapcar (lambda (pathname)
|
||||||
(pathname->url pathname dir system))
|
(pathname->url pathname dir-namestring))
|
||||||
(dir->pathnames dir)))
|
(dir->pathnames dir))))
|
||||||
|
|
||||||
(defun dir->packages (dir system system-pathname)
|
(defun dir->packages (dir system)
|
||||||
|
(let ((system-path-namestring (namestring
|
||||||
|
(asdf/component:component-relative-pathname
|
||||||
|
(asdf/find-system:find-system system))))
|
||||||
|
(system-prefix (concatenate 'string system "/")))
|
||||||
(mapcar (lambda (pathname)
|
(mapcar (lambda (pathname)
|
||||||
(pathname->package pathname system system-pathname))
|
(pathname->package pathname system-path-namestring system-prefix))
|
||||||
(dir->pathnames dir)))
|
(dir->pathnames dir))))
|
||||||
|
|
||||||
(defparameter *http-request-methods*
|
(defparameter *http-request-methods*
|
||||||
'(:GET :HEAD :POST :PUT :DELETE :CONNECT :OPTIONS :PATCH))
|
'(:GET :HEAD :POST :PUT :DELETE :CONNECT :OPTIONS :PATCH))
|
||||||
|
|
||||||
(defun enable-file-based-routing (app &key directory system)
|
(defun enable-file-based-routing (app &key directory system)
|
||||||
(let* ((system-pathname (asdf/component:component-relative-pathname
|
(let ((urls (dir->urls directory system))
|
||||||
(asdf/find-system:find-system system)))
|
(packages (dir->packages directory system)))
|
||||||
(urls (dir->urls directory system))
|
|
||||||
(packages (dir->packages directory system system-pathname)))
|
|
||||||
(ql:quickload packages)
|
(ql:quickload packages)
|
||||||
(loop
|
(loop
|
||||||
:for url :in urls
|
:for url :in urls
|
||||||
|
|
Loading…
Reference in a new issue