Ticket #7124: trac-0.13.dev-wiki-macros.patch
| File trac-0.13.dev-wiki-macros.patch, 4.9 KB (added by mark.m.mcmahon@…, 21 months ago) |
|---|
-
macros.py
19 19 import os 20 20 import re 21 21 from StringIO import StringIO 22 import fnmatch 22 23 23 24 from genshi.builder import Element, tag 24 25 from genshi.core import Markup … … 76 77 parameter is omitted, all pages are listed. 77 78 If the prefix is specified, a second argument of value 'hideprefix' 78 79 can be given as well, in order to remove that prefix from the output. 80 Any includes provided are processed before excludes. 79 81 80 82 Alternate `format` and `depth` named parameters can be specified: 81 83 - `format=compact`: The pages are displayed as comma-separated links. … … 89 91 only toplevel pages will be shown, if set to 1, only immediate 90 92 children pages will be shown, etc. If not set, or set to -1, 91 93 all pages in the hierarchy will be shown. 94 - `exclude=page1:page*2`: exclude pages which match any item in the colon 95 separated list of pages. 96 - `include=page1:page*2`: include pages wihch match any item in the colon 97 separated list of pages 92 98 """ 93 99 94 100 SPLIT_RE = re.compile(r"([/ 0-9.]+)") … … 102 108 start = prefix and prefix.count('/') or 0 103 109 format = kw.get('format', '') 104 110 111 def parse_include_exclude(in_or_exclude): 112 return [inc.strip() 113 for inc in in_or_exclude.split(':') 114 if inc.strip()] 115 includes = parse_include_exclude(kw.get('include', '')) 116 excludes = parse_include_exclude(kw.get('exclude', '')) 117 105 118 if hideprefix: 106 119 omitprefix = lambda page: page[len(prefix):] 107 120 else: … … 109 122 110 123 wiki = formatter.wiki 111 124 112 pages = sorted(page for page in wiki.get_pages(prefix) \113 if (depth < 0 or depth >= page.count('/') - start)114 and 'WIKI_VIEW' in formatter.perm('wiki', page))125 pages = [page for page in wiki.get_pages(prefix) 126 if (depth < 0 or depth >= page.count('/') - start) 127 and 'WIKI_VIEW' in formatter.perm('wiki', page)] 115 128 129 filtered_pages = set() 130 131 if includes: 132 for include in includes: 133 filtered_pages.update(fnmatch.filter(pages, include)) 134 else: 135 filtered_pages = set(pages) 136 137 for exclude in excludes: 138 filtered_pages.difference_update( 139 fnmatch.filter(filtered_pages, exclude)) 140 141 pages = sorted(filtered_pages) 142 116 143 if format == 'compact': 117 144 return tag( 118 145 separated((tag.a(wiki.format_page_name(omitprefix(p)), -
tests/macros.py
213 213 </p><div class="titleindex"><ul><li><strong>0.11</strong><ul><li><strong>Group</strong><ul><li><a href="/wiki/0.11/GroupOne">0.11/GroupOne</a></li><li><a href="/wiki/0.11/GroupTwo">0.11/GroupTwo</a></li></ul></li><li><a href="/wiki/0.11/Test">0.11/Test</a></li></ul></li><li><strong>Test</strong><ul><li><strong>0.11Abc</strong><ul><li><a href="/wiki/Test0.11/Abc">Test0.11/Abc</a></li><li><a href="/wiki/Test0.11Abc">Test0.11Abc</a></li></ul></li><li><strong>0.12</strong><ul><li><a href="/wiki/Test0.12Def">Test0.12Def</a></li><li><a href="/wiki/Test0.12Ijk">Test0.12Ijk</a></li></ul></li><li><strong>0.13</strong><ul><li><a href="/wiki/Test0.13alpha">Test0.13alpha</a></li><li><a href="/wiki/Test0.13beta">Test0.13beta</a></li></ul></li><li><a href="/wiki/Test0.131">Test0.131</a></li><li><a href="/wiki/Test2">Test2</a></li><li><a href="/wiki/TestTest">TestTest</a></li><li><a href="/wiki/TestThing">TestThing</a></li></ul></li><li><a href="/wiki/WikiStart">WikiStart</a></li></ul></div><p> 214 214 </p> 215 215 ------------------------------ 216 ============================== TitleIndex, compact format with prefix hidden, including Test0.13* 217 [[TitleIndex(Test,format=compact,include=*0.13*)]] 218 ------------------------------ 219 <p> 220 <a href="/wiki/Test0.131">Test0.131</a>, <a href="/wiki/Test0.13alpha">Test0.13alpha</a>, <a href="/wiki/Test0.13beta">Test0.13beta</a> 221 </p> 222 ------------------------------ 223 ============================== TitleIndex, compact format, excluding various topics 224 [[TitleIndex(Test,format=compact,exclude=Test0.13*:*0.11*:Test2:Test*i*)]] 225 ------------------------------ 226 <p> 227 <a href="/wiki/Test0.12Def">Test0.12Def</a>, <a href="/wiki/TestTest">TestTest</a> 228 </p> 229 ------------------------------ 230 ============================== TitleIndex, compact format, including and excluding various topics 231 [[TitleIndex(format=compact,include=*Group*:test2,exclude=*one)]] 232 ------------------------------ 233 <p> 234 <a href="/wiki/0.11/GroupTwo">0.11/GroupTwo</a>, <a href="/wiki/Test2">Test2</a> 235 </p> 236 ------------------------------ 216 237 """ 217 238 218 239 def titleindex4_setup(tc):
