Attachment 'IncludeMaxDepth.patch'

Download

   1 diff -r 8f2446858dd3 MoinMoin/macro/Include.py
   2 --- a/MoinMoin/macro/Include.py	Mon Mar 01 00:23:21 2010 +0100
   3 +++ b/MoinMoin/macro/Include.py	Wed Apr 28 10:23:32 2010 +0200
   4 @@ -32,12 +32,13 @@
   5  _arg_to = r'(,\s*to=(?P<tquote>[\'"])(?P<to>.+?)(?P=tquote))?'
   6  _arg_sort = r'(,\s*sort=(?P<sort>(ascending|descending)))?'
   7  _arg_items = r'(,\s*items=(?P<items>\d+))?'
   8 +_arg_depth = r'(,\s*depth=(?P<depth>\d+))?'
   9  _arg_skipitems = r'(,\s*skipitems=(?P<skipitems>\d+))?'
  10  _arg_titlesonly = r'(,\s*(?P<titlesonly>titlesonly))?'
  11  _arg_editlink = r'(,\s*(?P<editlink>editlink))?'
  12 -_args_re_pattern = r'^(?P<name>[^,]+)(%s(%s)?%s%s%s%s%s%s%s)?$' % (
  13 +_args_re_pattern = r'^(?P<name>[^,]+)(%s(%s)?%s%s%s%s%s%s%s%s)?$' % (
  14      _arg_heading, _arg_level, _arg_from, _arg_to, _arg_sort, _arg_items,
  15 -    _arg_skipitems, _arg_titlesonly, _arg_editlink)
  16 +    _arg_skipitems, _arg_titlesonly, _arg_editlink, _arg_depth)
  17  
  18  _title_re = r"^(?P<heading>\s*(?P<hmarker>=+)\s.*\s(?P=hmarker))$"
  19  
  20 @@ -99,7 +100,13 @@
  21      titlesonly = args.group('titlesonly')
  22      editlink = args.group('editlink')
  23  
  24 +    if args.group("depth"):
  25 +        depth = int(args.group('depth'))
  26 +    else:
  27 +        depth = 9999
  28 +
  29      # iterate over pages
  30 +    levelstack = []
  31      for inc_name in pagelist:
  32          if not request.user.may.read(inc_name):
  33              continue
  34 @@ -143,28 +150,29 @@
  35                  result.append(_sysmsg % ('warning', 'Include: ' + _('Nothing found for "%s"!')) % to_re)
  36  
  37          if titlesonly:
  38 -            levelstack = []
  39 +            #levelstack = []
  40              for title, level in extract_titles(body[from_pos:to_pos], title_re):
  41 -                if levelstack:
  42 -                    if level > levelstack[-1]:
  43 +                if not depth or (depth and level <= depth):
  44 +                    if levelstack:
  45 +                        if level > levelstack[-1]:
  46 +                            result.append(macro.formatter.bullet_list(1))
  47 +                            levelstack.append(level)
  48 +                        else:
  49 +                            while levelstack and level < levelstack[-1]:
  50 +                                result.append(macro.formatter.bullet_list(0))
  51 +                                levelstack.pop()
  52 +                            if not levelstack or level != levelstack[-1]:
  53 +                                result.append(macro.formatter.bullet_list(1))
  54 +                                levelstack.append(level)
  55 +                    else:
  56                          result.append(macro.formatter.bullet_list(1))
  57                          levelstack.append(level)
  58 -                    else:
  59 -                        while levelstack and level < levelstack[-1]:
  60 -                            result.append(macro.formatter.bullet_list(0))
  61 -                            levelstack.pop()
  62 -                        if not levelstack or level != levelstack[-1]:
  63 -                            result.append(macro.formatter.bullet_list(1))
  64 -                            levelstack.append(level)
  65 -                else:
  66 -                    result.append(macro.formatter.bullet_list(1))
  67 -                    levelstack.append(level)
  68 -                result.append(macro.formatter.listitem(1))
  69 -                result.append(inc_page.link_to(request, title))
  70 -                result.append(macro.formatter.listitem(0))
  71 -            while levelstack:
  72 -                result.append(macro.formatter.bullet_list(0))
  73 -                levelstack.pop()
  74 +                    result.append(macro.formatter.listitem(1))
  75 +                    result.append(inc_page.link_to(request, title))
  76 +                    result.append(macro.formatter.listitem(0))
  77 +            #while levelstack:
  78 +            #    result.append(macro.formatter.bullet_list(0))
  79 +            #    levelstack.pop()
  80              continue
  81  
  82          if from_pos or to_pos != -1:
  83 @@ -228,6 +236,10 @@
  84              ])
  85          # XXX page.link_to is wrong now, it escapes the edit_icon html as it escapes normal text
  86  
  87 +    while levelstack:
  88 +        result.append(macro.formatter.bullet_list(0))
  89 +        levelstack.pop()
  90 +
  91      # return include text
  92      return ''.join(result)
  93  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-04-28 08:24:08, 4.0 KB) [[attachment:IncludeMaxDepth.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.