Scope of eval'ed named params in 2.1

1 view
Skip to first unread message

Simon Baird

unread,
Aug 10, 2006, 1:45:27 AM8/10/06
to Tiddly...@googlegroups.com
I was hoping my 'new here' button could be done like this:
 
<<newTiddler tag:{{tiddler.title}} label:'new here'>>
 
But that doesn't work, I think because the param is eval'ed outside of the macro scope where tiddler, place etc are defined.
 
Here's a quick solution for this particular issue. It seems a bit hacky but maybe it's good enough....
 
 
String.prototype.parseParams = function(defaultName,defaultValue,allowEval,noNames,cascadeDefaults,tiddler) // mptw hack
...
 
config.macros.newTiddler.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
                ...
                var params = paramString.parseParams("anon",null,true,false,false,tiddler); // mptw hack
                ...
 
 
Simon.

--
Simon Baird <simon...@gmail.com>

Saq Imtiaz

unread,
Aug 10, 2006, 12:27:23 PM8/10/06
to Tiddly...@googlegroups.com
On 8/10/06, Simon Baird <simon...@gmail.com> wrote:
I was hoping my 'new here' button could be done like this:
 
<<newTiddler tag:{{tiddler.title}} label:'new here'>>
 
But that doesn't work, I think because the param is eval'ed outside of the macro scope where tiddler, place etc are defined.
 
Here's a quick solution for this particular issue. It seems a bit hacky but maybe it's good enough....
 
 
String.prototype.parseParams = function(defaultName,defaultValue,allowEval,noNames,cascadeDefaults,tiddler ) // mptw hack
...
 
config.macros.newTiddler.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
                ...
                var params = paramString.parseParams("anon",null,true,false,false,tiddler ); // mptw hack


I'd like to see something like this adopted into the core.... I end up wanting to do things like this quite often.
Saq

Saq Imtiaz

unread,
Aug 10, 2006, 12:29:36 PM8/10/06
to Tiddly...@googlegroups.com

PS: One limitation with Simons solution is that it will only work for named params.

Udo Borkowski

unread,
Aug 11, 2006, 5:12:18 AM8/11/06
to Tiddly...@googlegroups.com
Hi Simon,

I guess you're right, it would be nice if something like {{tiddler.title}} would work as macro parameters.

Regarding the implementation the problem is that currently parseParams is located in the "String" module of the code, that "does not know" about Tiddler and I assume we don't want to add this dependency (for maintenance reasons). Also adding the tiddler parameter to the parseParams function would probably be not sufficient, since we also need to extend the "readMacroParams" (etc?) function to ensure a consistent result. So I am afraid that this change will probably not make it into 2.1 because it will probably require some more refactoring.

Nevertheless I added a ticket (http://trac.tiddlywiki.org/tiddlywiki/ticket/134) so we can tackle this issue with 2.2

Udo

----------
Udo Borkowski
http://www.abego-software.de
Reply all
Reply to author
Forward
0 new messages