[Update book list generator to use HTML-TEMPLATE
clinton@unknownlamer.org**20080927201806
Code is now much shorter and cleaner with all of the nasty muse layout
code in a fairly readable template instead.
] {
hunk ./books.lisp 6
+(asdf:oos 'asdf:load-op :html-template)
hunk ./books.lisp 13
+(defparameter *template-pathname*
+ #p"/home/clinton/html/muse/site-support/templates/book-list.template")
+
hunk ./books.lisp 30
+(defun book-entry-vars (book)
+ (destructuring-bind (title fiction? &optional rating description)
+ book
+ `(:title ,title
+ :ratingp ,rating
+ :rating-good ,rating
+ :rating-bad ,(if rating (- 10 rating))
+ :classification ,(case fiction?
+ (:fiction "Fiction")
+ (:nonfiction "Nonfiction"))
+ :description ,(collapse-whitespace description))))
hunk ./books.lisp 42
-(defun print-book-entry (book &optional (stream t))
- (labels ((ratings-stars (rating)
- (labels ((stars (rating)
- (if (> rating 0)
- (make-string rating :initial-element #\bullet)
- nil)))
- (when rating
- (format nil "~A~@[~A~] (~A)"
- (stars rating) (stars (- 10 rating)) rating)))))
- (destructuring-bind (title fiction? rating description)
- book
- (format stream "** ~A~%~%~@[*Rating:* ~A / ~]*~A*~%~%~A~%~%"
- title
- (ratings-stars rating)
- (case fiction?
- (:fiction "Fiction")
- (:nonfiction "Nonfiction"))
- (collapse-whitespace description)))))
-
-(defun print-author-entry (entry &optional (stream t))
- (destructuring-bind (author description &rest books)
- entry
- (format stream "* ~{~A ~}~%~%~A~%~%"
- author (collapse-whitespace description))
- (mapc (lambda (book) (print-book-entry book stream)) books)))
+(defun author-vars (author)
+ (destructuring-bind (name description &rest books)
+ author
+ `(:name ,(format nil "~{~A ~}" name)
+ :description ,description
+ :books ,(mapcar #'book-entry-vars books))))
hunk ./books.lisp 49
-(defun print-book-database (all-books &optional (stream t))
- (format stream "#title A Not So Fancy Listing of Books~%~%")
- (mapc (lambda (author) (print-author-entry author stream))
- all-books))
-
-(defun print-sorted-book-database (all-books &optional (stream t))
- (print-book-database (sort (copy-list all-books)
- (lambda (name-1 name-2)
- ;; obviously fails to sort properly
- ;; when two authors have the same last
- ;; name
- (string< (symbol-name name-1)
- (symbol-name name-2)))
- :key (lambda (entry) (car (last (car entry)))))
- stream))
+(defun book-database-vars (book-database)
+ `(:authors ,(mapcar #'author-vars book-database)))
hunk ./books.lisp 53
- (book-path *book-pathname*))
+ (book-path *book-pathname*)
+ (template-path *template-pathname*))
hunk ./books.lisp 60
- (print-sorted-book-database
- (with-open-file (book-stream book-path :element-type 'extended-char)
- (read book-stream))
- muse-stream)))
+ (html-template:fill-and-print-template
+ template-path
+ (book-database-vars
+ (with-open-file (book-stream book-path :element-type 'extended-char)
+ (read book-stream)))
+ :stream muse-stream)))
+
addfile ./templates/book-list.template
hunk ./templates/book-list.template 1
-
+#title A Not So Fancy Listing of Books
+
+
+*
+
+
+
+**
+
+*Rating:* •• / **
+
+
+
+
}