Changeset 1226

Show
Ignore:
Timestamp:
09/01/06 08:28:40 (2 years ago)
Author:
Blackhex
Message:

DoxygenPlugin:

more_fixes-r1216.diff patch applied.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • doxygenplugin/0.10/doxygentrac/doxygentrac.py

    r1209 r1226  
    1919  add_stylesheet 
    2020from trac.Search import ISearchSource 
    21 from trac.wiki import IWikiSyntaxProvider, wiki_to_html 
    22 from trac.wiki.formatter import system_message 
     21from trac.wiki import WikiSystem, IWikiSyntaxProvider 
     22from trac.wiki.model import WikiPage 
     23from trac.wiki.formatter import wiki_to_html, system_message 
    2324from trac.util.html import html 
    2425 
     
    6162      """Default encoding used by the generated documentation files.""") 
    6263 
     64    SUMMARY_PAGES = """ 
     65    annotated classes dirs files functions globals hierarchy 
     66    index inherits main namespaces namespacemembers 
     67    """.split() 
     68 
    6369    # IPermissionRequestor methods 
    6470 
     
    7480        if req.perm.has_permission('DOXYGEN_VIEW'): 
    7581            # Return mainnav buttons. 
    76             yield 'mainnav', 'doxygen', html.a(self.title, 
    77               href = req.href.doxygen()) 
     82            yield 'mainnav', 'doxygen', \ 
     83                  html.a(self.title, href = req.href.doxygen()) 
    7884 
    7985    # IRequestHandler methods 
    8086 
    8187    def match_request(self, req): 
    82         ext = '|'.join(self.ext.split(' ')) 
    83         source_ext = '|'.join(self.source_ext.split(' ')) 
    84  
    8588        # Match documentation request. 
    86         self.log.debug(req.path_info) 
    87         match = re.match('^/doxygen(?:/?$|/([^/]*)(?:/?$|/(.*)$))', 
    88           req.path_info) 
    89         if match: 
    90             self.log.debug('matched group 1: %s' % (match.group(1),)) 
    91             self.log.debug('matched group 2: %s' % (match.group(2),)) 
    92  
    93             if not match.group(1) and not match.group(2): 
    94                 # Request for documentation index. 
    95                 req.args['path'] = os.path.join(self.base_path, 
    96                   self.default_doc) 
    97                 req.args['action'] = 'index' 
    98             else: 
    99                 # Get doc and file from request. 
    100                 if not match.group(2): 
    101                     doc = self.default_doc 
    102                     file = match.group(1) 
    103                 else: 
    104                     doc = match.group(1) 
    105                     file = match.group(2) 
    106  
    107                 self.log.debug('documentation: %s' % (doc,)) 
    108                 self.log.debug('file: %s' % (file,)) 
    109  
    110                 if re.match(r'''^search.php$''', file): 
    111                     # Request for searching. 
    112                     req.args['action'] = 'search' 
    113  
    114                 elif re.match(r'''^(.*)[.](%s)''' % (ext,), file): 
    115                     # Request for documentation file. 
    116                     path = os.path.join(self.base_path, doc, file) 
    117                     self.log.debug('path: %s' % (path,)) 
    118                     if os.path.exists(path): 
    119                         req.args['path'] = path 
    120                         req.args['action'] = 'file' 
    121                     else: 
    122                         req.args['action'] = 'search' 
    123                         req.args['query'] = file 
    124  
    125                 else: 
    126                     match = re.match(r'''^(.*)[.](%s)''' % (source_ext,), file) 
    127                     if match: 
    128                         # Request for source file documentation. 
    129                         path = os.path.join(self.base_path, doc, '%s_8%s.html' 
    130                           % (match.group(1), match.group(2))) 
    131                         self.log.debug('path: %s' % (path,)) 
    132                         if os.path.exists(path): 
    133                             req.args['path'] = path 
    134                             req.args['action'] = 'file' 
    135                         else: 
    136                             req.args['action'] = 'search' 
    137                             req.args['query'] = file 
    138  
    139                     else: 
    140                         path = os.path.join(self.base_path, doc, 'class%s.html' 
    141                           % (file,)) 
    142                         if os.path.exists(path): 
    143                             req.args['path'] = path 
    144                             req.args['action'] = 'file' 
    145                         else: 
    146                             path = os.path.join(self.base_path, doc, 
    147                               'struct%s.html' % (file,)) 
    148                             if os.path.exists(path): 
    149                                 req.args['path'] = path 
    150                                 req.args['action'] = 'file' 
    151                             else: 
    152                                 results = self._search_in_documentation(doc, 
    153                                   [file]) 
    154                                 for result in results: 
    155                                     self.log.debug(result) 
    156                                     if result['name'] == file: 
    157                                         req.redirect(req.href.doxygen(doc) 
    158                                           + '/' + result['url']) 
    159                                 req.args['action'] = 'search' 
    160                                 req.args['query'] = file 
    161             # Request matched. 
     89        if re.match(r'^/doxygen(?:$|/)', req.path_info): 
     90            if 'path' not in req.args: 
     91                segments = filter(None, req.path_info.split('/')) 
     92                segments = segments[1:] # ditch 'doxygen' 
     93                action, path, link = self._doxygen_lookup(segments) 
     94                if action: 
     95                    req.args['action'] = action 
     96                    if action == 'search' and path: 
     97                        req.args['query'] = path 
     98                    req.args['path'] = path 
    16299            return True 
    163  
    164         else: 
    165             # Request not matched. 
    166             return False 
    167  
     100             
    168101    def process_request(self, req): 
    169102        req.perm.assert_permission('DOXYGEN_VIEW') 
     
    173106        action = req.args.get('action') 
    174107 
    175         self.log.debug('path: %s' % (path,)) 
    176         self.log.debug('action: %s' % (action,)) 
     108        self.log.debug('Performing %s on "%s"' % (action or 'default', path)) 
    177109 
    178110        # Redirect search requests. 
    179111        if action == 'search': 
    180             req.redirect(req.href.search(q = req.args.get('query'), 
    181               doxygen = 'on')) 
    182  
    183         # Retrun apropriate content to type or search request 
    184         elif action == 'index': 
     112            req.redirect(req.href.search(q=req.args.get('query'), 
     113                                         doxygen='on')) 
     114 
     115        # Handle /doxygen request 
     116        if action == 'index': 
    185117            if self.wiki_index: 
    186                 # Get access to database 
    187                 db = self.env.get_db_cnx() 
    188                 cursor = db.cursor() 
    189  
    190                 # Get wiki index  # FIXME: use WikiPage() instead 
    191                 sql = "SELECT text FROM wiki WHERE name = %s" 
    192                 cursor.execute(sql, (self.wiki_index,)) 
    193                 text = system_message('Error', 'Wiki page %s does not exists' % 
    194                   self.wiki_index) 
    195                 for row in cursor: 
    196                     text = wiki_to_html(row[0], self.env, req) 
    197  
    198                 # Display wiki index page 
    199                 req.hdf['doxygen.text'] = text 
     118                if WikiSystem(self.env).has_page(self.wiki_index): 
     119                    req.redirect(req.href.wiki(self.wiki_index)) 
     120                # Display missing wiki 
     121                text = wiki_to_html('Doxygen index page [wiki:%s] does not ' 
     122                                    'exists' % self.wiki_index, self.env, req) 
     123                req.hdf['doxygen.text'] = system_message('Error', text) 
    200124                return 'doxygen.cs', 'text/html' 
    201             else: 
    202                 add_stylesheet(req, 'doxygen/css/doxygen.css') 
    203                 req.hdf['doxygen.path'] = path + '/' + self.index 
    204                 return 'doxygen.cs', 'text/html' 
    205  
    206         elif action == 'file': 
    207             type = mimetypes.guess_type(path)[0] 
    208  
    209             if type == 'text/html': 
    210                 add_stylesheet(req, 'doxygen/css/doxygen.css') 
    211                 req.hdf['doxygen.path'] = path 
    212                 return 'doxygen.cs', 'text/html' 
    213             else: 
    214                 req.send_file(path, type) 
     125            path = os.path.join(self.base_path, self.default_doc, self.index) 
     126 
     127        # view or redirect 
     128        mimetype = mimetypes.guess_type(path)[0] 
     129        if mimetype == 'text/html': 
     130            add_stylesheet(req, 'doxygen/css/doxygen.css') 
     131            req.hdf['doxygen.path'] = path 
     132            return 'doxygen.cs', 'text/html' 
     133        else: 
     134            req.send_file(path, mimetype)             
    215135 
    216136    # ITemplateProvider methods 
     
    261181 
    262182    # IWikiSyntaxProvider 
     183     
    263184    def get_link_resolvers(self): 
    264         yield ('doxygen', self._doxygen_link) 
     185        def doxygen_link(formatter, ns, params, label): 
     186            action, path, link = self._doxygen_lookup(params.split('/')) 
     187            if action in ('view', 'index', 'redirect'): 
     188                return html.a(label, title=params, 
     189                              href=formatter.href.doxygen(link, path=path)) 
     190            else: 
     191                return html.a(label, title=params, class_='missing', 
     192                              href=formatter.href.doxygen()) 
     193        yield ('doxygen', doxygen_link) 
    265194 
    266195    def get_wiki_syntax(self): 
     
    268197 
    269198    # internal methods 
     199 
     200    def _doxygen_lookup(self, segments): 
     201        """Try to interpret path components as a request for doxygen targets 
     202 
     203        Return an `(action,path,link)` pair, where: 
     204         - `action` describes what should be done (one of 'view', 
     205           'search' or 'index'), 
     206         - `path` is the location on disk of the resource. 
     207         - `link` is the link to the resource, relative to the 
     208           req.href.doxygen base, 
     209        """ 
     210        doc, file = segments[:-1], segments and segments[-1] 
     211        doc = doc and os.path.join(*doc) or self.default_doc 
     212        def lookup(file, category='undefined'): 
     213            path = os.path.join(self.base_path, doc, file) 
     214            self.log.debug('%s file "%s" (at %s)' % (category, file, path)) 
     215            return os.path.exists(path) and path, doc + '/' + file 
     216 
     217        if not file: 
     218            path, link = lookup('index.html', 'index') 
     219            return 'index', path, link 
     220 
     221        self.log.debug('looking up "%s" in documentation "%s"' % (file, doc)) 
     222 
     223        # Direct request for searching 
     224        if file == 'search.php': 
     225            return 'search', None, None 
     226 
     227        # Request for a documentation file. 
     228        doc_ext_re = '|'.join(self.ext.split(' ')) 
     229        if re.match(r'''^(.*)[.](%s)''' % doc_ext_re, file): 
     230            path, link = lookup(file, 'documentation') 
     231            if path: 
     232                return 'view', path, link 
     233            else: 
     234                return 'search', file, None 
     235 
     236        # Request for source file documentation. 
     237        source_ext_re = '|'.join(self.source_ext.split(' ')) 
     238        match = re.match(r'''^(.*)[.](%s)''' % source_ext_re, file) 
     239        if match: 
     240            basename, suffix = match.groups() 
     241            basename = basename.replace('_', '__') 
     242            path, link = lookup('%s_8%s.html' % (basename, suffix), 'source') 
     243            if path: 
     244                return 'view', path, link 
     245            else: 
     246                return 'search', file, None 
     247 
     248        # Request for summary pages 
     249        if file in self.SUMMARY_PAGES: 
     250            path, link = lookup(file + '.html', 'summary') 
     251            if path: 
     252                return 'view', path, link 
     253 
     254        # Request for a named object 
     255        # TODO: 
     256        #  - do something about dirs 
     257        #  - expand with enum, defs, etc. 
     258        #  - this doesn't work well with the CREATE_SUBDIRS Doxygen option 
     259        path, link = lookup('class%s.html' % file, 'class') 
     260        if not path: 
     261            path, link = lookup('struct%s.html' % file, 'struct') 
     262        if path: 
     263            return 'view', path, link 
     264 
     265        # Revert to search... 
     266        results = self._search_in_documentation(doc, [file]) 
     267        class_ref = file+' Class Reference' 
     268        for result in results: 
     269            self.log.debug('Reverted to search, found: ' + repr(result)) 
     270            name = result['name'] 
     271            if name == file or name == class_ref: 
     272                path, link = lookup(result['url']) 
     273                return 'redirect', path, link 
     274        self.log.debug('%s not found in %s' % (file, doc)) 
     275        return 'search', file, None 
     276 
    270277    def _search_in_documentation(self, doc, keywords): 
    271278        # Open index file for documentation 
     
    343350                        results[i]['rank'] = float(freq*multi) \ 
    344351                          / float(totalFreq) 
    345  
    346352        return results 
    347353 
     
    376382        return result 
    377383 
    378     def _doxygen_link(self, formatter, ns, params, label): 
    379         if ns == 'doxygen': 
    380             return html.a(label, href = formatter.href.doxygen(params), 
    381               title = params) 
    382         else: 
    383             return html.a(label, href = formatter.href.doxygen(), 
    384               title = params, class_ = 'missing') 
  • doxygenplugin/0.10/doxygentrac/htdocs/css/doxygen.css

    r1209 r1226  
    77{ 
    88  display: block; 
    9   margin: 0em
    10   padding: 0.5em 0em
     9  margin: 0
     10  padding: 0.5em 0 0 0
    1111  font-size: 10px; 
    1212  list-style: none; 
     
    1717{ 
    1818  border-right: 1px solid #d7d7d7; 
    19   padding: 0em 0.75em; 
     19  padding: 0 0.75em; 
    2020  white-space: nowrap; 
    2121} 
     22 
     23div.tabs form 
     24{ 
     25  float: right; 
     26} 
     27 
     28div.tabs label, div.tabs input 
     29{  
     30  padding: 0 0.75em; 
     31  font-size: 10px; 
     32} 
     33 
     34div#main div.nav 
     35{  
     36  margin: 0; 
     37  padding: 1em 0 0 0.75em; 
     38} 
     39 
     40h1 
     41{  
     42  margin: 1em; 
     43}