File tree Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ BoolValue: class extends Value {
22
22
23
23
type : func -> String { "Bool" }
24
24
toString : func -> String { value toString () }
25
+
26
+ isTrue : func -> Bool { value }
25
27
}
26
28
27
29
ListValue : class <T > extends Value {
@@ -37,7 +39,7 @@ ListValue: class <T> extends Value {
37
39
38
40
Context : abstract class {
39
41
add : abstract func (name : String , value : Value )
40
- get : abstract func (name : String , value : Value )
42
+ get : abstract func (name : String ) -> Value
41
43
42
44
addString : func (name : String , value : String ) {
43
45
add (name, StringValue new (value))
Original file line number Diff line number Diff line change 1
1
import io/Writer
2
- import mustang/Context
2
+ import mustang/[ Context, Renderer]
3
3
4
4
/* *
5
5
Base template node interface.
@@ -34,19 +34,39 @@ VariableNode: class extends TNode {
34
34
35
35
render : func (context : Context , out : Writer ) {
36
36
variable := context get (variableName)
37
+ if (! variable) {
38
+ Exception new ("Variable '%s' not found in context!" format (variableName)) throw ()
39
+ }
40
+
37
41
out write (variable toString ())
38
42
}
39
43
40
44
debug : func -> String { "Variable: name=%s" format (variableName) }
41
45
}
42
46
43
47
SectionNode : class extends TNode {
44
- name : String
48
+ variableName : String
45
49
46
- init : func (= name ) {}
50
+ init : func (= variableName ) {}
47
51
48
52
render : func (context : Context , out : Writer ) {
53
+ variable := context get (variableName)
54
+ if (! variable) {
55
+ Exception new ("Variable '%s' not found in context!" format (variableName)) throw ()
56
+ }
57
+
58
+ if (variable type () == "List" ) {
59
+ }
60
+ else if (variable type () == "Bool" ) {
61
+ if ((variable as BoolValue ) isTrue ()) {
62
+ Renderer new (this firstChild, context) render (out)
63
+ }
64
+ }
65
+ else {
66
+ // TODO: better report this error
67
+ Exception new ("Section variable must be either list or bool!" ) throw ()
68
+ }
49
69
}
50
70
51
- debug : func -> String { "Section: name=%s" format (name ) }
71
+ debug : func -> String { "Section: name=%s" format (variableName ) }
52
72
}
Original file line number Diff line number Diff line change @@ -59,7 +59,8 @@ SectionParser: class extends TagParser {
59
59
isBlock : func -> Bool { true }
60
60
61
61
parse : func (tag : String ) -> TNode {
62
- SectionNode new (tag)
62
+ variableName := tag substring (1 ). trim ()
63
+ SectionNode new (variableName)
63
64
}
64
65
}
65
66
You can’t perform that action at this time.
0 commit comments