Injecting static content in TurboGears

Something that you usually need to do when providing a library or a reusable wsgi application is installing static data with the library itself. This can be quickly performed by adding something like package_data = {”:[‘*.html’, ‘*.js’, ‘*.css’, ‘*.png’]} to your But then how can we let our turbogears application serve that? For html files (genshi templates) the solution is quite simple, you can just expose them by using @expose(‘librarypackage.templatesdir.template’). For example supposing we are installing libcool with its templates in libcool/templates you can do @expose(‘libcool.templates.index’) For js and css files you can add them to your pages by creating a tw.api.JSLink or tw.api.CSSLink object. Just create inside your library something like: cool_js =¬†tw.api.JSLink(modname = __name__, filename = ‘static/cool.js’) […]