Function: normalize-url-spec

Documentation

Converts defurlmap forms into internal representation to be processed by `make-urlmap'.

Source

(defun normalize-url-spec (url-spec)
  "Converts defurlmap forms into internal representation to be processed by `make-urlmap'."
  (let* ((handler-designator (third url-spec)) ;; a symbol or a form that returns function.
	 (handler (if (consp handler-designator)
		      handler-designator
		      `(symbol-function ',handler-designator)))
	 (url (ensure-prefix-slash-only (car url-spec)))) 
    (ecase (second url-spec)
      (:handler `(list :handler :url ,url :dispatch ,handler))
      (:wethod
       (let* ((discriminators (aif (nthcdr 3 url-spec)
				   (check-function-discriminators handler-designator it)
				   ;; when no specializers are specified, it means all are specified.
				   (get-function-discriminators handler-designator))))
	 `'(:wethod
	    :url ,url
	    :wethod-urls
	    ,(mapcar (curry #'^wethod-url-frag handler-designator)
		     discriminators)
	    :discriminators ,discriminators
	    :wethod-name ,handler-designator)))
      (:class-wethod
       (let ((discriminators (nthcdr 3 url-spec)))
	 `'(:class-wethod
	    :url ,url
	    :discriminators ,(mapcar (fn (d) (mapcar (curry #'list 'eql) d))
				     discriminators)
	    :wethod-urls
	    ,(mapcar
	      (fn (discriminator)
		;; make sure all the classes are defined. Else find-class signals error.
		(mapc #'find-class discriminator)
		(^class-wethod-url-frag handler-designator discriminator))
	      discriminators)
	    :wethod-name ,handler-designator)))
      (:package (^url-package-spec url-spec))
      (:map  `'(:map :url ,url :map-name ,(last1 url-spec))))))
Source Context