diff piecrust/app.py @ 999:46025a1b5434

plugins: Support multiple customizable plugins directories. Also add support for specifying the theme directory in some customizable paths.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 21 Nov 2017 09:54:56 -0800
parents 7d83b9484b98
children 2e5c5d33d62c
line wrap: on
line diff
--- a/piecrust/app.py	Tue Nov 21 09:54:00 2017 -0800
+++ b/piecrust/app.py	Tue Nov 21 09:54:56 2017 -0800
@@ -16,6 +16,7 @@
 from piecrust.plugins.base import PluginLoader
 from piecrust.routing import Route
 from piecrust.sources.base import REALM_THEME
+from piecrust.uriutil import multi_replace
 
 
 logger = logging.getLogger(__name__)
@@ -112,8 +113,8 @@
             return None
 
         # See if there's a theme we absolutely want.
-        td = self._get_dir(THEME_DIR)
-        if td is not None:
+        td = os.path.join(self.root_dir, THEME_DIR)
+        if os.path.isdir(td):
             return td
 
         # Try to load a theme specified in the configuration.
@@ -127,8 +128,8 @@
         return os.path.join(RESOURCES_DIR, 'theme')
 
     @cached_property
-    def plugins_dir(self):
-        return self._get_dir(PLUGINS_DIR)
+    def plugins_dirs(self):
+        return self._get_configurable_dirs(PLUGINS_DIR, 'site/plugins_dirs')
 
     @cached_property
     def cache_dir(self):
@@ -240,11 +241,9 @@
                 return pub
         return None
 
-    def _get_dir(self, default_rel_dir):
-        abs_dir = os.path.join(self.root_dir, default_rel_dir)
-        if os.path.isdir(abs_dir):
-            return abs_dir
-        return None
+    def resolvePath(self, path):
+        path = multi_replace(path, {'%theme_dir%': self.theme_dir})
+        return os.path.join(self.root_dir, path)
 
     def _get_configurable_dirs(self, default_rel_dir, conf_name):
         dirs = []
@@ -253,9 +252,9 @@
         conf_dirs = self.config.get(conf_name)
         if conf_dirs is not None:
             if isinstance(conf_dirs, str):
-                dirs.append(os.path.join(self.root_dir, conf_dirs))
+                dirs.append(self.resolvePath(conf_dirs))
             else:
-                dirs += [os.path.join(self.root_dir, p) for p in conf_dirs]
+                dirs += [self.resolvePath(p) for p in conf_dirs]
 
         # Add the default directory if it exists.
         default_dir = os.path.join(self.root_dir, default_rel_dir)