1 """
2 MoinMoin - PartialInclude Macro
3
4 Written by Seth Shikora
5 For Personal Telco http://www.personaltelco.net/
6
7 Modified by Thomas Waldmann, http://linuxwiki.de/ThomasWaldmann
8 for usage of regex to find multiple pages. You can use that e.g.
9 for MonthCalendar or News overviews.
10
11 Released into the public domain.
12
13 You call it like [[PartialInclude(regex)]].
14
15 -- Adam Shand http://adam.shand.net/
16
17 """
18
19 from MoinMoin.Page import Page
20 from MoinMoin import config
21 from MoinMoin import wikiutil
22
23 import sys, cStringIO, re
24
25 def execute(macro, args):
26 _ = macro.request.getText
27
28 if not args:
29 return '<p><strong class="error">%s</strong></p>' % _('You must supply a regular expression as argument.')
30
31 try:
32 pagename_re = re.compile(args)
33 except re.error, e:
34 return '<p><strong class="error">%s</strong></p>' % _('Error in regular expression.')
35
36 pagelist = wikiutil.getPageList(config.text_dir)
37 pagelist = filter(pagename_re.search, pagelist)
38 pagelist.sort()
39
40 content = ''
41 for pagename in pagelist:
42 raw = Page(pagename).get_raw_body()
43 part = raw.splitlines()
44 lines = []
45 for line in part:
46 index = line.find("----")
47 if index != -1:
48 break
49 lines.append(line)
50 p = Page(pagename)
51 p.set_raw_body('\n'.join(lines))
52
53
54 stdout = sys.stdout
55 sys.stdout = cStringIO.StringIO()
56 try:
57 p.send_page(macro.request, content_only=1)
58 pagecontent = sys.stdout.getvalue()
59 finally:
60 sys.stdout = stdout
61
62 if pagecontent[:4] == "\n<p>":
63 pagecontent = pagecontent[4:]
64
65 content += """
66 <div class="partialinclude">
67 %s
68 <div class="partialincludelink">
69 %s
70 </div>
71 </div>""" % (pagecontent, macro.formatter.pagelink(pagename, generated=1))
72
73 return content
MoinMoin: macro/PartialInclude.py (last edited 2007-10-29 19:07:31 by localhost)