Helma Logo
main list history

Version 9 by hannes on 17. February 2009, 13:16

31 render(createSkin("<% rendered.foobar %>")); // displays contents of res.handlers.rendered.foobar (which is the same as bar above)
32 // displays contents of res.handlers.rendered.foobar
33 // (which is the same as bar above)

Version 8 by tobi on 03. November 2006, 19:19

93Here, the only ugly thing is the missing HopObejct render() method and that we have to send the item object as argument into the global render() method. Just needs to be done. // *tobi*

Version 7 by tobi on 05. October 2006, 23:01

85 <!-- listitem.skin -->
87

Version 6 by tobi on 05. October 2006, 23:00

59The 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.
60
61Of course, many improvements can be made from here. What I did in a final step is to append rendered skins if the third argument specifies a property already defined in res.handlers.rendered:
62
63 function render(skin, param, str) {
64    if (str) {
65      var result = this.renderSkinAsString(skin, param);
66      if (!res.handlers.rendered[str]) {
67          res.handlers.rendered[str] = "";
68      }
69      res.handlers.rendered[str] += result;
70      return result;
71    } else {
72      renderSkin(skin, param);
73    }
74 }
75 
76Now it becomes really elegant to render a collection:
77
78 render("header", null, "one");
79 for (var i=0; i<this.size(); i+=1) {
80    render("item", this.get(i), "list");
81 }
82 render("footer", null, "two");
83 render("page");
84
85 <!-- list.skin -->
86 <a href="<% param.url %>"><% param.name %></a>
87 <!-- page.skin -->
88 <% rendered.one %>
89 <% rendered.list %>
90 <% rendered.two %>
91
92Here, the only ugly thing is the missing HopObejct render() method and that we have to send the item object as argument into the global render() method. Just needs to be done.
93

Version 5 by tobi on 05. October 2006, 22:48

1While 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.

Version 4 by tobi on 05. October 2006, 22:45

47 <!-- main.skin -->
48 Hello, <% param.name %>!
49
51
52 <!-- main.skin -->
53 Hello, <% param.name %>!

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

1Developing 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.
22(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.
27 render("foo");, param);
28 // assign a render rendered skin as string to a variable
29 var bar = render("foo", param, "foobar");
29 render(createSkin("<% rendered.foobar %>"));)); // displays contents of res.handlers.rendered.foobar (which is the same as bar above)
31By cascading render calls, each with a third argument, it's very easy to build structures:
32
33 render("header", null, "one");
34 render("main", {name: "World"}, "two");
35 render("footer", null, "three");
36 render("page");
37
38The skins:
39
40 <!-- header.skin -->
41 <html>
42 <title>Test</title>
43 <body>
44
45 <!-- footer.skin -->
46 </body>
47 </html>
48
49 <!-- main.skin -->
50 Hello, <% param.name %>!
51
52 <!-- page.skin -->
53 <% rendered.one %>
54 <% rendered.two %>
55 <% rendered.three %>
56
57The 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.

Version 2 by tobi on 05. October 2006, 22:21

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

Version 1 by tobi on 05. October 2006, 22:21

1Developing the first version of Rabbit, a little idea came into my mind which suddenly opened a door for very comfortable skin rendering.
2
3I added a method called <code>render()</code> which mainly is wrapping renderSkin(). However, it takes a string as third argument:
4
5 function render(skin, param, str) {
6    renderSkin(skin, param);
7 }
8
9This string is used as name for a property of res.handlers.rendered
10the rendered skin will be assigned to:
11
12 function render(skin, param, str) {
13    if (str) {
14      var result = this.renderSkinAsString(skin, param);
15      res.handlers.rendered[str] = result;
16      return result;
17    } else {
18      renderSkin(skin, param);
19    }
20 }
21
22(Moreover, it returns the rendered skin as result.)
23
24This way, I now can do the following with render():
25
26 // directly output a rendered skin as usual
27 render("foo");
28 // assign a render skin to a variable
29 var bar = render("foo", "foobar");
30 // use the "rendered" handler as container of previously rendered skins
31 render(createSkin("<% rendered.foobar %>"));