Mercurial > piecrust2
comparison piecrust/plugins/base.py @ 849:8f8bbb2e70e1
templating: Template engines can now load extensions directly from plugins.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 27 Apr 2017 20:55:07 -0700 |
parents | 7d83b9484b98 |
children | 4850f8c21b6e 46025a1b5434 |
comparison
equal
deleted
inserted
replaced
848:7d83b9484b98 | 849:8f8bbb2e70e1 |
---|---|
11 class PieCrustPlugin(object): | 11 class PieCrustPlugin(object): |
12 def getFormatters(self): | 12 def getFormatters(self): |
13 return [] | 13 return [] |
14 | 14 |
15 def getTemplateEngines(self): | 15 def getTemplateEngines(self): |
16 return [] | |
17 | |
18 def getTemplateEngineExtensions(self, engine_name): | |
16 return [] | 19 return [] |
17 | 20 |
18 def getDataProviders(self): | 21 def getDataProviders(self): |
19 return [] | 22 return [] |
20 | 23 |
66 def getTemplateEngines(self): | 69 def getTemplateEngines(self): |
67 return self._getPluginComponents( | 70 return self._getPluginComponents( |
68 'getTemplateEngines', | 71 'getTemplateEngines', |
69 initialize=True, register_timer=True, | 72 initialize=True, register_timer=True, |
70 register_timer_suffixes=['_segment', '_layout']) | 73 register_timer_suffixes=['_segment', '_layout']) |
74 | |
75 def getTemplateEngineExtensions(self, engine_name): | |
76 return self._getPluginComponents('getTemplateEngineExtensions', | |
77 engine_name) | |
71 | 78 |
72 def getDataProviders(self): | 79 def getDataProviders(self): |
73 return self._getPluginComponents('getDataProviders') | 80 return self._getPluginComponents('getDataProviders') |
74 | 81 |
75 def getProcessors(self): | 82 def getProcessors(self): |
151 (plugin_name, ex)) | 158 (plugin_name, ex)) |
152 return | 159 return |
153 | 160 |
154 return plugin | 161 return plugin |
155 | 162 |
156 def _getPluginComponents(self, name, *, | 163 def _getPluginComponents(self, name, *args, |
157 initialize=False, | 164 initialize=False, |
158 register_timer=False, | 165 register_timer=False, |
159 register_timer_suffixes=None, | 166 register_timer_suffixes=None, |
160 order_key=None): | 167 order_key=None): |
161 if name in self._componentCache: | 168 if name in self._componentCache: |
162 return self._componentCache[name] | 169 return self._componentCache[name] |
163 | 170 |
164 all_components = [] | 171 all_components = [] |
165 for plugin in self.plugins: | 172 for plugin in self.plugins: |
166 plugin_components = getattr(plugin, name)() | 173 plugin_components = getattr(plugin, name)(*args) |
167 all_components += plugin_components | 174 all_components += plugin_components |
168 | 175 |
169 if initialize: | 176 if initialize: |
170 for comp in plugin_components: | 177 for comp in plugin_components: |
171 comp.initialize(self.app) | 178 comp.initialize(self.app) |