Move the filepath stuff into an :around method.

This commit is contained in:
Brit Butler 2012-12-14 14:55:25 -05:00
parent 6dc400c91c
commit d7747ea0b2

View file

@ -15,6 +15,12 @@
(defgeneric page-path (object) (defgeneric page-path (object)
(:documentation "The path to store OBJECT at once rendered.")) (:documentation "The path to store OBJECT at once rendered."))
(defmethod page-path :around ((object object))
(let ((result (namestring (call-next-method))))
(if (position #\. result)
result
(concatenate 'string result ".html"))))
(defun render-page (content &optional theme-fn &rest render-args) (defun render-page (content &optional theme-fn &rest render-args)
"Render the given CONTENT to disk using THEME-FN if supplied. "Render the given CONTENT to disk using THEME-FN if supplied.
Additional args to render CONTENT can be passed via RENDER-ARGS." Additional args to render CONTENT can be passed via RENDER-ARGS."
@ -26,15 +32,12 @@ Additional args to render CONTENT can be passed via RENDER-ARGS."
:injections (find-injections content)))) :injections (find-injections content))))
(defun write-page (filepath page) (defun write-page (filepath page)
"Write the given PAGE to FILEPATH.html unless an extension is present." "Write the given PAGE to FILEPATH."
(let ((path (if (position #\. filepath) (ensure-directories-exist filepath)
filepath (with-open-file (out filepath
(concatenate 'string filepath ".html")))) :direction :output
(ensure-directories-exist path) :if-does-not-exist :create)
(with-open-file (out path (write-line page out)))
:direction :output
:if-does-not-exist :create)
(write-line page out))))
(defun compile-blog (staging) (defun compile-blog (staging)
"Compile the blog to a STAGING directory as specified in .coleslawrc." "Compile the blog to a STAGING directory as specified in .coleslawrc."