= Theme Plugins = '''Do not edit this page until this notice is removed''' This proposal describes a way trac could get a working theme support. The main idea is that every project which uses trac should have it's own theme. Or at least each major trac installation. The current way is overriding `htdocs_location` in the trac config to bypass the shipped css and js files and inject new ones. Using the `site.html` file (talking of trac 0.11) you can then override the way the template is rendered. Because of the great Genshi API with XPATH support nearly everything is overrideable. But trac upgrades are a pain in the ass and distributing themes does not work. '''Solution''' * generic css classes (see below) * prefixing every css class with #x-trac * shipping two themes `trac` and `custom`, first one is the default trac theme, the latter a instance based theme, also see below * map theme providers to names using entrypoints * specify the used theme in the config with `[trac]\ntheme=TracTheme` == State Of Implementation == I am currently working on implementing this. See the most recent patch for some more information. Available themes in that patch: * `TracTheme` - a theme that looks like a normal trac installation * `JinjaTheme` - a theme that integrates trac into the jinja webpage as proof of concept * `CustomTheme` - a theme that loads the `site.html` and instance htdocs == Generic CSS Classes == One of the first things which should be done is cleaning up the shipped css files. They should use more generic classes and documented classes. Each plugin the developer should be able to use them too in his or her plugins. Also, the trac core would only ship layout css files without color definitions. The default theme would then add the color definitions for the elements (links, browser etc). Currently the only way to change the trac colors is copying the default css files and replace all the color hex values with own ones. To create a list of generic classes an analysis of the current css files and genshi templates would be required. Also *all* css rules must be prefixed with `#x-trac` in order to avoid name collisions with existing templates of project webpages. == Example Theme Provider == This is an example theme provider for a distributable theme. {{{ #!python class MyTheme(Component): implements(IThemeProvider, ITemplateProvider) # IThemeProvider def get_theme_htdocs_id(self): return 'mytheme' def get_theme_site_template(self): return 'mytheme/site.html' # ITemplateProvider methods def get_templates_dirs(self): from pkg_resources import resource_filename return [resource_filename(__name__, 'templates')] def get_htdocs_dirs(self): from pkg_resources import resource_filename return [('mytheme', resource_filename(__name__, 'htdocs'))] }}} == Custom Theme Provider == This is included the trac distribution in order to load templates from the instance folder. {{{ #!python class CustomTheme(Component): implements(IThemeProvider) # IThemeProvider def get_theme_htdocs_id(self): return 'site' def get_theme_site_template(self): return 'site.html' }}} There will also be a `UserTheme` component class which uses the `site.html` from the trac instance folder and the template/htdocs folder in the instance. It's one of the both default themes: * `trac` - the trac default theme * `custom` - a special theme that forwards the htdocs/template lookups to the instance folders and uses the normal `site.html` as template. == Templates == Changes in the templates are quite small. The `layout.html` should look like this: {{{ #!text/html