Hey Les,

Les a écrit :
> How can I retrieve a list of symbols from any template string?

If you wish to work with all Template's, you'll need to use their 
specific syntax regex ("pattern").  The default syntax says #{...}, but 
it can be pretty much anything, really, as long as you provide an 
alternative pattern at creation time.

So I'd go with something like this:

Template.prototype.getSymbols = function() {
   var result = [];
   this.template.scan(this.pattern, function(md) {
     if (md[1] != '\\') result.push(md[3]);
   });
   return result;
};

Then you could do:

var t = new Template(
   "Hello #{name}, you are #{age}! Syntax is \\#{...}");

t.evaluate({name: 'tdd', age: 29})
// => "Hello tdd, you are 29! Syntax is #{...}"

t.getSymbols()
// => ["name", "age"]

And this will work with custom patterns, too!

-- 
Christophe Porteneuve aka TDD
[EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to