1 """
   2     MoinMoin - IncludeTeaser macro
   3 
   4     Copyright (c) 2003 by Th.Fanslau <tfanslau@gmx.de>
   5     All rights reserved, see COPYING for details.
   6 
   7     This macro includes the formatted first paragraph of the given page.
   8 
   9     Usage:
  10         [[IncludeTeaser(page)]]
  11 
  12         page        Name of the page to include
  13 
  14     Examples:
  15         [[IncludeTeaser(FooBar)]]
  16            -- includes page FooBar
  17 
  18     $Id$
  19 """
  20 
  21 import sys, re, cStringIO
  22 from MoinMoin.Page import Page
  23 from MoinMoin.i18n import _
  24 
  25 _arg_level = r',\s*(?P<level>\d+)'
  26 _args_re_pattern = r'^(?P<name>[^,]+)(%s)?$' % (_arg_level,)
  27 
  28 def execute(macro, text, args_re=re.compile(_args_re_pattern)):
  29     ret = ''
  30 
  31     # parse and check arguments
  32     args = args_re.match(text)
  33     if not args:
  34         return ('<p><strong class="error">%s</strong></p>' % _('Invalid include arguments "%s"!')) % (text,)
  35 
  36     # get the page
  37     print_mode = macro.form.has_key('action') and macro.form['action'].value == "print"
  38     inc_name = args.group('name')
  39     this_page = macro.formatter.page
  40 
  41     inc_page = Page(inc_name, formatter=macro.formatter.__class__(macro.request))
  42 
  43     # output the included page
  44     stdout = sys.stdout
  45     sys.stdout = cStringIO.StringIO()
  46     inc_page.send_page(macro.request, content_only=1)
  47     ret = sys.stdout.getvalue().splitlines()[1]
  48     sys.stdout = stdout
  49 
  50     # if no heading and not in print mode, then output a helper link
  51     #TODO: Replace "more" with _("more") or a Icon
  52 
  53     if not print_mode:
  54         ret = ret + macro.parser.interwiki(["wiki:" + inc_name, "more"])
  55 
  56     # return include text
  57     return ret

MoinMoin: macro/InsertTeaser.py (last edited 2007-10-29 19:08:31 by localhost)