Bladeren bron

Generalize DO-CTYPES to DO-SUBCLASSES, update callsites.

Brit Butler 11 jaren geleden
bovenliggende
commit
39687805f5
3 gewijzigde bestanden met toevoegingen van 12 en 10 verwijderingen
  1. 2 1
      src/coleslaw.lisp
  2. 3 9
      src/content.lisp
  3. 7 0
      src/util.lisp

+ 2 - 1
src/coleslaw.lisp

@@ -55,7 +55,8 @@ Additional args to render CONTENT can be passed via RENDER-ARGS."
55 55
                        (merge-pathnames "static" (repo *config*))))
56 56
       (when (probe-file dir)
57 57
         (run-program "rsync --delete -raz ~a ." dir)))
58
-    (do-ctypes (publish (make-keyword ctype)))
58
+    (do-subclasses (ctype content)
59
+      (publish (make-keyword ctype)))
59 60
     (render-indexes (feeds *config*))
60 61
     (update-symlink "index.html" "1.html")))
61 62
 

+ 3 - 9
src/content.lisp

@@ -70,7 +70,7 @@
70 70
 (defun discover (content-type)
71 71
   "Load all content of the given CONTENT-TYPE from disk."
72 72
   (purge-all content-type)
73
-  (let ((file-type (string-downcase (princ-to-string content-type))))
73
+  (let ((file-type (string-downcase (symbol-name content-type))))
74 74
     (do-files (file (repo *config*) file-type)
75 75
       (let ((obj (construct content-type (read-content file))))
76 76
         (if (gethash (content-slug obj) *content*)
@@ -78,16 +78,10 @@
78 78
                    (content-slug obj))
79 79
             (setf (gethash (content-slug obj) *content*) obj))))))
80 80
 
81
-(defmacro do-ctypes (&body body)
82
-  "Iterate over the subclasses of CONTENT performing BODY with ctype lexically
83
-bound to the current subclass."
84
-  (alexandria:with-gensyms (ctypes)
85
-    `(let ((,ctypes (closer-mop:class-direct-subclasses (find-class 'content))))
86
-       (loop for ctype in (mapcar #'class-name ,ctypes) do ,@body))))
87
-
88 81
 (defun load-content ()
89 82
   "Load all content stored in the blog's repo."
90
-  (do-ctypes (discover ctype)))
83
+  (do-subclasses (ctype content)
84
+    (discover ctype)))
91 85
 
92 86
 (defun by-date (content)
93 87
   "Sort CONTENT in reverse chronological order."

+ 7 - 0
src/util.lisp

@@ -4,6 +4,13 @@
4 4
   "Create an instance of CLASS-NAME with the given ARGS."
5 5
   (apply 'make-instance class-name args))
6 6
 
7
+(defmacro do-subclasses ((var class) &body body)
8
+  "Iterate over the subclasses of CLASS performing BODY with VAR
9
+lexically bound to the current subclass' class-name."
10
+  (alexandria:with-gensyms (klasses)
11
+    `(let ((,klasses (closer-mop:class-direct-subclasses (find-class ',class))))
12
+       (loop for ,var in (mapcar #'class-name ,klasses) do ,@body))))
13
+
7 14
 (defun fmt (fmt-str args)
8 15
   "A convenient FORMAT interface for string building."
9 16
   (apply 'format nil fmt-str args))