jehugaleahsa / mustache-sharp

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

Feature request: extracting tags from the template #39

Open lukasz-lysik opened 9 years ago

lukasz-lysik commented 9 years ago

I couldn't find a way to get a list of tags used in the template.

In my application I would like to check which tags are required and then call appropriate services, gather all the required data and then compile the template.

I think that functionality would be useful. I found that this is possible (although not directly) in Ruby implementation of Mustache: http://stackoverflow.com/questions/10920826/extract-key-names-using-mustache-ruby-api

jehugaleahsa commented 9 years ago

Check out the PlaceholderFound event on the FormatCompiler. You can use it to build a list of all keys that appear in the template. That's different from all the tags that appear. I also don't remember if that includes keys that appear within a tag or not.

daball commented 9 years ago

I also need to be able to reflect on the compiled template in the project I'm working on. If nobody else is tasked to do this, I'll investigate it as soon as I wrap up my work on DynamicObject support, which is currently in my fork of the project.

PaulGrimshaw commented 9 years ago

I built a module to do this using the event "PlaceholderFound" as Travis suggests. I agree it would be nicer if this was wrapped up in a method that would return all the keys and paths (e.g. Contact.FirstName, Contact.Location.Name), but this can all be achieved using the event.

On Sat, Nov 29, 2014 at 8:58 PM, David Ball notifications@github.com wrote:

I also need to be able to reflect on the compiled template in the project I'm working on. If nobody else is tasked to do this, I'll investigate it as soon as I wrap up my work on DynamicObject support, which is currently in my fork of the project.

— Reply to this email directly or view it on GitHub https://github.com/jehugaleahsa/mustache-sharp/issues/39#issuecomment-64965018 .

Kind Regards

Paul Grimshaw

Mobile No: 07920 593 319

Quick Tracks – Dynamic Web Apps & Forms | Online Databases

daball commented 9 years ago

PlaceholderFound event works great. I haven't tested the PlaceholderEventArgs.Context parameter pattern yet, but I think it'll do everything I need it to do.