1 """
2 MoinMoin - IncludePages macro
3
4 Copyright (c) 2002 by Michael Reinsch <mr@uue.org>
5 All rights reserved, see COPYING for details.
6
7 Code based on the MoinMoin PageList macro
8 Copyright (c) 2000, 2001, 2002 by Jürgen Hermann <jh@web.de>
9
10 This macro includes the formatted content of the given pages, following
11 recursive includes if encountered. Cycles are detected!
12
13 It uses the MoinMoin Include macro which does the real work.
14
15 Usage:
16 [[IncludePages(pagepattern,level)]]
17
18 pagepattern Pattern of the page(s) to include
19 level Level (1..5) of the generated heading (optional)
20
21 The headings for the included pages will be generated from the page
22 names
23
24 Examples:
25 [[IncludePages(FooBar/20.*)]]
26 -- includes all pages which start with FooBar/20 this is usefull
27 in combination with the MonthCalendar macro
28
29 [[IncludePages(FooBar/20.*, 2)]]
30 -- set level to 2 (default is 1)
31
32 $Id$
33 """
34
35 import re
36 from MoinMoin import user
37 from MoinMoin import config
38 from MoinMoin import wikiutil
39 from MoinMoin.i18n import _
40 import MoinMoin.macro.Include
41
42 _arg_level = r',\s*(?P<level>\d+)'
43 _args_re_pattern = r'^(?P<pattern>[^,]+)(%s)?$' % (_arg_level,)
44
45 def execute(macro, text, args_re=re.compile(_args_re_pattern)):
46 ret = ''
47
48
49 args = args_re.match(text)
50 if not args:
51 return ('<p><strong class="error">%s</strong></p>' %
52 _('Invalid include arguments "%s"!')) % (text,)
53
54
55 inc_pattern = args.group('pattern')
56 if args.group('level'):
57 level = int(args.group('level'))
58 else:
59 level = 1
60
61 try:
62 needle_re = re.compile(inc_pattern, re.IGNORECASE)
63 except re.error, e:
64 return ('<p><strong class="error">%s</strong></p>' %
65 _("ERROR in regex '%s'") % (inc_pattern,), e)
66
67 all_pages = wikiutil.getPageList(config.text_dir)
68 hits = filter(needle_re.search, all_pages)
69 hits.sort()
70
71 for inc_name in hits:
72 params = '%s,,%s' % (inc_name, level)
73 ret = ret +"<p>"+ MoinMoin.macro.Include.execute(macro, params) +"\n"
74
75
76 return ret
MoinMoin: macro/IncludePages.py (last edited 2007-10-29 19:08:21 by localhost)