fluid.stringTemplate and multiple replacement

Antranig Basman antranig.basman at colorado.edu
Mon Jul 25 17:28:47 UTC 2011


Thanks for this fix, Charly - it is looking nearly ready to go. To get it ready to merge in, could you
i) Add test cases to demonstrate the special character cases you have tested, as well as verifying the basic 
functionality of the improvement to match multiple tokens,
ii) Break out the logic at line 1732 into a standalone utility named something like fluid.stringToRegExp, 
since this might well be valuable in some other situation

Thanks,
Antranig

On 25/07/2011 03:53, charly molter wrote:
> Hello,
> Here's my correction I've tried with special characters it works:
> https://github.com/lahabana/infusion/commit/e7e4206f4b0abe727b86ea91ec8682bfccc1475e
>
> Thank you
>
> On Fri, Jun 17, 2011 at 12:27 AM, charly molter<charly.molter at gmail.com>  wrote:
>> Hello,
>> I'm currently using the stringTemplate function on a template like
>> that "<%tag %classes %attributes>%content</%tag>" my problem is
>> that it doesn't do the multiple replacement of %tag after checking the
>> code:
>>     fluid.stringTemplate = function (template, values) {
>>         var newString = template;
>>         for (var key in values) {
>>             var searchStr = "%" + key;
>>             newString = newString.replace(searchStr, values[key]);
>>         }
>>         return newString;
>>     };
>> It seems quite obvious that it doesn't do it. However I think this is
>> a lack, you expect from this kind of function to replace every
>> occurrences of a similar token.
>> So please tell me if there's something I've missed to use it that way...
>> Otherwise after looking for a little bit I've found that enhancement
>> that would enable to do that:
>>
>>     fluid.stringTemplate = function (template, values) {
>>         var newString;
>>         var tmpString = template;
>>         for (var key in values) {
>>             var searchStr = "%" + key;
>>             do {
>>                 newString = tmpString;
>>                 tmpString = newString.replace(searchStr, values[key]);
>>             } while(tmpString !== newString);
>>         }
>>         return newString;
>>     };
>>
>> So what do you think about it? Am I the only one thinking that the
>> replacement in a template should be repetitive?
>>
>> --
>> Charly Molter
>>
>
>
>




More information about the fluid-work mailing list