PK Z4^) ctxtnavadd/web_ui.pyfrom trac.core import *
from trac.web.chrome import INavigationContributor, ITemplateProvider
from trac.util import Markup
try:
from trac.web.chrome import add_javascript
have_aj = True
except ImportError:
have_aj = False
from ctxtnavadd.api import ICtxtnavAdder
inc_script = """"""
class CtxtnavAddModule(Component):
"""An evil module that adds buttons to the ctxtnav bar of other plugins."""
implements(INavigationContributor, ITemplateProvider)
ctxtnav_adders = ExtensionPoint(ICtxtnavAdder)
# INavigationContributor methods
def get_active_navigation_item(self, req):
return '' # This is never called
def get_navigation_items(self, req):
evil_js = '/'.join(['ctxtnavadd','js','ctxtnavadd.js'])
if have_aj:
add_javascript(req, evil_js)
else:
self._add_js_inc(req, req.href.chrome(evil_js))
self._add_js(req,self._make_js(req))
return [] # This returns no buttons
# ITemplateProvider methods
def get_templates_dirs(self):
"""
Return the absolute path of the directory containing the provided
ClearSilver templates.
"""
from pkg_resources import resource_filename
#return [resource_filename(__name__, 'templates')]
return []
def get_htdocs_dirs(self):
"""
Return a list of directories with static resources (such as style
sheets, images, etc.)
Each item in the list must be a `(prefix, abspath)` tuple. The
`prefix` part defines the path in the URL that requests to these
resources are prefixed with.
The `abspath` is the absolute path to the directory containing the
resources on the local file system.
"""
from pkg_resources import resource_filename
return [('ctxtnavadd', resource_filename(__name__, 'htdocs'))]
# Internal methods
def _add_js(self, req, data):
"""Add javascript to a page via hdf['project.footer']"""
footer = req.hdf['project.footer']
footer += data
req.hdf['project.footer'] = Markup(footer)
def _add_js_inc(self, req, file):
"""Add a javascript include via hdf['project.footer']"""
self._add_js(req, inc_script%file)
def _make_js(self, req):
"""Generate the needed Javascript."""
adds = []
for adder in self.ctxtnav_adders:
if adder.match_ctxtnav_add(req):
for add in adder.get_ctxtnav_adds(req):
if isinstance(add, Markup):
adds.append(Markup(add.replace("'","\\'")))
else:
href, text = add
adds.append(Markup('%s'%(href,Markup.escape(text,False))))
js = ""
for add in adds:
js += "add_ctxtnav('%s');\n"%add
return """"""%js
PK ʩ4p_ _ ctxtnavadd/api.pyfrom trac.core import *
class ICtxtnavAdder(Interface):
"""An extension point interface to adding ctxtnav entries."""
def match_ctxtnav_add(req):
"""Return True if you want to alter this requests ctxtnav bar."""
def get_ctxtnav_adds(req):
"""Return a list of the form (path, text) to be added to the bar."""
PK i4 ctxtnavadd/__init__.pyPK pj4hIPE E ctxtnavadd/web_ui.pyc;
Dc @ s d k Td k l Z l Z d k l Z y d k l Z e Z Wn e j
o
e
Z n Xd k l Z d Z
d e f d YZ d S( ( s *( s INavigationContributors ITemplateProvider( s Markup( s add_javascript( s
ICtxtnavAdders1 s CtxtnavAddModulec B sf t Z d Z e e e e e Z d Z d Z
d Z d Z d Z
d Z d Z RS( sE An evil module that adds buttons to the ctxtnav bar of other plugins.c C s d Sd S( Ns ( ( s selfs req( ( s/ build/bdist.linux-i686/egg/ctxtnavadd/web_ui.pys get_active_navigation_item s c C sm d i d d d g } t o t | | n | i | | i i | | i | | i
| g Sd S( Ns /s
ctxtnavadds jss
ctxtnavadd.js( s joins evil_jss have_ajs add_javascripts reqs selfs _add_js_incs hrefs chromes _add_jss _make_js( s selfs reqs evil_js( ( s/ build/bdist.linux-i686/egg/ctxtnavadd/web_ui.pys get_navigation_items s c C s d k l } g Sd S( sr
Return the absolute path of the directory containing the provided
ClearSilver templates.
( s resource_filenameN( s
pkg_resourcess resource_filename( s selfs resource_filename( ( s/ build/bdist.linux-i686/egg/ctxtnavadd/web_ui.pys get_templates_dirs% s
c C s' d k l } d | t d f g Sd S( s
Return a list of directories with static resources (such as style
sheets, images, etc.)
Each item in the list must be a `(prefix, abspath)` tuple. The
`prefix` part defines the path in the URL that requests to these
resources are prefixed with.
The `abspath` is the absolute path to the directory containing the
resources on the local file system.
( s resource_filenames
ctxtnavadds htdocsN( s
pkg_resourcess resource_filenames __name__( s selfs resource_filename( ( s/ build/bdist.linux-i686/egg/ctxtnavadd/web_ui.pys get_htdocs_dirs. s
c C s. | i d } | | 7} t | | i d