我正在尝试为 hunchentoot 服务器在 common lisp 中编写类似于 ruby on rails 的路由文件,即
(route "/home" :controller home :action index)
示例控制器文件如下所示:
;;; controller file
(defun index ()
;; do something
)
(defun add (x)
;; do something
)
这样做的原因是将控制器与视图分开。
所以,我有以下功能:
(defun build-handler (controller action)
(intern (concatenate 'string (symbol-name controller) "-" (symbol-name action))))
(defun format-view-file (controller params)
(let ((fstring (read-from-view-file))) ; the view file must be named after the controller. the details are not shown here
(format nil fstring params)))
(defun get-action-arguments (f)
;; read the controller file
;; and find the action function
;; return a list of its arguments
;; something like this, in case f was "(defun bar (x) (1+ x))"
(car (cdr (cdr f))))
和宏:
(defmacro route (uri &key controller action)
(let ((var (build-handler controller action))
(params (get-action-arguments action)))
`(hunchentoot:define-easy-handler (,var :uri ,uri) ,params
(setf (hunchentoot:content-type*) "text/plain")
(format-view-file ,params))))
我的问题是我无法正确传递参数。参数应该如何在路由宏中?
或者,是否有更好的方法来完成此任务,或者是否有一个在 hunchentoot 之上工作的库(我找到了一些但不知道选择哪个,所以我开始编写自己的)。
非常感谢您!