Simple Macro Args

Note that a variation on the functionality described here will appear in the next version of Albatross after 1.35 (AndrewMcNamara).

Macro handling in standard Albatross is powerful but a bit unwieldy to use and quite verbose, especially when the macro arguments are small. So I have made two small patches to make this easy. The first is Default_Macro_Args. The second is the ability to specify simple macro arguments directly in the <al-expand> tag, without using <al-setarg>. The limitation here is that the argument specified in this way must be a simple string; Albatross tags such as <al-value> will not be expanded in these arguments.

Given the box macro described in Default_Macro_Args, you would have to specify the box color like this:

<al-expand name="box">
  <al-setarg name="color">green</al-setarg>
  # box contents
</al-expand>

With the attached patch, this becomes a much more readable:

<al-expand name="box" color="green">
  # box contents
</al-expand>

The attached patch is against 1.10:

--- albatross/tags.py.DIST1     Mon Jul 21 12:45:47 2003
+++ albatross/tags.py   Mon Jul 21 12:55:35 2003
@@ -7,7 +7,7 @@
 #
 import time
 
-from albatross.template import Content, EmptyTag, EnclosingTag
+from albatross.template import Text, Content, EmptyTag, EnclosingTag
 from albatross.common import *
 
 # Empty content object which tags can use as default value for
@@ -1210,6 +1210,9 @@
         if not macro:
             self.raise_error('undefined macro "%s"' % self.get_attrib('name'))
         args = {}
+       for k, v in self.attrib_items():
+           if k != 'name':
+               args[k] = Text(v)
         args[None] = self.content
         for name, value in self.arg_dict.items():
             args[name] = value

(beware that cut-n-pasting this will probably mess with whitespace so you may need to apply the patch by hand, or use "patch -l" or some such.)

None: Simple_Macro_Args (last edited 2011-02-15 06:05:18 by localhost)