Re: [ANN] Amber: HTML Template Engine

1,430 views
Skip to first unread message

Dumitru Ungureanu

unread,
Oct 31, 2012, 5:22:43 PM10/31/12
to golan...@googlegroups.com, ek...@eknkc.com
Sounds interesting.

I'm pretty new to Go too, so my only "suggestion" is about the HAML-like part. Could you possibly consider the possibility of adding support for plain HTML too?

HAML adds a degree of complexity for those used to deal with and validate plain HTML and may prove to be quite trickier to manage with more complex HTML.

Jeremy Wohl

unread,
Nov 1, 2012, 3:34:34 AM11/1/12
to golan...@googlegroups.com, ek...@eknkc.com
Well done.  The Jade-style systems make templates a pleasure to build and maintain.  I was hoping someone would find the incentive for a Go implementation.

I might point you to the Slim variant, which manages to cut down the visual noise even more.  Thanks.

On Wednesday, October 31, 2012 1:55:04 PM UTC-7, ek...@eknkc.com wrote:
Hi,

I just published a new template engine named "amber", (named after jade, node.js template engine)


Why? What?

- It is HAML based. So, all html tags go into indented blocks and attributes can be supplied via css like selctor syntax. (See documentation)
- Compiles to standard Go templates (html/template). Just returns a *Template, ready to be used. It should make things easier for integration, also, I expect the runtime to be highly optimized, as it is built in.
- Supports basic expressions. You can go ahead and print `Friends * 2`, or `2 + 3 * (SomeData % 1)`..
- Supports expressions as attribute conditions. Best example, during an iteration: `.even ? number % 2 == 0` This will add "even" class to the parent html tag, only is the condition holds.
- Expressions require helper functions in generated template's FuncMap. (add, multiple, greater than etc..) These are supplied by amber when you compile an amber template to go template.
- Supports template inheritance. So, it is possible to create a master template, define basic structure and named blocks. And then extend it for different pages, overriding contents of named blocks or just appenfing / prepending content.
- Standard if, else, iterator statements.

I don't know if anyone would be interested, but if you do, keep in mind that it's still experimental. I love Jade on Node.JS so wanted to have something as similar as possible for my Go Projects. I'm also relatively new to Go, so let me know if you have any suggestions.

Martin Angers

unread,
Apr 9, 2013, 8:44:40 PM4/9/13
to golan...@googlegroups.com, ek...@eknkc.com
I love your design decision to compile to Go's native template. This should be the way to go for other template engine ports. Makes it trivial to abstract the actual engine and build generic libraries that work on html/template while still supporting those user-land implementations.

Le jeudi 1 novembre 2012 21:49:24 UTC-4, ek...@eknkc.com a écrit :
I did not know about Slim. Just got some great ideas :)
Gotta improve error reporting first, then I'll see what I can get from Slim. Thanks a lot.

Bryan Matsuo

unread,
Apr 10, 2013, 1:01:38 AM4/10/13
to golan...@googlegroups.com, ek...@eknkc.com
Sounds like a great idea. The text/template package is tolerable but not always the most convenient. I have been wanting people to start writing more expressive template engines.

I am wondering though... At first glance Amber appears to lack support for a couple of the conveniences that text/template does offer. I am mainly talking about accessing nested values (e.g. B in a struct { A struct { B string }}), function invocation, and method calls (pipes from text/templates would be cool but not really necessary). If any of these are possible it should probably be stated in the docs.

Either way, thanks for the package! I'll likely be looking into it in the next couple days.
Reply all
Reply to author
Forward
0 new messages