summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2023-02-20 10:02:57 -0800
committercolin <colin@cicadas.surf>2023-02-20 10:02:57 -0800
commitc129745433a3acd62e600adc6c9a1000b66f6f4c (patch)
tree1f8e4d68f210346d760f54c78c9f2cc1232e74d9
parentfc4b6e145457bc057b050170245d290b9b70fbe8 (diff)
Add: route building protocol functions
-rw-r--r--endpoints.lisp24
-rw-r--r--utilities.lisp4
2 files changed, 27 insertions, 1 deletions
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))))