From 4b264e258777f4ed8cca3775c2b5b533e6801206 Mon Sep 17 00:00:00 2001 From: Brit Butler Date: Mon, 20 Aug 2012 09:41:50 -0400 Subject: [PATCH] Add DO-FILES and refactor COMPILE-THEME. --- src/coleslaw.lisp | 10 ++++++++++ src/themes.lisp | 10 ++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/coleslaw.lisp b/src/coleslaw.lisp index 88d6148..552c06e 100644 --- a/src/coleslaw.lisp +++ b/src/coleslaw.lisp @@ -5,6 +5,16 @@ If ARGS is provided, use (apply 'format nil PATH ARGS) as the value of PATH." (merge-pathnames (apply 'format nil path args) coleslaw-conf:*basedir*)) +(defun to-pathname (file parent) + "Convert an iolib file-path back to a pathname." + (merge-pathnames (file-path-namestring file) parent)) + +(defmacro do-files ((var path) &body body) + "For each file under PATH, run BODY." + `(iolib.os:mapdir (lambda (x) + (let ((,var (to-pathname x ,path))) + ,@body)) ,path)) + (defun compile-blog () (let ((staging #p"/tmp/coleslaw/")) ; TODO: More incremental compilation? Don't regen whole blog unnecessarily. diff --git a/src/themes.lisp b/src/themes.lisp index fcc7625..4af27bf 100644 --- a/src/themes.lisp +++ b/src/themes.lisp @@ -10,12 +10,10 @@ (find-package (string-upcase (concatenate 'string "coleslaw.theme." name)))) (defun compile-theme (&key (theme-dir (app-path "themes/~a/" (theme *config*)))) - (flet ((maybe-compile (file) - (let* ((path (merge-pathnames (file-path-namestring file) theme-dir)) - (extension (pathname-type path))) - (when (and extension (string= extension "tmpl")) - (compile-template :common-lisp-backend path))))) - (iolib.os:mapdir #'maybe-compile theme-dir))) + (do-files (file theme-dir) + (let ((extension (pathname-type file))) + (when (and extension (string= extension "tmpl")) + (compile-template :common-lisp-backend file))))) ;; DOCUMENTATION ;; A theme directory should be named after the theme and contain *.tmpl files