fluid.stringTemplate and multiple replacement

Colin Clark colinbdclark at gmail.com
Mon Jul 25 14:33:45 UTC 2011


Hi Charly,

Thanks for the fix! A quick suggestion:

Can you make a fresh, up-to-date branch of Infusion, name it after the JIRA issue you're fixing, and then apply your fix there? Then you can make a pull request directly from your branch. We'll review it and get it in.

This helps make it easy to manage code reviews and pull requests in context of the original issue.

Thanks so much,

Colin

On 2011-07-25, at 7:51 AM, charly molter wrote:

> Hey,
> I'm sorry I've just realized that I had forgotten the "%" token this
> is now fixed in this commit:
> https://github.com/lahabana/infusion/commit/5d2ee45670601263dea49159ed4341a4599276f4
> 
> On Mon, Jul 25, 2011 at 10:53 AM, charly molter <charly.molter at gmail.com> 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
>>> 
>> 
>> 
>> 
>> --
>> Charly Molter
>> 
> 
> 
> 
> -- 
> Charly Molter
> _______________________________________________________
> fluid-work mailing list - fluid-work at fluidproject.org
> To unsubscribe, change settings or access archives,
> see http://lists.idrc.ocad.ca/mailman/listinfo/fluid-work

---
Colin Clark
Technical Lead, Fluid Project
http://fluidproject.org



More information about the fluid-work mailing list