Attachment '02.extract-setup-functions.patch'

Download

   1 # HG changeset patch
   2 # User gerg.ward+moin@gmail.com
   3 # Date 1225379794 14400
   4 # Node ID 4eae0f3824d2084833ff9397ec48bc6b3a684d61
   5 # Parent  abcab597f0bf4bf291c8df9903dc09d7e92d8349
   6 Factor out several functions that setup the list of pages to include:
   7 get_pagelist(), sort_pagelist(), limit_pagelist().
   8 
   9 diff -r abcab597f0bf -r 4eae0f3824d2 MoinMoin/macro/Include.py
  10 --- a/MoinMoin/macro/Include.py	Thu Oct 30 11:12:10 2008 -0400
  11 +++ b/MoinMoin/macro/Include.py	Thu Oct 30 11:16:34 2008 -0400
  12 @@ -52,6 +52,34 @@
  13          titles.append((title_text, level))
  14      return titles
  15  
  16 +def get_pagelist(request, this_page, args):
  17 +    inc_name = wikiutil.AbsPageName(this_page.page_name, args.group('name'))
  18 +    pagelist = [inc_name]
  19 +    if inc_name.startswith("^"):
  20 +        try:
  21 +            inc_match = re.compile(inc_name)
  22 +        except re.error:
  23 +            pass # treat as plain page name
  24 +        else:
  25 +            # Get user filtered readable page list
  26 +            pagelist = request.rootpage.getPageList(filter=inc_match.match)
  27 +    return pagelist
  28 +
  29 +def sort_pagelist(pagelist, args):
  30 +    sort_dir = args.group('sort')
  31 +    pagelist.sort()
  32 +    if sort_dir == 'descending':
  33 +        pagelist.reverse()
  34 +
  35 +def limit_pagelist(pagelist, args):
  36 +    maxitems = args.group('items')
  37 +    if maxitems:
  38 +        del pagelist[int(maxitems):]
  39 +
  40 +    skipitems = args.group('skipitems')
  41 +    if skipitems:
  42 +        del pagelist[:int(skipitems)]
  43 +
  44  def execute(macro, text, args_re=re.compile(_args_re_pattern), title_re=re.compile(_title_re, re.M)):
  45      request = macro.request
  46      _ = request.getText
  47 @@ -73,29 +101,12 @@
  48          this_page._macroInclude_pagelist = {}
  49  
  50      # get list of pages to include
  51 -    inc_name = wikiutil.AbsPageName(this_page.page_name, args.group('name'))
  52 -    pagelist = [inc_name]
  53 -    if inc_name.startswith("^"):
  54 -        try:
  55 -            inc_match = re.compile(inc_name)
  56 -        except re.error:
  57 -            pass # treat as plain page name
  58 -        else:
  59 -            # Get user filtered readable page list
  60 -            pagelist = request.rootpage.getPageList(filter=inc_match.match)
  61 +    pagelist = get_pagelist(request, this_page, args)
  62  
  63      # sort and limit page list
  64 -    pagelist.sort()
  65 -    sort_dir = args.group('sort')
  66 -    if sort_dir == 'descending':
  67 -        pagelist.reverse()
  68 -    max_items = args.group('items')
  69 -    if max_items:
  70 -        pagelist = pagelist[:int(max_items)]
  71 +    sort_pagelist(pagelist, args)
  72 +    limit_pagelist(pagelist, args)
  73  
  74 -    skipitems = 0
  75 -    if args.group("skipitems"):
  76 -        skipitems = int(args.group("skipitems"))
  77      titlesonly = args.group('titlesonly')
  78      editlink = args.group('editlink')
  79  
  80 @@ -105,9 +116,6 @@
  81              continue
  82          if inc_name in this_page._macroInclude_pagelist:
  83              result.append(u'<p><strong class="error">Recursive include of "%s" forbidden</strong></p>' % (inc_name, ))
  84 -            continue
  85 -        if skipitems:
  86 -            skipitems -= 1
  87              continue
  88          fmt = macro.formatter.__class__(request, is_included=True)
  89          fmt._base_depth = macro.formatter._base_depth

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] (2008-10-30 17:01:52, 20.5 KB) [[attachment:01.test-include.patch]]
  • [get | view] (2008-10-30 17:02:07, 3.1 KB) [[attachment:02.extract-setup-functions.patch]]
  • [get | view] (2008-10-30 17:02:17, 11.1 KB) [[attachment:03.extract-page-functions.patch]]
 All files | Selected Files: delete move to page copy to page

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