summaryrefslogtreecommitdiff
path: root/src/names.lisp
blob: 05397a666ef5eb28fc4ce9a07b40956d88de797c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;;;; names.lisp -- a protocol for getting the names of things, and
;;;; generally referring to objects with strings.

(in-package :dnd)

(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 ((adventure adventure))
  (title adventure))

(defmethod unique-name ((hero hero))
  (name hero))


(defgeneric urlpath (object)
  (:documentation "Return the path to the object given a particular")
  (:method ((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 /class/identifier."
    (format nil "/~a/~a/~a"
            (urlify (class-name (class-of object)))
            (urlify (uid object))
            (urlify (or (unique-name object) (uid object))))))