Skip to content

Instantly share code, notes, and snippets.

@PuercoPop
Created April 27, 2018 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PuercoPop/fb40d1cb8025272c3ba2437e71f26a3a to your computer and use it in GitHub Desktop.
Save PuercoPop/fb40d1cb8025272c3ba2437e71f26a3a to your computer and use it in GitHub Desktop.
(defmacro define-regexp-route (name (url-regexp &rest capture-names) &body body)
(multiple-value-bind (body declarations documentation)
(parse-body body :documentation t)
`(progn
(defun ,name ()
,@(when documentation
(list documentation))
,@declarations
(when *debug*
(format *trace-output* "=== Calling ~A Handler ===" ',name))
(match (script-name *request*)
((ppcre ,url-regexp ,@capture-names)
,@body)))
(push (create-regex-dispatcher ,url-regexp ',name)
*dispatch-table*))))
(define-regexp-route display-entry ("^/entry/(.*?)/$" entry-title)
"Display the contents of the ENTRY."
(when-let ((entry (find-entry-by-title entry-title)))
(show-entry entry)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment