Mercurial > piecrust2
annotate piecrust/plugins/base.py @ 196:154b8df04829
processing: Add Compass and Sass processors.
The Sass processor is similar to the Less processor, i.e. it tries to be
part of the structured pipeline processing by using the mapfile produced by
the Sass compiler in order to provide a list of dependencies.
The Compass processor is completely acting outside of the pipeline, so the
server won't know what's up to date and what's not. It's expected that the
user will run `compass watch` to keep things up to date. However, it will
require to pass the server's cache directory to put things in, so we'll need
to add some easy way to get that path for the user.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 11 Jan 2015 23:08:49 -0800 |
parents | 343d08ef5668 |
children | 5dbab01daaba |
rev | line source |
---|---|
0 | 1 import os |
2 | |
3 | |
4 class PieCrustPlugin(object): | |
5 def getFormatters(self): | |
6 return [] | |
7 | |
8 def getTemplateEngines(self): | |
9 return [] | |
10 | |
11 def getDataProviders(self): | |
12 return [] | |
13 | |
14 def getFileSystems(self): | |
15 return [] | |
16 | |
17 def getProcessors(self): | |
18 return [] | |
19 | |
20 def getImporters(self): | |
21 return [] | |
22 | |
23 def getCommands(self): | |
24 return [] | |
25 | |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
26 def getCommandExtensions(self): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
27 return [] |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
28 |
0 | 29 def getRepositories(self): |
30 return [] | |
31 | |
32 def getBakerAssistants(self): | |
33 return [] | |
34 | |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
35 def getSources(self): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
36 return [] |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
37 |
0 | 38 def initialize(self, app): |
39 pass | |
40 | |
41 | |
42 class PluginLoader(object): | |
43 def __init__(self, app): | |
44 self.app = app | |
45 self._plugins = None | |
46 self._pluginsMeta = None | |
47 self._componentCache = {} | |
48 | |
49 @property | |
50 def plugins(self): | |
51 self._ensureLoaded() | |
52 return self._plugins | |
53 | |
54 def getFormatters(self): | |
55 return self._getPluginComponents('getFormatters', True, | |
56 order_key=lambda f: f.priority) | |
57 | |
58 def getTemplateEngines(self): | |
59 return self._getPluginComponents('getTemplateEngines', True) | |
60 | |
61 def getDataProviders(self): | |
62 return self._getPluginComponents('getDataProviders') | |
63 | |
64 def getFileSystems(self): | |
65 return self._getPluginComponents('getFileSystems') | |
66 | |
67 def getProcessors(self): | |
68 return self._getPluginComponents('getProcessors', True, | |
69 order_key=lambda p: p.priority) | |
70 | |
71 def getImporters(self): | |
72 return self._getPluginComponents('getImporters') | |
73 | |
74 def getCommands(self): | |
75 return self._getPluginComponents('getCommands') | |
76 | |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
77 def getCommandExtensions(self): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
78 return self._getPluginComponents('getCommandExtensions') |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
79 |
0 | 80 def getRepositories(self): |
81 return self._getPluginComponents('getRepositories', True) | |
82 | |
83 def getBakerAssistants(self): | |
84 return self._getPluginComponents('getBakerAssistants') | |
85 | |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
86 def getSources(self): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
87 return self._getPluginComponents('getSources') |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
88 |
0 | 89 def _ensureLoaded(self): |
90 if self._plugins is not None: | |
91 return | |
92 | |
1
aaa8fb7c8918
Re-arranged modules to reduce dependencies to builtin stuff.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
93 from piecrust.plugins.builtin import BuiltInPlugin |
0 | 94 self._plugins = [BuiltInPlugin()] |
95 self._pluginsMeta = {self._plugins[0].name: False} | |
96 | |
97 for d in self.app.plugins_dirs: | |
98 _, dirs, __ = next(os.walk(d)) | |
99 for dd in dirs: | |
100 self._loadPlugin(os.path.join(d, dd)) | |
101 | |
102 for plugin in self._plugins: | |
103 plugin.initialize(self.app) | |
104 | |
105 def _loadPlugin(self, plugin_dir): | |
106 pass | |
107 | |
7
343d08ef5668
More PieCrust 3 fixes, and a couple of miscellaneous bug fixes.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
108 def _getPluginComponents(self, name, initialize=False, order_key=None): |
0 | 109 if name in self._componentCache: |
110 return self._componentCache[name] | |
111 | |
112 all_components = [] | |
113 for plugin in self.plugins: | |
114 plugin_components = getattr(plugin, name)() | |
115 all_components += plugin_components | |
116 if initialize: | |
117 for comp in plugin_components: | |
118 comp.initialize(self.app) | |
119 | |
7
343d08ef5668
More PieCrust 3 fixes, and a couple of miscellaneous bug fixes.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
120 if order_key is not None: |
343d08ef5668
More PieCrust 3 fixes, and a couple of miscellaneous bug fixes.
Ludovic Chabant <ludovic@chabant.com>
parents:
3
diff
changeset
|
121 all_components.sort(key=order_key) |
0 | 122 |
123 self._componentCache[name] = all_components | |
124 return all_components | |
125 |