Helma Logo
main list history
previous version  overview  next version

Version 3 by tobi on 05. October 2006, 22:44

Developing While developing the first version of Rabbit, Rabbit a little idea came into my mind which suddenly opened a door for even more comfortable skin rendering.

I added a method called <code>render()</code> which mainly is wrapping renderSkin(). However, it takes a string as third argument:

function render(skin, param, str) {
    renderSkin(skin, param);

This string is used as name for a property of res.handlers.rendered
the rendered skin will be assigned to:

function render(skin, param, str) {
    if (str) {
      var result = this.renderSkinAsString(skin, param);
      res.handlers.rendered[str] = result;
      return result;
    } else {
      renderSkin(skin, param);

(Moreover, it returns Also note that the rendered skin is returned as resultresult if the third argument is set making a notorious "renderAsString()" sibling obsolete.

This way, I now can do the following with render():

// directly output a rendered skin as usual
render("foo");, param);
// assign a render rendered skin as string to a variable
var bar = render("foo", param, "foobar");
// use the "rendered" handler as container of previously rendered skins
render(createSkin("<% rendered.foobar %>"));)); // displays contents of res.handlers.rendered.foobar (which is the same as bar above)

By cascading render calls, each with a third argument, it's very easy to build structures:

render("header", null, "one");
render("main", {name: "World"}, "two");
render("footer", null, "three");

The skins:

<!-- header.skin -->

<!-- footer.skin -->

<!-- main.skin -->
Hello, <% param.name %>!

<!-- page.skin -->
<% rendered.one %>
<% rendered.two %>
<% rendered.three %>

The above code virtually cries for dropping the third argument again and using the first (the skin name) as the name for the res.handlers.rendered property. However, then we need a different method to indicate that a skin should be rendered as string and to prevent every rendered skin being assigned to a res.handlers.rendered property... Of course, many improvements can be made here, yet.