Revert "[wiki] ajout de la macro Include.py (http://moinmo.in/HelpOnMacros/Include)"
This reverts commit e7d9593a06a54b57d3946ecfdeb8613264ea9196.
This commit is contained in:
parent
7e6d2ba39d
commit
867a0f2bc7
1 changed files with 0 additions and 78 deletions
|
@ -1,78 +0,0 @@
|
||||||
# Include is now a standard macro
|
|
||||||
|
|
||||||
"""
|
|
||||||
MoinMoin - Include macro
|
|
||||||
|
|
||||||
Copyright (c) 2000 by Richard Jones <richard@bizarsoftware.com.au>
|
|
||||||
Copyright (c) 2000 by Jürgen Hermann <jh@web.de>
|
|
||||||
All rights reserved, see COPYING for details.
|
|
||||||
|
|
||||||
This macro includes the formatted content of the given page, following recursive
|
|
||||||
includes if encountered. Cycles are detected!
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
[[Include(pagename,heading,level)]]
|
|
||||||
|
|
||||||
pagename Name of the page to include
|
|
||||||
heading Text for the generated heading (optional)
|
|
||||||
level Level (1..5) of the generated heading (optional)
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
[[Include(FooBar)]] -- include the text of FooBar in the current paragraph.
|
|
||||||
[[Include(FooBar, heading)]] -- add a H1 of 'Foo Bar' followed by the text
|
|
||||||
[[Include(FooBar, heading, 2]] -- add a H2 of 'Foo Bar'
|
|
||||||
[[Include(FooBar, 'All about Foo Bar', 2]] -- add a H2 of 'All about Foo Bar'
|
|
||||||
|
|
||||||
$Id$
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys, string, re, StringIO
|
|
||||||
from MoinMoin.Page import Page
|
|
||||||
|
|
||||||
args_re_pattern = r'(?P<name>\w+)(,\s*(?P<heading>(heading|[\'"](?P<htext>.+)[\'"]))(,\s*(?P<level>\d+))?)?'
|
|
||||||
|
|
||||||
def execute(macro, text, args_re=re.compile(args_re_pattern)):
|
|
||||||
ret = ''
|
|
||||||
# parse and check arguments
|
|
||||||
m = args_re.match(text)
|
|
||||||
if not m:
|
|
||||||
ret = ret + '<strong class="error">Invaild include arguments "%s"</strong>'%text
|
|
||||||
|
|
||||||
# get the Page
|
|
||||||
name = m.group('name')
|
|
||||||
this_page = macro.formatter.page
|
|
||||||
if not hasattr(this_page, 'included'):
|
|
||||||
this_page.included = {}
|
|
||||||
if this_page.included.has_key(name):
|
|
||||||
ret = ret + '<strong class="error">Recursive include of "%s" forbidden</strong>'%name
|
|
||||||
inc_page = Page(name)
|
|
||||||
inc_page.included = this_page.included
|
|
||||||
|
|
||||||
# do headings
|
|
||||||
level = None
|
|
||||||
if m.group('heading'):
|
|
||||||
level = 1
|
|
||||||
if m.group('htext'):
|
|
||||||
heading = m.group('htext')
|
|
||||||
else:
|
|
||||||
heading = page.split_title()
|
|
||||||
if m.group('level'):
|
|
||||||
level = int(m.group('level'))
|
|
||||||
ret = ret + macro.formatter.url(name, macro.formatter.heading(level, heading))
|
|
||||||
|
|
||||||
# output the Page
|
|
||||||
this_page.included[name] = 1
|
|
||||||
stdout = sys.stdout
|
|
||||||
# python... I love you
|
|
||||||
sys.stdout = StringIO.StringIO()
|
|
||||||
inc_page.send_page(macro.form, content_only=1)
|
|
||||||
ret = ret + sys.stdout.getvalue()
|
|
||||||
sys.stdout = stdout
|
|
||||||
|
|
||||||
# if not printable, then output a helper link
|
|
||||||
if not level and (not macro.form.has_key('print') or
|
|
||||||
not macro.form['print'].value):
|
|
||||||
ret = ret + macro.formatter.url(name, '<small>[goto %s]</small>'%name)
|
|
||||||
|
|
||||||
del this_page.included[name]
|
|
||||||
return ret
|
|
Loading…
Add table
Add a link
Reference in a new issue