On Mon, Nov 29, 2010 at 1:15 PM, Chris Nelson <[email protected]> wrote:

At the top of your module add:

from pkg_resources import resource_filename
from trac.web.chrome import ITemplateProvider

> class TaacJSGanttSupport(Component):

You also need to implement ITemplateProvider. Despite the name it's
this that tells trac where your static resources are.

    implements(IRequestFilter, ITemplateProvider)

    def get_htdocs_dirs(self):
        return [('tracjsgnatt', resource_filename(__name__, 'htdocs'))]

    def get_templates_dirs(self):
        return []

>    def post_process_request(self, req, template, data, content_type):
>        add_script(req, '/tracjsgantt/jsgantt.js')
>        add_stylesheet(req, '/tracjsgantt/jsgantt.css')
>        return template, data, content_type

You then call add_script() and add_stylesheet() without a leading '/'. So:

    def post_process_request(self, req, template, data, content_type):
        add_script(req, 'tracjsgantt/jsgantt.js')
        add_stylesheet(req, 'tracjsgantt/jsgantt.css')
        return template, data, content_type

> (I've tried that with and without the leading / in the names.)
>
> When I run this, the HTML includes:
>
>  <script type="text/javascript" src="/trac/tracjsgantt/jsgantt.js"></script>
>
> But looking for jsgantt.js in my Trac environment finds no files.  If I 
> manually copy it where I think it should be, it still doesn't work.
>
> Is there something wrong with my code?  When looking for scripts and style 
> sheets, what is /trac?  How do I make my setup process put files there?  
> Shouldn't setup put it in the egg?
>

The steps above should sort you.

-- 
Alex Willmer <[email protected]>
http://moreati.org.uk/blog http://twitter.com/moreati

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/trac-dev?hl=en.

Reply via email to