formosatek/dotliquid — pull request #59 by somedave (2012-04-25 19:52:15+00:00)
Title: Allow IFileSystem To Return A Template

I had a use case where I was preparsing and caching templates for use, but when I went to include or extend them I found that they were getting reparsed all over again on each include. The problem is that IFileSystem can only return a string which is parsed into a new template on every include or extends tag. I wanted a way to pass back a previously parsed Template object to avoid that overhead when appropriate.

My solution was to modify IFileSystem to return an object rather than a string. Include and extends tags now check if the object is a Template, and if so they use it. If not, they use ToString() on the returned object (which in the case of a string obviously just returns the string). While I could have written a more comprehensive solution involving multiple interface types (I.e., one for passing back templates and another for strings), I think this approach strikes a good balance between minimizing changes to existing code and providing a better capability.