Re: JavaScript Templating Engine
Hannes Wallnoefer <hannesw <at> gmail.com>
2005-12-01 16:09:58 GMT
2005/11/30, Juerg Lehni <juerg <at> scratchdisk.com>:
> Because of my thoughts yesterday evening, I was thinking about
> implementing a template engine directly in JavaScript this morning,
> by creating a RegExp based parser that creates the string for a
> function that would render the given template and then evaluate that
> string, cache the resulting function in a template cache and call it
> each time the template needs to be rendered.
This is basically what .hsp files did in Helma, way before skins and
macros were introduced. Support for .hsp files is still in Helma, so
check it out: Add a file called hsp_action.hsp to your Root proto with
the following content:
1 2 3
<% if (true) %>
foo
<%= 33 + 234 %>
This will generate a function hsp_action() in the Root proto which,
when invoked via HTTP as /hsp, will render the following output:
1 2 3 foo 267
>From what I understand, even the implementation is very similar to
what you did. See
helma.scripting.rhino.HacHspConverter.processHspBody() for how it's
done in Helma.
>
> I went ahead and created a little test, which showed that the concept
(Continue reading)