APP-PATH tweaks, COMPILE-THEME fix.

This commit is contained in:
Brit Butler 2012-08-19 14:06:30 -04:00
parent 558a04e696
commit 65d4f349da
4 changed files with 27 additions and 53 deletions

View file

@ -1,19 +1,9 @@
(in-package :coleslaw) (in-package :coleslaw)
(defclass blog () (defun app-path (path &rest args)
((author :initarg :author :initform "" :accessor author) "Take a relative PATH and return the corresponding pathname beneath coleslaw.
(domain :initarg :domain :initform "" :accessor domain) If ARGS is provided, use (apply 'format nil PATH ARGS) as the value of PATH."
(interval :initarg :interval :initform 600 :accessor interval) (merge-pathnames (apply 'format nil path args) coleslaw-conf:*basedir*))
(license :initarg :license :initform "" :accessor license)
(plugins :initarg :plugins :initform '() :accessor plugins)
(repo :initarg :repo :initform #p"/" :accessor repo)
(sitenav :initarg :sitenav :initform "" :accessor sitenav)
(title :initarg :title :initform "" :accessor title)
(theme :initarg :theme :initform "hyde" :accessor theme)))
(defun app-path (path)
"Take a relative PATH and return the corresponding pathname beneath coleslaw."
(merge-pathnames path coleslaw-conf:*basedir*))
(defun compile-blog () (defun compile-blog ()
(let ((staging #p"/tmp/coleslaw/")) (let ((staging #p"/tmp/coleslaw/"))
@ -22,7 +12,7 @@
(delete-files staging :recursive t) (delete-files staging :recursive t)
(ensure-directories-exist staging)) (ensure-directories-exist staging))
(with-current-directory staging (with-current-directory staging
(let ((css-dir (app-path (format nil "themes/~a/css/" (theme *config*)))) (let ((css-dir (app-path "themes/~a/css/" (theme *config*)))
(static-dir (merge-pathnames "static/" (repo *config*)))) (static-dir (merge-pathnames "static/" (repo *config*))))
(dolist (dir (list css-dir static-dir)) (dolist (dir (list css-dir static-dir))
(run-program "cp" `("-R" ,dir ".")))) (run-program "cp" `("-R" ,dir "."))))
@ -36,7 +26,7 @@
(defun deploy (dir) (defun deploy (dir)
"Deploy DIR, updating the .prev and .curr symlinks." "Deploy DIR, updating the .prev and .curr symlinks."
(let ((new-build (app-path (format nil "generated/~a" (get-universal-time))))) (let ((new-build (app-path "generated/~a" (get-universal-time))))
(run-program "mv" (list dir (namestring new-build))) (run-program "mv" (list dir (namestring new-build)))
(when (probe-file (app-path ".prev")) (when (probe-file (app-path ".prev"))
(delete-files (read-symlink (app-path ".prev")) :recursive t)) (delete-files (read-symlink (app-path ".prev")) :recursive t))
@ -47,6 +37,7 @@
(defun main () (defun main ()
(load-config) (load-config)
(compile-theme)
(loop do (if (blog-update-p) (loop do (if (blog-update-p)
(compile-blog) (compile-blog)
(sleep (interval *config*))))) (sleep (interval *config*)))))

View file

@ -1,5 +1,16 @@
(in-package :coleslaw) (in-package :coleslaw)
(defclass blog ()
((author :initarg :author :initform "" :accessor author)
(domain :initarg :domain :initform "" :accessor domain)
(interval :initarg :interval :initform 600 :accessor interval)
(license :initarg :license :initform "" :accessor license)
(plugins :initarg :plugins :initform '() :accessor plugins)
(repo :initarg :repo :initform #p"/" :accessor repo)
(sitenav :initarg :sitenav :initform "" :accessor sitenav)
(title :initarg :title :initform "" :accessor title)
(theme :initarg :theme :initform "hyde" :accessor theme)))
(defparameter *config* nil (defparameter *config* nil
"A variable to store the blog configuration and plugin settings.") "A variable to store the blog configuration and plugin settings.")

View file

@ -4,35 +4,5 @@
#:delete-files #:delete-files
#:read-symlink #:read-symlink
#:run-program) #:run-program)
(:export ;; themes (:import-from :iolib.pathnames #:file-path-namestring)
#:add-injection (:export #:main))
#:remove-injection
;; plugins
#:load-plugins
;; posts
#:make-post
#:add-post
#:remove-post
#:render-post
#:find-post
#:post-url
#:post-id
#:post-title
#:post-tags
#:post-date
#:post-content
#:post-aliases
;; indices
#:make-index
#:add-to-index
#:remove-from-index
#:render-index
#:find-index
#:index-url
#:index-id
#:index-posts))

View file

@ -9,11 +9,13 @@
(defun theme-package (&key (name (theme *config*))) (defun theme-package (&key (name (theme *config*)))
(find-package (string-upcase (concatenate 'string "coleslaw.theme." name)))) (find-package (string-upcase (concatenate 'string "coleslaw.theme." name))))
(defun compile-theme (&key (theme-dir (app-path (theme *config*)))) (defun compile-theme (&key (theme-dir (app-path "themes/~a/" (theme *config*))))
(loop for file in (iolib.os:list-directory theme-dir) (flet ((maybe-compile (file)
do (let ((extension (pathname-type file))) (let* ((path (merge-pathnames (file-path-namestring file) theme-dir))
(when (and extension (string= extension "tmpl")) (extension (pathname-type path)))
(compile-template :common-lisp-backend file))))) (when (and extension (string= extension "tmpl"))
(compile-template :common-lisp-backend path)))))
(iolib.os:mapdir #'maybe-compile theme-dir)))
;; DOCUMENTATION ;; DOCUMENTATION
;; A theme directory should be named after the theme and contain *.tmpl files ;; A theme directory should be named after the theme and contain *.tmpl files