Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Templating (Parser hack)

1 view
Skip to first unread message

Henrik Lindqvist

unread,
Dec 4, 2009, 7:33:55 PM12/4/09
to dev-tech-js-...@lists.mozilla.org
Hi,

I'am planning on using Rhino as a replacement for JSP, soo I've hacked
the parser adding a optional feature to enable a similar syntax:

-- cut --
%><h1>Title</h1>
<ul>
<% for (var i = 1; i <= 10; i++) { %>
<li>Item #<%= i %></li>
<% } %>
</ul>
-- cut --

Now some questions:

1. Is anyone else interested is such a feature?

2. Would such a feature, properly implemented, ever be accepted to the
main trunk of the Rhino source?

3. If yes. Any tips on how to correctly implement this? I've now just
added an additional token '%>template text<%', the parser then creates
AST nodes to call a "print" function with the template text and '<%='
expression as arguments. As said, currently a quick hack.

/ henrik

Keith

unread,
Dec 7, 2009, 4:14:47 PM12/7/09
to
On Dec 4, 7:33 pm, Henrik Lindqvist <henrik.lindqv...@llamalab.com>
wrote:

Wow... I was looking forward for such a thing in Rhino. However, not
being a Rhino expert I ended up using println() statements. This will
be a welcome addition. Wouldn't borrowing syntax from XQuery instead
of JSP be much neater? Some thing like:


function main()
{
return <html>
<body>
for (var i=0; i<10; ++i)
<div>{i}</div>
</body>
</html>
}

var xhtmlNode=main();
{xhtmlNode}

Attila Szegedi

unread,
Dec 8, 2009, 1:41:46 AM12/8/09
to Henrik Lindqvist, dev-tech-js-...@lists.mozilla.org
I honestly abhor ASP/JSP, and the language within the HTML template being JavaScript instead of Java doesn't really change my feelings. So, I wouldn't really like to see it in the main trunk. JS template engines seem to be springing into existence like mushrooms after rain these days anyway, and they're all written as libraries. I think a good JS template library shouldn't have a dependency on the JS runtime (Rhino in this case).

Attila.

--
home: http://www.szegedi.org
twitter: http://twitter.com/szegedi
weblog: http://constc.blogspot.com

Mark Porter

unread,
Dec 9, 2009, 4:39:07 PM12/9/09
to
I'm doing exactly this in Myna (http://www.mynajs.org/site/article/
MynaServerLanguageFeatures.ejs) by running the JS through a pre-
processor and converting it to JavaScript before compiling. This also
allows for embedded templating (see link above). If you are looking
for a replacement/alternative to JSP, check it out.

On Dec 4, 5:33 pm, Henrik Lindqvist <henrik.lindqv...@llamalab.com>
wrote:

Mark Porter

unread,
Dec 9, 2009, 4:42:24 PM12/9/09
to
Actually, Myna does something very similar to this as well via an
adaptation of ExtJS's Template and XTemplate objects:
http://www.mynajs.org/shared/docs/js/libOO/files/Template-sjs.html
0 new messages