jehugaleahsa / mustache-sharp

An extension of the mustache text template engine for .NET.
The Unlicense
306 stars 78 forks source link

Compiler.PlaceholderFound not firing for {{#if... #13

Closed PaulGrimshaw closed 10 years ago

PaulGrimshaw commented 10 years ago

Is it possible to have the PlaceholderFound event fire for {{#if...}}, {{#with...}} and {{#each...}} as well as normal placeholders? The current PlaceholderFound logic works great, but I can't seem to pick up whether a particular field is in the template if the field is ONLY in the {{#if tag.

jehugaleahsa commented 10 years ago

Those events fire every time a key is found. On Oct 28, 2013 4:05 PM, "Paul Grimshaw" notifications@github.com wrote:

Is it possible to have the PlaceholderFound event fire for {{#if...}}, {{#with...}} and {{#each...}} as well as normal placeholders? The current PlaceholderFound logic works great, but I can't seem to pick up whether a particular field is in the template if the field is ONLY in the {{#if tag.

— Reply to this email directly or view it on GitHubhttps://github.com/jehugaleahsa/mustache-sharp/issues/13 .

PaulGrimshaw commented 10 years ago

The example code below gives no results:

var keys = new List(); var template = "{{#if Test}}{{/if}}"; var compiler = new FormatCompiler(); compiler.PlaceholderFound += (o, e) => {keys.Add(e.Key); }; var generator = compiler.Compile(template);

Am I missing something? I am looking to pick up that the "Test" property has been accessed...

jehugaleahsa commented 10 years ago

I will create a unit test from your example and see what is going on.

jehugaleahsa commented 10 years ago

My bad, there is an event on the Generator that says whenever a placeholder is replaced.

You are asking about the event on the actual FormatCompiler. Let me see what I can do.

jehugaleahsa commented 10 years ago

I just created a new NuGet package that includes your requested changes. I created a couple of unit tests based on your example. Please let me know if you run into any problems. If everything looks good, please close this issue. Thanks!