1 """
2 MoinMoin - IncludeTeasers macro
3
4 Copyright (c) 2003 by Th.Fanslau <tfanslau@gmx.de>
5 All rights reserved, see COPYING for details.
6
7 This macro calls "IncludeTeaser" for a set of Pages that match a certain
8 regular Expression.
9
10 Usage:
11 [[IncludeTeasers(pagepattern, max)]]
12
13 pagepattern Pattern of the page(s) to include
14 max Number of Top Files to include
15
16 Examples:
17 [[IncludeTeaser(FooBar)]]
18 -- includes page FooBar
19
20 $Id$
21 """
22
23 import re
24 from MoinMoin import wikiutil
25 from MoinMoin import config
26 from MoinMoin.i18n import _
27 import MoinMoin.macro.IncludeTeaser
28
29 _arg_max = r',\s*(?P<max>\d+)'
30 _args_re_pattern = r'^(?P<pattern>[^,]+)(%s)?$' % (_arg_max,)
31
32 def execute(macro, text, args_re=re.compile(_args_re_pattern)):
33 ret = ''
34
35
36 args = args_re.match(text)
37 if not args:
38 return ('<p><strong class="error">%s</strong></p>' % _('Invalid include arguments "%s"!')) % (text,)
39
40
41 inc_pattern = args.group('pattern')
42 if args.group('max'):
43 max = int(args.group('max'))
44 else:
45 max = 1
46
47 try:
48 needle_re = re.compile(inc_pattern, re.IGNORECASE)
49 except re.error, e:
50 return ('<p><strong class="error">%s</strong></p>' %
51 _("ERROR in regex '%s'") % (inc_pattern,), e)
52
53 all_pages = wikiutil.getPageList(config.text_dir)
54 hits = filter(needle_re.search, all_pages)
55 hits.sort()
56 hits.reverse()
57
58 if max > len(hits):
59 max = len(hits)
60
61 for i in range(0, max):
62 params = hits[i]
63 ret = ret + MoinMoin.macro.IncludeTeaser.execute(macro, params)
64
65
66 return ret
MoinMoin: macro/InsertTeasers.py (last edited 2007-10-29 19:09:18 by localhost)