Cleanup plugin loading.

This commit is contained in:
Brit Butler 2014-05-06 15:18:58 -04:00
parent 0912413f11
commit 1ea73feab7

View file

@ -19,23 +19,24 @@
(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.")
(defun enable-plugin (file &rest args) (defun enable-plugin (name args)
"Given a path to a plugin, FILE, compile+load it, then call its ENABLE function." "Given a plugin, NAME, compile+load it and call its ENABLE function with ARGS."
(compile-file file) (flet ((plugin-path (sym)
(load file) (app-path "plugins/~(~A~)" sym))
(let* ((pkgname (format nil "coleslaw-~a" (pathname-name file))) (plugin-package (sym)
(plugin-pkg (find-package (string-upcase pkgname)))) (format nil "~:@(coleslaw-~A~)" sym)))
(apply (find-symbol "ENABLE" plugin-pkg) args))) (let ((file (plugin-path name)))
(load (compile-file file :verbose nil :print nil) :verbose t))
(let ((package (find-package (plugin-package name))))
(apply (find-symbol "ENABLE" package) args))))
(defun load-plugins (plugins) (defun load-plugins (plugins)
"Compile and load the listed PLUGINS. It is expected that matching *.lisp files "Compile and load the listed PLUGINS. It is expected that matching *.lisp files
are in the plugins folder in coleslaw's source directory." are in the plugins folder in coleslaw's source directory."
(setf *injections* nil) (setf *injections* nil)
(flet ((plugin-path (sym) (dolist (plugin plugins)
(app-path "plugins/~a" (string-downcase (symbol-name sym))))) (destructuring-bind (name &rest args) plugin
(dolist (plugin plugins) (enable-plugin name args))))
(destructuring-bind (name &rest args) plugin
(apply 'enable-plugin (plugin-path name) args)))))
(defun discover-config-path (repo-path) (defun discover-config-path (repo-path)
"Check the supplied REPO-PATH for a .coleslawrc and if one "Check the supplied REPO-PATH for a .coleslawrc and if one