/
Handler.winxed
70 lines (59 loc) · 1.75 KB
/
Handler.winxed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Handler abstract parent type
This is the abstract parent type of the logic handlers. Do not use
this class directly.
*/
class Rosella.Template.Handler
{
// Empty constructor.
function Handler(var tokens [optional]) { }
// Add a child node
function add_child(var node)
{
Rosella.Error.invalid(__FUNCTION__, "Default Template.Handler does not allow child nodes");
}
// Render contents
function render(var engine, var ctx, var sb)
{
Rosella.Error.must_subclass(__CLASS__);
}
// This node can have children (Default)
function can_have_children() { return 0; }
// Execute a routine, saving away a list of values from the context
// to prevent them from being clobbered
function __save_ctx_values(var func, var ctx, var keys [slurpy])
{
var saved = {};
for (string key in keys)
saved[key] = ctx.get_value(key);
func();
for (string key in keys)
ctx.set_temporary(key, saved[key]);
}
}
namespace Rosella.Template.Handler
{
/* Handler type that is able to contain child nodes
*/
class Children : Rosella.Template.Handler
{
var children;
// Constructor.
function Children(var tokens [optional])
{
self.children = [];
}
// This handler does have child nodes
function can_have_children() { return 1; }
// Add a child node.
function add_child(var node)
{
push(self.children, node);
}
// Render the contents of all children
function __render_children(var engine, var ctx, var sb)
{
for (var child in self.children)
child.render(engine, ctx, sb);
}
}
}