Changeset 2055

Show
Ignore:
Timestamp:
02/27/07 18:21:29 (2 years ago)
Author:
coderanger
Message:

TagsPlugin:

New UI based around IStreamFilter.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tagsplugin/branches/filter/tractags/web_ui.py

    r1836 r2055  
    22from trac.web.main import IRequestHandler 
    33from trac.web.chrome import ITemplateProvider, INavigationContributor 
     4from trac.web.api import IStreamFilter, IRequestFilter 
    45from trac.util import Markup 
    56from StringIO import StringIO 
    67from trac.wiki.web_ui import WikiModule 
    78from trac.wiki.formatter import wiki_to_oneliner 
     9from genshi.builder import tag 
     10from genshi.core import START, END 
    811from tractags.expr import Expression 
     12 
     13from api import TagEngine 
     14 
    915import re 
     16 
     17 
     18 
    1019try: 
    1120    set = set 
     
    6877            return 'tagswiki.cs', None 
    6978        return result 
     79 
     80class TagsWikiFilter(Component): 
     81 
     82    implements(IStreamFilter, IRequestFilter) 
     83     
     84    # IStreamFilter methods 
     85    def match_stream(self, req, stream, method): 
     86        return req.path_info.startswith('/wiki') and \ 
     87               req.args.get('action') == 'edit' and \ 
     88               method == 'xhtml' 
     89                
     90    def process_stream(self, req, stream, method): 
     91        page_name = req.path_info[6:] or 'WikiStart' 
     92        stage = 1 
     93        elm = tag.div([tag.label('Tag under: (',  
     94                                 tag.a('view all tags', href=req.href.tags()), 
     95                                  ')',  
     96                                  for_='tags'),  
     97                       tag.br(),  
     98                       tag.input(title='Comma separated list of tags', 
     99                                 type='text', 
     100                                 id='tags', 
     101                                 size='30', 
     102                                 name='tags', 
     103                                 value=', '.join(TagEngine(self.env).tagspace.wiki.get_tags([page_name])) 
     104                                ), 
     105                      ], class_='field') 
     106                       
     107        for kind, data, pos in stream:             
     108            yield kind, data, pos 
     109            if stage == 1 and \ 
     110               kind is START and \ 
     111               data[0].localname == 'input' and \ 
     112               data[1].get('id') == 'comment': 
     113                stage = 2 
     114            elif stage == 2 and \ 
     115                 kind is END and \ 
     116                 data.localname == 'div': 
     117                for e in elm.generate(): 
     118                    yield e 
     119                stage = None 
     120             
     121    # IRequestFilter methods 
     122    def pre_process_request(self, req, handler): 
     123         
    70124 
    71125class TagsModule(Component):