Turbogears Local Widget Links

When writing a widget that you’re only going to use in your own project, you might still want to take advantage of the automatic javascript link insertion. This little class lets you do that:

`

from turbogears import startup
from turbogears.widgets.base import JSLink

class LocalJSLink(JSLink):
    register = False
    
    def __init__(self, name):
        self.mod = None
        self.name = name

    def update_data(self, d):
        super(JSLink, self).update_data(d)
        d["link"] = "/%sstatic/javascript/%s" % (startup.webpath, self.name)

`

To use this, just place your javascript in your /static/javascript directory and add a LocalJSLink for the file you want to your widget:

javascript = [LocalJSLink("myjsfile.js")]