From c129745433a3acd62e600adc6c9a1000b66f6f4c Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 20 Feb 2023 10:02:57 -0800 Subject: Add: route building protocol functions --- endpoints.lisp | 24 ++++++++++++++++++++++++ utilities.lisp | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/endpoints.lisp b/endpoints.lisp index 788dc2d..6dde37e 100644 --- a/endpoints.lisp +++ b/endpoints.lisp @@ -9,6 +9,30 @@ (defparameter +session-cookie-name+ "dnd-session") +;;; DND ROUTE PROTOCOL + +(defgeneric unique-name (object) + (:documentation "Returns a unique name for an object, or NIL if it does not have one.") + (:method ((ob t)) nil)) + +(defmethod unique-name ((campaign campaign)) + (campaign-title campaign)) + +(defmethod unique-name ((hero hero)) + (hero-name hero)) + +(defgeneric urlpath (inflection object) + (:documentation "Return the path to the object given a particular") + (:method ((inflection t) (object has-uid)) + "If the object has a unique human readable name, urlify that name and +incorporate it into the urlpath. Otherwise use the object's uid. + +Returns /inflection/class/identifier." + (format nil "~a/~a/~a" + (urlify inflection) + (urlify (class-name (class-of object))) + (urlify (or (unique-name object) (uid object)))))) + ;;; UTILITIES (defun redirect-to (location) diff --git a/utilities.lisp b/utilities.lisp index 5644f2e..7acdbca 100644 --- a/utilities.lisp +++ b/utilities.lisp @@ -34,4 +34,6 @@ (eql ("COOL beans") nil) :end (unless (zerop (length nick)) - (every (lambda (char) (find char +user-nick-chars+)) (string-downcase nick)))) + (loop :for char :across nick + :always (find char +user-nick-chars+ + :test #'char-equal)))) -- cgit v1.2.3