kilt icon indicating copy to clipboard operation
kilt copied to clipboard

Runtime Compilation

Open crisward opened this issue 7 years ago • 4 comments

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.

crisward avatar Nov 15 '16 13:11 crisward

It might be possible. I'm not so sure. I think the templating libs themselves would need to change.

jeromegn avatar Nov 21 '16 13:11 jeromegn

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.

straight-shoota avatar Jun 19 '17 13:06 straight-shoota

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.

straight-shoota avatar Jun 21 '17 18:06 straight-shoota

Runtime compilation for Kilt would be awesome!

Jens0512 avatar Jan 31 '19 20:01 Jens0512