Details

Applies to
macro/RandomPage.py
Purpose

Allow a custom link text for links generated by the RandomPage macro

Description

This patch adds a second argument to the RandomPage macro. When RandomPage is generating a single link, this second argument sets the linktext of that generated link. This allows you to generate a random link without showing the target in the link text, for added surprise.

For example, writing:

<<RandomPage(1,foo)>>

gives you a link like [[random|foo]] where random is some random page name.

Patch

   1 diff --git a/plugin/macro/RandomPage.py b/plugin/macro/RandomPage.py
   2 index b97cd1d..9622b45 100644
   3 --- a/plugin/macro/RandomPage.py
   4 +++ b/plugin/macro/RandomPage.py
   5 @@ -13,7 +13,9 @@ from MoinMoin.Page import Page
   6  
   7  Dependencies = ["time"]
   8  
   9 -def macro_RandomPage(macro, links=1):
  10 +# Generate links random pagelinks. If links is 1, linktext can be used to
  11 +# override the link text.
  12 +def macro_RandomPage(macro, links=1, linktext=None):
  13      request = macro.request
  14      links = max(links, 1) # at least 1 link
  15  
  16 @@ -44,7 +46,7 @@ def macro_RandomPage(macro, links=1):
  17      if links == 1:
  18          name = pages[0]
  19          return (f.pagelink(1, name, generated=1) +
  20 -                f.text(name) +
  21 +                f.text(linktext or name) +
  22                  f.pagelink(0, name))
  23  
  24      # return a list of page links

randompage-linktext.patch

Discussion

Plan


CategoryMoinMoinPatch

MoinMoin: MoinMoinPatch/RandomPageCustomLinktext (last edited 2009-09-15 20:10:23 by ip565e4eed)