kilt
kilt copied to clipboard
Runtime Compilation
It is possible to do runtime compilation of templates? I'm thinking for development purposes, so the crystal server wouldn't need restarting after template updates. A bit like when using Jade with express in development mode.
It might be possible. I'm not so sure. I think the templating libs themselves would need to change.
I have created Crinja which implements the Jinja2 template engine and parses templates at runtime. crustache and liquid.cr also parse templates at runtime, but they can also be included at compile time.
For Crinja I have not yet implemented a code generator which would allow to include a parsed template directly into the executable. I am not even sure, this would be very useful, because the original source code is needed anyway besides the abstract syntax tree for extended error messages. So it is more space-efficient and requires no special implementation to bake only the source file into the executable and parse it at runtime. This could be exposed in a Kilt-compatible way.
The question for Kilt is, should it be an interface for compile-time templates only or also include templates parsed at runtime. The latter is much more complicated because it requires a detailed interface for interacting with the underlying template engines at runtime.
An example of Kilt + BakedFileSystem: https://github.com/straight-shoota/crinja/blob/master/examples/kilt/kilt.cr
Though I am not convinced an abstraction layer like Kilt is really useful because parsing and rendering templates at runtime will usually require a more detailed customization with the engine.
Runtime compilation for Kilt would be awesome!