[ANN] ego: An ERb style templating language for Go

290 views
Skip to first unread message

benbjoh...@gmail.com

unread,
Feb 23, 2014, 5:27:44 PM2/23/14
to golan...@googlegroups.com
hey all-

I know, yet another templating language! Ego is an ERb-style templating language for Go that aims to accomplish a couple things:

1. Allow full support of Go constructs.

2. Support compile-time type checks.

3. Included in the compiled binary by default.

It does this by simply transpiling text and code blocks inside the template into a Go function. It also allows you to specify your function signature so you can pass arguments into it.


I'd love to hear some feedback. Thanks!


Ben Johnson

Andrew Gallant

unread,
Feb 23, 2014, 5:53:18 PM2/23/14
to golan...@googlegroups.com, benbjoh...@gmail.com
At first glance, this looks like a neat and fun idea.

One of the key features of the html/template package in the standard library is its security model. Does your package address security at all? (It might be OK if the answer is no, but I think it should be something that's addressed in your README.)

Matt Sherman

unread,
Feb 23, 2014, 5:55:21 PM2/23/14
to golan...@googlegroups.com, benbjoh...@gmail.com
Looks great! I am unfamiliar with template languages for Go that support arbitrary use of Go code, are there others?


On Sunday, February 23, 2014 5:27:44 PM UTC-5, benbjoh...@gmail.com wrote:

Ben Johnson

unread,
Feb 23, 2014, 6:07:38 PM2/23/14
to golan...@googlegroups.com, Andrew Gallant, benbjoh...@gmail.com
One of the key features of the html/template package in the standard library is its security model. Does your package address security at all? (It might be OK if the answer is no, but I think it should be something that's addressed in your README.)

No, ego doesn't support any kind of security model right now. ERb used to have a construct for escaping output values: <%=h … %>. Now they escape all output values by default.

I'll add it to ego.


Thanks!

-- 
Ben

Matt Sherman

unread,
Feb 23, 2014, 7:27:51 PM2/23/14
to golan...@googlegroups.com
ASP.net started with an ERB syntax and then evolved to something called Razor, which is quite nice. Many fewer delimiters. For example, this:

<% for _, colorName := range u.FavoriteColors { %>
  <li><%= colorName %></li>
<% } %>

...becomes this:

@for _, colorName := range u.FavoriteColors {
  <li>@colorName</li>
}

Non-trivial of course but sexy. Curious if ego might get there, or consider a terser syntax.

Jake Scott

unread,
Feb 24, 2014, 1:06:32 AM2/24/14
to golan...@googlegroups.com
HI Mat, re: razor.. there is a useful comparison between razor and erb style here:

benbjoh...@gmail.com

unread,
Feb 24, 2014, 9:31:59 AM2/24/14
to golan...@googlegroups.com
Non-trivial of course but sexy. Curious if ego might get there, or consider a terser syntax.
 
I like the syntax of Razor. I'm curious about the parsing rules involved and how difficult that would be to implement.

I'm going to keep the ERb syntax for ego -- mostly because it's accessible and easy to learn. The ego codebase is ~400 LOC though so doing a separate razor implementation probably wouldn't be too hard.

Ben

Matt Sherman

unread,
Feb 24, 2014, 2:13:27 PM2/24/14
to golan...@googlegroups.com, benbjoh...@gmail.com
Yeah, the rules are a bit tricky. They make inferences based on angle brackets, for example. The source is here: http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Razor/

(I wouldn't suggest trying to emulate their source, but might be a good reference.)

Kudos for bringing this style of templating, btw. I'm accustomed to having the full language in the view engine. Go's templates are great too, just a different point of view.
Reply all
Reply to author
Forward
0 new messages