Anonymous avatar Anonymous committed 6f79fb2

Added options for WikiHistoryMacro

Comments (0)

Files changed (3)

trac-dev/tracbm/setup.py

 
 versions = [
     (1, 0, 0),
+    (1, 0, 1),
     ]
     
 latest = '.'.join(str(x) for x in versions[-1])

trac-dev/tracbm/tracbm/config.py

 __author__ = 'Olemis Lang'
 
 from trac.core import TracError
-from trac.resource import Resource
-from trac.util.datefmt import format_datetime, localtz
 from trac.util.text import to_unicode
-from trac.wiki.api import IWikiMacroProvider, WikiSystem, parse_args
+from trac.wiki.api import parse_args
 from trac.wiki.macros import WikiMacroBase
-from trac.wiki.model import WikiPage
 
-from genshi.builder import Element, tag
+from genshi.builder import tag
 
 class ConfigOptionMacro(WikiMacroBase):
     r"""Insert configuration options in Wiki pages
     
     Usage is as follows.
     
-    [[ConfigOption(section, name, type=option_type, sep=char)]]
+    `[[ConfigOption(section, name, type=option_type, sep=char)]]`
     
     ''section'' :  the section in trac.ini (mandatory)
     ''name'' :     option name (mandatory)

trac-dev/tracbm/tracbm/wiki.py

 __author__ = 'Olemis Lang'
 
 from trac.core import TracError
+from trac.config import ListOption, Option
 from trac.resource import Resource
 from trac.util.datefmt import format_datetime, localtz
 from trac.util.text import to_unicode
-from trac.wiki.api import IWikiMacroProvider, WikiSystem, parse_args
+from trac.wiki.api import parse_args
 from trac.wiki.macros import WikiMacroBase
 from trac.wiki.model import WikiPage
 
-from genshi.builder import Element, tag
+from genshi.builder import tag
 
 class WikiHistoryMacro(WikiMacroBase):
     r"""Embed information about wiki changelog in wiki pages.
     If invoked without keyword arguments then full 
     changelog is shown inside a table with columns 
-    `Fecha`, `Version`, `Descripcion, `Autor`. Please  
-    read below for further details.
+    `Fecha`, `Version`, `Descripcion, `Autor`. Column labels 
+    may be customized using `chgtable_titles` option in `wiki` 
+    section. CSS class used to render the table may be specified 
+    through `chgtable_class` option in `wiki` section 
+    (see TracIni if you need help). Please read below for further 
+    details.
     
     Usage is as follows (all fields are optional).
     
-    [[WikiHistory(pagename, version, attr=attr_name, cols=columns)]]
+    `[[WikiHistory(pagename, version, attr=attr_name, cols=columns)]]`
     
     ''pagename'' : the name of target Wiki page. If missing or empty 
                    and a wiki page is being rendered then it defaults to 
                    specific columns (order matters). Identifiers are 
                    the same supported for `attr` parameter.
     """
+    
+    table_class = Option('wiki', 'chgtable_class', 'listing', 
+                                doc="""CSS class to render wiki history table""")
+    labels = ListOption('wiki', 'chgtable_titles', u'Version, Date, Author, Comment', 
+                                keep_empty=True,
+                                doc="""Comma separated list of column labels for """
+                                """version, time, author, and comment (in that order)""",
+                                )
+    
     def expand_macro(self, formatter, name, content):
         args, kw = parse_args(content)
         attr, cols = [kw.get(k) for k in ('attr', 'cols')]
             pagename = pagename or (is_wiki and resource.id or 'WikiStart')
             version = (args[1:2] or [None])[0]
             page = WikiPage(self.env, pagename, version=version)
-        ATTR_LABELS = [u'Version', u'Fecha', u'Autor', u'Descripcion',]
         ALL_ATTRS = ['version', 'time', 'author', 'comment']
+        ATTR_LABELS = self.labels
+        ATTR_LABELS = (len(ATTR_LABELS) == len(ALL_ATTRS)) and \
+                        ATTR_LABELS or [u'Version', u'Date', u'Author', u'Comment']
         
         def format_verinfo(value, attridx):
             return {
             def ver_row(verinfo):
                 return tag.tr([verinfo[c] for c in cols])
             return tag.table(
-                            [tag.tr(
-                                    [tag.th(tag.i(h))
-                                        for h in (ATTR_LABELS[c] for c in cols)]
-                                   )] +
-                            [tag.tr(
-                                        [
-                                            tag.td(format_verinfo(x[c], c))
+                            tag.thead([tag.tr(
+                                        [tag.th(tag.i(h or ''))
+                                            for h in (ATTR_LABELS[c] for c in cols)]
+                                   )]),
+                            tag.tbody([tag.tr(
+                                        [tag.td(format_verinfo(x[c], c))
                                                 for c in cols]
-                                    ) for x in page.get_history()], 
-                            class_='wiki', align='center')
+                                    ) for x in page.get_history()]), 
+                            class_=self.table_class, align='center')
         else :
             try :
                 attridx = ALL_ATTRS.index(attr)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.