Changeset 3085


Ignore:
Timestamp:
03/24/06 17:53:30 (7 years ago)
Author:
moschny
Message:

Cleanup, small enhancements.

  • Import cStringIO, if available, instead of StringIO.
  • Use a StringIO buffer for assembling the TOC.
  • Bugfix for preview mode: Don't use text from hdf, but from request itself.
  • setyp.py: Get the version from the tracnav source.
  • Increment the version number.
Location:
trac/plugins/tracnav
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trac/plugins/tracnav/setup.py

    r3084 r3085  
    22 
    33from setuptools import setup 
    4  
    5 PACKAGE = 'TracNav' 
    6 VERSION = '3.90' 
     4from tracnav.tracnav import __version__ as version 
    75 
    86setup( 
    9     name = PACKAGE, 
    10     version = VERSION, 
     7    name = 'TracNav', 
     8    version = version, 
    119    packages = ['tracnav'], 
    1210    package_data = { 'tracnav': ['htdocs/css/*.css'] }, 
    13     author = 'Bernhard Haumacher, Thomas Moschny', 
     11    author = 'Bernhard Haumacher', 
     12    author_email = 'haui@haumacher.de', 
     13    maintainer = 'Thomas Moschny', 
     14    maintainer_email = 'moschny@ipd.uni-karlsruhe.de', 
    1415    url = 'http://svn.ipd.uka.de/trac/javaparty/wiki/TracNav', 
    1516    description = 'The navigation bar for Trac', 
    16     entry_points={'trac.plugins': '%s = tracnav' % PACKAGE}, 
    17     licence = 'GPL', 
     17    entry_points={'trac.plugins': 'TracNav = tracnav'}, 
     18    keywords = 'trac toc', 
     19    license = 'GPL', 
    1820) 
  • trac/plugins/tracnav/tracnav/tracnav.py

    • Property svn:keywords changed from Id to Id LastChangedRevision
    r3083 r3085  
    5555 
    5656""" 
    57  
    58 __revision__ = "$Id$" 
     57__id__        = '$Id$' 
     58__version__   = '3.91' 
     59__revision__  = '$LastChangedRevision$' 
    5960 
    6061import re 
    61 from trac.core import Component 
     62from trac.core import Component, implements 
    6263from trac.wiki.api import WikiSystem, IWikiMacroProvider 
    63 from trac.web.chrome import ITemplateProvider 
     64from trac.web.chrome import ITemplateProvider, add_stylesheet 
    6465from trac.wiki.model import WikiPage 
    6566from trac.wiki.formatter import Formatter, OneLinerFormatter 
    66 from StringIO import StringIO 
     67try: 
     68    from cStringIO import StringIO 
     69except ImportError: 
     70    from StringIO import StringIO 
     71 
    6772 
    6873TRACNAVHOME = "http://svn.ipd.uka.de/trac/javaparty/wiki/TracNav" 
     
    110115class TracNav(Component): 
    111116 
    112     from trac.core import implements 
    113117    implements(IWikiMacroProvider, ITemplateProvider) 
    114118 
     
    117121        Fetch the wiki page containing the toc, if available. 
    118122        """ 
    119         preview = req.hdf.getValue('args.preview', "") 
    120  
    121         if  preview: 
    122             cur_path = req.hdf.getValue('HTTP.PathInfo', '') 
    123             toc_path = "/wiki/" + name 
    124             if cur_path == toc_path: 
    125                 return req.hdf.getValue('args.text', '') 
    126  
    127         if WikiSystem(self.env).has_page(name): 
     123        preview = req.args.get('preview', '') 
     124        curpage = req.args.get('page') 
     125 
     126        if preview and name == curpage: 
     127            return req.args.get('text', '') 
     128        elif WikiSystem(self.env).has_page(name): 
    128129            return WikiPage(self.env, name).text 
    129130        else: 
     
    159160 
    160161    def _parse_toc(self, gen, next_indent, level = 0): 
     162        """ 
     163        Construct the toc tree at the given level. 
     164        """ 
    161165        toclist = [] 
    162166        if next_indent > level: 
     
    193197        Main routine of the wiki macro. 
    194198        """ 
    195         curpage = req.hdf.getValue('wiki.page_name', "") 
    196  
    197         # split the argument to get the wiki page names to include 
     199        out = StringIO() 
     200         
     201        # header 
     202        col = 0 
     203        out.write('%s<div class="wiki-toc trac-nav">\n' % self.i(col)) 
     204        col += 1 
     205        out.write('%s<h2><a href="%s">TracNav</a> menu</h2>\n' % \ 
     206                  (self.i(col), TRACNAVHOME)) 
     207 
     208        # add TOCs 
     209        curpage = req.args.get('page','') 
    198210        names = (args or "TOC").split('|') 
    199211 
    200         # Parsing the tocS 
    201         tocs = [] 
    202212        for name in names: 
    203213            toc_text = self.get_toc(req, name) 
     
    205215            if not toc: 
    206216                toc = self.parse_toc(' * TOC "%s" is empty!' % name) 
    207             tocs.append((name, toc)) 
    208  
    209         col = 0 
    210         html = '%s<div class="wiki-toc trac-nav">\n' % self.indentation(col) 
    211         col += 1 
    212         html += '%s<h2><a href="%s">TracNav</a> menu</h2>\n' % \ 
    213                 (self.indentation(col), TRACNAVHOME) 
    214  
    215         for name, toc in tocs: 
    216217            (found, filtered) = self.filter_toc(curpage, toc) 
    217218            if found: 
    218                 html += self.display_all(req, name, filtered, col) 
     219                self.display_all(out, req, name, filtered, col) 
    219220            else: 
    220                 html += self.display_all(req, name, toc, col) 
     221                self.display_all(out, req, name, toc, col) 
     222 
     223        # footer  
    221224        col -= 1 
    222         html += '%s</div>\n' % self.indentation(col) 
    223  
    224         from trac.web.chrome import add_stylesheet 
     225        out.write('%s</div>\n' % self.i(col)) 
     226 
     227        # add our stylesheet 
    225228        add_stylesheet(req, 'tracnav/css/tracnav.css') 
    226         return html 
     229 
     230        # emit  
     231        return out.getvalue() 
    227232 
    228233 
     
    251256 
    252257 
    253     def indentation(self, col): 
     258    def i(self, col): 
    254259        return ' ' * col 
    255260 
    256261 
    257     def display_all(self, req, name, toc, col): 
    258         preview = req.hdf.getValue('args.preview', "") 
    259         curpage = req.hdf.getValue('wiki.page_name', "") 
    260         html = '' 
     262    def display_all(self, out, req, name, toc, col): 
     263        preview = req.hdf.getValue('args.preview', '') 
     264        curpage = req.hdf.getValue('wiki.page_name', '') 
    261265 
    262266        if (not preview) and req.hdf.getValue('trac.acl.WIKI_MODIFY', ''): 
    263             html += '%s<div class="edit"><a href="%s?edit=yes">edit</a></div>\n' % \ 
    264                     (self.indentation(col), self.env.href.wiki(name)) 
    265         html += '%s<ul>\n' % self.indentation(col) 
     267            out.write('%s<div class="edit"><a href="%s?edit=yes">edit</a></div>\n' % \ 
     268                    (self.i(col), self.env.href.wiki(name))) 
     269        out.write('%s<ul>\n' % self.i(col)) 
    266270        col += 1 
    267         html += self.display(curpage, toc, 0, col) 
     271        self.display(out, curpage, toc, 0, col) 
    268272        col -= 1 
    269         html += '%s</ul>\n' % self.indentation(col) 
    270         return html 
    271  
    272  
    273     def display(self, curpage, toc, depth, col): 
    274         html = '' 
     273        out.write('%s</ul>\n' % self.i(col)) 
     274 
     275 
     276    def display(self, out, curpage, toc, depth, col): 
    275277        for name, title, sub in toc: 
    276278            li_style = ' style="padding-left: %dem;"' % (depth + 1) 
     
    280282                else: 
    281283                    cls = '' 
    282                 html += '%s<li%s%s>%s</li>\n' % \ 
    283                         (self.indentation(col), li_style, cls, title) 
     284                out.write('%s<li%s%s>%s</li>\n' % \ 
     285                        (self.i(col), li_style, cls, title)) 
    284286            else: 
    285                 html += '%s<li%s>\n' % (self.indentation(col), li_style) 
     287                out.write('%s<li%s>\n' % (self.i(col), li_style)) 
    286288                col += 1 
    287289                if name == None or sub: 
    288                     html += '%s<h4>%s</h4>\n' % \ 
    289                             (self.indentation(col), title) 
     290                    out.write('%s<h4>%s</h4>\n' % (self.i(col), title)) 
    290291                else: 
    291                     html += '%s<h4>%s...</h4>\n' % \ 
    292                             (self.indentation(col), title) 
     292                    out.write('%s<h4>%s...</h4>\n' % (self.i(col), title)) 
    293293                col -= 1 
    294                 html += '%s</li>\n' % self.indentation(col) 
     294                out.write('%s</li>\n' % self.i(col)) 
    295295                if len(sub) > 0: 
    296                     html += self.display(curpage, sub, depth + 1, col) 
    297         return html 
     296                    self.display(out, curpage, sub, depth + 1, col) 
    298297 
    299298 
Note: See TracChangeset for help on using the changeset viewer.