= Default Macro Args = ||<#80FF80> 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 the ability in the tag to specify a default value for the argument. The second is [[Simple_Macro_Args]]. The default arg is used if a matching is not specified in the . Unlike real macro arguments, the default arg must be a simple string; using etc in a default argument is not supported (tho it could be with not too much difficulty). We use the default arg in cases where you are specifying simple formatting (colors, styles etc) and may want to override them. Like this: {{{
">
}}} This macro takes the unnamed macro arg and formats it into a box with the specified color (which defaults to "gray"). You might use it like this: {{{ # ....
}}} for a grey box, or {{{ green # etc }}} for a green box. The patch (against 1.10) is as follows: {{{ --- albatross/tags.py.DIST Mon Jul 21 12:40:16 2003 +++ albatross/tags.py Mon Jul 21 12:45:47 2003 @@ -1154,7 +1154,15 @@ name = 'al-usearg' def to_html(self, ctx): - content = ctx.get_macro_arg(self.get_attrib('name')) + try: + content = ctx.get_macro_arg(self.get_attrib('name')) + except ApplicationError: + # OK, look for a default= clause + if self.has_attrib('default'): + ctx.write_content(self.get_attrib('default')) + return + else: + raise # Peel one level of arguments off stack to evaluate enclosed # content then restore the stack afterwards. Nested macros # cause infinite recursion otherwise. }}} (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.) ---- Another possibility for defining a macro with default args could be: {{{ ... }}} or even the following if it's easier for the macro parsing: {{{ }}} I don't like the look of that second version much though. - Matt