Mercurial > piecrust2
comparison piecrust/app.py @ 1005:2e5c5d33d62c
Merge changes.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 21 Nov 2017 22:07:12 -0800 |
parents | 8adc27285d93 46025a1b5434 |
children | c4cf3cfe2726 |
comparison
equal
deleted
inserted
replaced
1004:4f2e0136123d | 1005:2e5c5d33d62c |
---|---|
13 from piecrust.configuration import ConfigurationError | 13 from piecrust.configuration import ConfigurationError |
14 from piecrust.environment import StandardEnvironment | 14 from piecrust.environment import StandardEnvironment |
15 from piecrust.page import Page | 15 from piecrust.page import Page |
16 from piecrust.plugins.base import PluginLoader | 16 from piecrust.plugins.base import PluginLoader |
17 from piecrust.routing import Route | 17 from piecrust.routing import Route |
18 from piecrust.sources.base import REALM_THEME | |
19 from piecrust.uriutil import multi_replace | |
18 | 20 |
19 | 21 |
20 logger = logging.getLogger(__name__) | 22 logger = logging.getLogger(__name__) |
21 | 23 |
22 | 24 |
116 # No theme if the curent site is already a theme. | 118 # No theme if the curent site is already a theme. |
117 if self.theme_site: | 119 if self.theme_site: |
118 return None | 120 return None |
119 | 121 |
120 # See if there's a theme we absolutely want. | 122 # See if there's a theme we absolutely want. |
121 td = self._get_dir(THEME_DIR) | 123 td = os.path.join(self.root_dir, THEME_DIR) |
122 if td is not None: | 124 if os.path.isdir(td): |
123 return td | 125 return td |
124 | 126 |
125 # Try to load a theme specified in the configuration. | 127 # Try to load a theme specified in the configuration. |
126 from piecrust.themes.base import ThemeLoader | 128 from piecrust.themes.base import ThemeLoader |
127 loader = ThemeLoader(self.root_dir) | 129 loader = ThemeLoader(self.root_dir) |
131 | 133 |
132 # Nothing... use the default theme. | 134 # Nothing... use the default theme. |
133 return os.path.join(RESOURCES_DIR, 'theme') | 135 return os.path.join(RESOURCES_DIR, 'theme') |
134 | 136 |
135 @cached_property | 137 @cached_property |
136 def plugins_dir(self): | 138 def plugins_dirs(self): |
137 return self._get_dir(PLUGINS_DIR) | 139 return self._get_configurable_dirs(PLUGINS_DIR, 'site/plugins_dirs') |
138 | 140 |
139 @cached_property | 141 @cached_property |
140 def cache_dir(self): | 142 def cache_dir(self): |
141 return os.path.join(self.root_dir, CACHE_DIR, self.cache_key) | 143 return os.path.join(self.root_dir, CACHE_DIR, self.cache_key) |
142 | 144 |
227 cache_key = '%s@%s' % (source.name, content_item.spec) | 229 cache_key = '%s@%s' % (source.name, content_item.spec) |
228 return self.env.page_repository.get( | 230 return self.env.page_repository.get( |
229 cache_key, | 231 cache_key, |
230 lambda: Page(source, content_item)) | 232 lambda: Page(source, content_item)) |
231 | 233 |
232 def _get_dir(self, default_rel_dir): | 234 def resolvePath(self, path): |
233 abs_dir = os.path.join(self.root_dir, default_rel_dir) | 235 path = multi_replace(path, {'%theme_dir%': self.theme_dir}) |
234 if os.path.isdir(abs_dir): | 236 return os.path.join(self.root_dir, path) |
235 return abs_dir | |
236 return None | |
237 | 237 |
238 def _get_configurable_dirs(self, default_rel_dir, conf_name): | 238 def _get_configurable_dirs(self, default_rel_dir, conf_name): |
239 dirs = [] | 239 dirs = [] |
240 | 240 |
241 # Add custom directories from the configuration. | 241 # Add custom directories from the configuration. |
242 conf_dirs = self.config.get(conf_name) | 242 conf_dirs = self.config.get(conf_name) |
243 if conf_dirs is not None: | 243 if conf_dirs is not None: |
244 if isinstance(conf_dirs, str): | 244 if isinstance(conf_dirs, str): |
245 dirs.append(os.path.join(self.root_dir, conf_dirs)) | 245 dirs.append(self.resolvePath(conf_dirs)) |
246 else: | 246 else: |
247 dirs += [os.path.join(self.root_dir, p) for p in conf_dirs] | 247 dirs += [self.resolvePath(p) for p in conf_dirs] |
248 | 248 |
249 # Add the default directory if it exists. | 249 # Add the default directory if it exists. |
250 default_dir = os.path.join(self.root_dir, default_rel_dir) | 250 default_dir = os.path.join(self.root_dir, default_rel_dir) |
251 if os.path.isdir(default_dir): | 251 if os.path.isdir(default_dir): |
252 dirs.append(default_dir) | 252 dirs.append(default_dir) |