Olivine-Labs/lustache — pull request #12 by andsve (2013-10-28 19:30:55+00:00)
Title: Added: Runtime/delayed compile for partials.

Oh hai!

I needed a solution to avoid knowing all the partials in runtime. It should not break anything, but add the possibility to provide a partials-table with a custom metatable, overwriting its __index field. Like this:

```lua
local partials_lut = {}
local mt = {
__index = function ( self, needed_partial )

-- do stuff here that cant be done
-- before running lustache.render
return do_some_cool_stuff( needed_partial )

end}
setmetatable(partials_lut, mt)

local template = ...
local view = ...

lustache:render(template, view, partials_lut)
```

I use it in a static site generation project I'm writing in Lua, much like how Jekyll work. I recursively "compile" the files I need, and thus I can't know beforehand if a mustache template will need a specific partial. Instead I "compile" needed partial only if it requested via the __index-field.

Perhaps others might benefit from this functionality as well! :)

Regards,
Sven