Short description

sometimes it is nice to show neighbours by the navigation macro only. e.g. for irssi logs

   1 diff -r 9d161d1dbdfc MoinMoin/macro/Navigation.py
   2 --- a/MoinMoin/macro/Navigation.py	Wed Oct 29 11:49:51 2008 +0100
   3 +++ b/MoinMoin/macro/Navigation.py	Wed Oct 29 13:52:40 2008 +0100
   4 @@ -109,7 +109,7 @@
   5          return self.do_siblings(root=self.pagename)
   6  
   7  
   8 -    def do_siblings(self, root=None):
   9 +    def do_siblings(self, root=None, neighbours=False):
  10          """ Navigate from a subpage to its siblings.
  11          """
  12          _ = self._
  13 @@ -123,8 +123,10 @@
  14  
  15          # iterate over children, adding links to all of them
  16          result = []
  17 -        children = _getPages(request, '^%s/' % re.escape(parent))
  18 +        children = sorted(_getPages(request, '^%s/' % re.escape(parent)))
  19 +        index = 0
  20          for child in children:
  21 +
  22              # display short page name, leaving out the parent path
  23              # (and make sure the name doesn't get wrapped)
  24              shortname = child[len(parent):]
  25 @@ -135,12 +137,21 @@
  26  
  27              if child == self.pagename:
  28                  # do not link to focus
  29 -                result.append(self.macro.formatter.text(shortname))
  30 +                result.append(self.macro.formatter.text(shortname) + '   ')
  31 +                if neighbours:
  32 +                    this_page_pos = index
  33              else:
  34                  # link to sibling / child
  35 -                result.append(Page(request, child).link_to(request, text=shortname, querystr=self.querystr))
  36 -            result.append('   ')
  37 -
  38 +                result.append(Page(request, child).link_to(request, text=shortname, querystr=self.querystr) + '   ')
  39 +            index += 1
  40 +        if neighbours:
  41 +            nb = result[this_page_pos]
  42 +            if this_page_pos - 1 >= 0:
  43 +                nb = result[this_page_pos - 1] + nb
  44 +            if this_page_pos + 1 <= index -1:
  45 +                nb = nb + result[this_page_pos + 1]
  46 +            result = nb
  47 +            print result
  48          return ''.join(result)
  49  
  50  
  51 diff -r 9d161d1dbdfc MoinMoin/parser/text_irssi.py
  52 --- a/MoinMoin/parser/text_irssi.py	Wed Oct 29 11:49:51 2008 +0100
  53 +++ b/MoinMoin/parser/text_irssi.py	Wed Oct 29 13:52:40 2008 +0100
  54 @@ -8,6 +8,8 @@
  55  """
  56  
  57  import re
  58 +from MoinMoin.macro.Navigation import Navigation
  59 +from MoinMoin._tests import make_macro
  60  
  61  Dependencies = []
  62  
  63 @@ -53,6 +55,10 @@
  64          tbl_style = 'vertical-align:top;'
  65          write = self.out.write
  66  
  67 +        m = make_macro(self.request, self.request.page)
  68 +        children = Navigation(m, 'children', 1).do_siblings(neighbours=True)
  69 +        write(children)
  70 +
  71          def write_tbl_cell(text, code=1, add_style=''):
  72              write(fmt.table_cell(1, style=tbl_style+add_style))
  73              if code:

neighbours.patch


CategoryFeatureRequest

MoinMoin: FeatureRequest/NavigationNeighbours (last edited 2008-10-29 12:53:04 by ReimarBauer)