Been having a lot of fun learning TiddlyWiki and relearning Java, but I've 
hit another wall. I need a way to repeat macros a number of times. I don't 
know ahead of time what those macros will be, how many times they'll need 
to be repeated, how many parameters the repeated macro will have, and what 
those parameters will be called. So far, I think I've managed to handle the 
first two unknowns (which macro and how many repeats) but I'm stumped on 
how to deal with the other two parts (how many parameters and what they're 
called).

Here's the code for the Tiddler I've written so far:

\define buttonmacro(countUp)
<$button style="background-color:White; width:100%; height:100%" >"""
Button Caption $countUp$
"""</$button>
\end


<$macrocall $name=repeatmacroxv3 targetMacro=buttonmacro x=3 />


And here's the javascript macro I've written so far:

/*\
title: $:/_my/macros/repeatmacroxv3.js
type: application/javascript
module-type: macro

Macro to return a macro multiple times
\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Information about this macro
*/

exports.name = "repeatmacroxv3";

exports.params = [
 {name: "targetMacro"},
 {name: "x"}
];

/*
Run the macro
*/
exports.run = function(targetMacro,x) {
 var i;
 var result;
 for (i = 0; i < x; i++) { 
    if (i == 0) {
      result = "<<" + targetMacro + " " + String(i + 1) + ">>";
    } else {
      result += "<<" + targetMacro + " " + String(i + 1) + ">>";
    }
 }
 return result;
};

})();


My instincts are telling me to try using lists somehow to pass the 
parameters to the javascript and maybe seeing if the javascript can check 
what the macro to be repeated wants for parameters. But I'm not sure that's 
the best way. In fact, I feel like this is something that would have been 
so commonly needed that someone would have already made a plug-in or macro 
for this situation already. But I can't seem to find it, probably because I 
haven't found the right search terms.

So my questions are:
1. Has someone made a generalized macro repeater already, and if so, where 
can I get it from?
2. If a generalized macro repeater doesn't already exist, how what is the 
best way to create 

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/d23debf6-2612-446a-b1af-e8365bd727c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to