| 12 | |
| 13 | === New Configuration API for Components === |
| 14 | |
| 15 | Components can still use `self.config.get...`, but there's now a better way to do this, |
| 16 | which among other things make it easy to document your configuration settings. |
| 17 | |
| 18 | When you had: |
| 19 | {{{ |
| 20 | #!python |
| 21 | class DoxygenPlugin(Component): |
| 22 | implements(...) |
| 23 | # ... |
| 24 | def match_request(self, req): |
| 25 | # Get config variables. |
| 26 | base_path = self.config.get('doxygen', 'path', '/var/lib/trac/doxygen') |
| 27 | }}} |
| 28 | |
| 29 | You should now write: |
| 30 | {{{ |
| 31 | #!python |
| 32 | class DoxygenPlugin(Component): |
| 33 | implements(...) |
| 34 | base_path = Option('doxygen', 'path', '/var/lib/trac/doxygen', |
| 35 | """Directory containing doxygen generated files.""") |
| 36 | |
| 37 | # ... |
| 38 | def match_request(self, req): |
| 39 | base_path = self.base_path |
| 40 | # actually, use `self.base_path` where you'd used `base_path` |
| 41 | }}} |
| 42 | |
| 43 | Besides the string `Option`, you have also access to more specialized types for you configuration settings, like `BoolOption`, `IntOption`, `ListOption`, etc. (see [source:trunk/trac/config.py@head#L326 config.py]). |
| 44 | |
| 45 | By using the [WikiMacros#TracIni-macro TracIni(doxygen)] macro, you'll get the documentation for all your settings. |
| 46 | |