changeset 3243:1ad6243cdf06

macros: refactor for new arg parser
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 12 Mar 2008 00:23:45 +0100
parents 924a9abe5689
children 886b8969dbc6
files MoinMoin/macro/FootNote.py MoinMoin/macro/GetText.py MoinMoin/macro/LikePages.py MoinMoin/macro/PageHits.py MoinMoin/macro/RandomPage.py MoinMoin/macro/RandomQuote.py
diffstat 6 files changed, 18 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/macro/FootNote.py	Tue Mar 11 22:46:26 2008 +0100
+++ b/MoinMoin/macro/FootNote.py	Wed Mar 12 00:23:45 2008 +0100
@@ -18,7 +18,7 @@
 
 Dependencies = ["time"] # footnote macro cannot be cached
 
-def execute(macro, args):
+def macro_FootNote(macro, text=u''):
     request = macro.request
     formatter = macro.formatter
 
@@ -28,27 +28,27 @@
         request.footnote_ctr = 0
         request.footnote_show_ctr = 0
 
-    if not args:
+    if not text:
         return emit_footnotes(request, formatter)
     else:
         # grab new footnote backref number
         idx = request.footnote_ctr
         request.footnote_ctr += 1
 
-        shahex = sha.new(args.encode(config.charset)).hexdigest()
+        shahex = sha.new(text.encode(config.charset)).hexdigest()
         backlink_id = "fndef-%s-%d" % (shahex, idx)
         fwdlink_id = "fnref-%s" % shahex
 
-        if not args in request.footnotes:
+        if not text in request.footnotes:
             showidx = request.footnote_show_ctr
             request.footnote_show_ctr += 1
-            request.footnotes[args] = ([], fwdlink_id, showidx)
-        flist, dummy, showidx = request.footnotes[args]
-        request.footnotes[args] = (flist + [(backlink_id, idx)], fwdlink_id, showidx)
+            request.footnotes[text] = ([], fwdlink_id, showidx)
+        flist, dummy, showidx = request.footnotes[text]
+        request.footnotes[text] = (flist + [(backlink_id, idx)], fwdlink_id, showidx)
 
         # do index -> text mapping in the same dict, that's fine because
-        # args is always a string and idx alwas a number.
-        request.footnotes[idx] = args
+        # text is always a string and idx alwas a number.
+        request.footnotes[idx] = text
 
         return "%s%s%s%s%s" % (
             formatter.sup(1),
--- a/MoinMoin/macro/GetText.py	Tue Mar 11 22:46:26 2008 +0100
+++ b/MoinMoin/macro/GetText.py	Wed Mar 12 00:23:45 2008 +0100
@@ -13,9 +13,9 @@
 
 Dependencies = ["language"]
 
-def execute(macro, args):
+def macro_GetText(macro, text=u''):
     """ Return a translation of args, or args as is """
-    translation = macro.request.getText(args)
+    translation = macro.request.getText(text)
 
     return macro.formatter.text(translation)
 
--- a/MoinMoin/macro/LikePages.py	Tue Mar 11 22:46:26 2008 +0100
+++ b/MoinMoin/macro/LikePages.py	Wed Mar 12 00:23:45 2008 +0100
@@ -10,7 +10,7 @@
 
 from MoinMoin.action import LikePages
 
-def execute(macro, args):
+def macro_LikePages(macro):
     request = macro.request
     # we don't want to spend much CPU for spiders requesting nonexisting pages
     if not request.isSpiderAgent:
@@ -23,6 +23,5 @@
         if matches and not isinstance(matches, (str, unicode)):
             return request.redirectedOutput(LikePages.showMatches, pagename, request, start, end, matches, False)
 
-        return args
     return ''
 
--- a/MoinMoin/macro/PageHits.py	Tue Mar 11 22:46:26 2008 +0100
+++ b/MoinMoin/macro/PageHits.py	Wed Mar 12 00:23:45 2008 +0100
@@ -14,7 +14,7 @@
 
 class PageHits:
 
-    def __init__(self, macro, args):
+    def __init__(self, macro):
         self.macro = macro
         self.request = macro.request
         self.cache = caching.CacheEntry(self.request, 'charts', 'pagehits', scope='wiki', use_pickle=True)
@@ -97,6 +97,6 @@
         return ''.join(result)
 
 
-def execute(macro, args):
-    return PageHits(macro, args).execute()
+def macro_PageHits(macro):
+    return PageHits(macro).execute()
 
--- a/MoinMoin/macro/RandomPage.py	Tue Mar 11 22:46:26 2008 +0100
+++ b/MoinMoin/macro/RandomPage.py	Wed Mar 12 00:23:45 2008 +0100
@@ -13,14 +13,9 @@
 
 Dependencies = ["time"]
 
-def execute(macro, args):
+def macro_RandomPage(macro, links=1):
     request = macro.request
-
-    # get number of wanted links
-    try:
-        links = max(int(args), 1)
-    except StandardError:
-        links = 1
+    links = max(links, 1) # at least 1 link
 
     # Get full page unfiltered page list - very fast!
     all_pages = request.rootpage.getPageList(user='', exists=0)
@@ -69,4 +64,3 @@
     result = ''.join(result)
     return result
 
-
--- a/MoinMoin/macro/RandomQuote.py	Tue Mar 11 22:46:26 2008 +0100
+++ b/MoinMoin/macro/RandomQuote.py	Wed Mar 12 00:23:45 2008 +0100
@@ -25,10 +25,9 @@
 
 Dependencies = ["time"]
 
-def execute(macro, args):
+def macro_RandomQuote(macro, pagename=u'FortuneCookies'):
     _ = macro.request.getText
 
-    pagename = args or 'FortuneCookies'
     if macro.request.user.may.read(pagename):
         page = Page(macro.request, pagename)
         raw = page.get_raw_body()