From c205dff8ea8671680dfd9654dd6405d4ba4d0933 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sun, 16 Jun 2024 21:10:36 -0500 Subject: [PATCH] Actually define a YASON encoder for every class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … I’m not even sure what I committed earlier. --- src/activity-vocabulary.lisp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/activity-vocabulary.lisp b/src/activity-vocabulary.lisp index 25068fc..d2bc841 100644 --- a/src/activity-vocabulary.lisp +++ b/src/activity-vocabulary.lisp @@ -203,15 +203,6 @@ CLASS’es slots with JSON keys based on the camel-cased slot name." ;;; JSON serialization ;;; ———————————————————————————————————————— -(defun class-slots-to-camel-cased-strings-alist (class) - "Return an associative list of a CLASS’es direct slots (by symbol) matched with -their names in camel-case format." - (mapcar - (lambda (slot) - (let ((name (closer-mop:slot-definition-name slot))) - (cons name (str:camel-case (symbol-name name))))) - (closer-mop:class-direct-slots class))) - ;; Ensure all classes have their slots’ encodings defined with YASON. (mapcar (lambda (class) (closer-mop:finalize-inheritance class) @@ -219,3 +210,27 @@ their names in camel-case format." (mapcar #'find-class '(object link activity collection collection-page ordered-collection-page place profile relationship tombstone))) + + + +;;; Util +;;; ———————————————————————————————————————— +(defun class-slots-to-camel-cased-strings-alist (class) + "Return an associative list of a CLASS’es direct slots (by symbol) matched with +their names in camel-case format." + (mapcar + (lambda (slot) + (let ((name (closer-mop:slot-definition-name slot))) + (cons name (camel-case (symbol-name name))))) + (closer-mop:class-direct-slots class))) + +(defun camel-case (string) + "Convert a STRING to camel-casing. +Wrapper around STR:CAMEL-CASE, working around a bug that a non-alphanumeric +character at the start of the string gets erroneously (or at least undesireably, +to us) removed." + (if (not (alphanumericp (aref string 0))) + (concatenate 'string + (string (aref string 0)) + (str:camel-case string)) + (str:camel-case string)))