Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: compile each template to into a module #3

Open
ngocdaothanh opened this issue Jun 25, 2009 · 1 comment
Open

Proposal: compile each template to into a module #3

ngocdaothanh opened this issue Jun 25, 2009 · 1 comment

Comments

@ngocdaothanh
Copy link

Although it spawns processes, I doubt that herml_manager may be a bottle neck.

I propose that a template be compiled to a module in-memory (the module name can be referred from the template path implicitly, or specified explicitly) with a function "render" so that it can render itself.

In other words, a template is converted into code instead of data. This way, the Erlang VM caches and manages the templates for us efficiently. When we want to render, just call it. When we want to update a template, just recompile it and the Erlang VM will automatically replace the old code with the new one for us.

For example, the library "erlang-gettext" can compile a plain text .po file to a module elegantly like this:
http://github.com/davide/erlang-gettext/blob/baee1560a705d1337fa05be822fde57abef1d312/src/gettext_generate.erl

For a feeling, ErlyDTL is working like this:
erlydtl:compile("/path/to/welcome.html", welcome_template),
welcome_template:render([
{name, "Johnny"},
{friends, [<<"Frankie Lee">>, <<"Judas Priest">>]},
{primes, [1, 2, "3", <<"5">>]}
]).

I'm new to AST. I found some instruction here:
http://www.evanmiller.org/write-a-template-compiler-for-erlang.html

@seancribbs
Copy link
Collaborator

PDI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants