from genshi.builder import tag
from genshi.filters import Transformer
from genshi.filters.transform import StreamBuffer

from trac.core import *
from trac.web.chrome import Chrome, add_stylesheet, add_script
from trac.web.api import IRequestFilter, ITemplateStreamFilter

class Theme(Component):
    implements(IRequestFilter, ITemplateStreamFilter)

    def pre_process_request(self, req, handler):
        add_stylesheet(req, 'http://fonts.googleapis.com/css?family=Ubuntu')
        add_stylesheet(req, 'lightertheme/theme.css')
        return handler

    def post_process_request(self, req, template, data, content_type):
        return template, data, content_type

    def filter_stream(self, req, method, filename, stream, data):
        """
        Wrap the banner and mainnav in a single banner_wrapper div
        """
        buffer = StreamBuffer()
        filter = Transformer("//div[@id='banner']")
        stream |= filter.wrap(tag.div(id="banner_wrapper")).end().select("//div[@id='mainnav']").cut(buffer, accumulate=True).end().buffer().select("//div[@id='banner_wrapper']").append(tag.hr()).a\
ppend(buffer).end()

        return stream




@@ -1,20 +1,65 @@
+from pkg_resources import resource_filename%0A%0A
 from genshi.builder 
@@ -246,16 +246,62 @@
 _script%0A
+from trac.web.chrome import ITemplateProvider%0A
 from tra
@@ -432,16 +432,35 @@
 amFilter
+, ITemplateProvider
 )%0A%0A    d
@@ -1079,16 +1079,29 @@
 %22)).end(
+%0A            
 ).select
@@ -1167,16 +1167,29 @@
 .buffer(
+%0A            
 ).select
@@ -1242,10 +1242,8 @@
 )).a
-%5C%0A
 ppen
@@ -1282,10 +1282,703 @@
 stream%0A%0A
+    def get_htdocs_dirs(self):%0A        %22%22%22%0A        Return a list of directories with static resources (such as style%0A        sheets, images, etc.)%0A        Each item in the list must be a %60(prefix, abspath)%60 tuple. The%0A        %60prefix%60 part defines the path in the URL that requests to these%0A        resources are prefixed with.%0A       %0A        The %60abspath%60 is the absolute path to the directory containing the%0A        resources on the local file system.%0A        %22%22%22%0A        return %5B(%22lightertheme%22, resource_filename(__name__, 'htdocs'))%5D%0A%0A    def get_templates_dirs(self):%0A        %22%22%22Return a list of directories containing the provided template%0A        files.%0A        %22%22%22%0A        return %5B%5D%0A
 %0A%0A

fix typo; also, plugin needs to declare its htdocs explicitly