Skip to content

Commit 53f384e

Browse files
committed
Get boolean sections working.
1 parent 8946a40 commit 53f384e

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

mustang/Context.ooc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ BoolValue: class extends Value {
2222

2323
type: func -> String { "Bool" }
2424
toString: func -> String { value toString() }
25+
26+
isTrue: func -> Bool { value }
2527
}
2628

2729
ListValue: class <T> extends Value {
@@ -37,7 +39,7 @@ ListValue: class <T> extends Value {
3739

3840
Context: abstract class {
3941
add: abstract func(name: String, value: Value)
40-
get: abstract func(name: String, value: Value)
42+
get: abstract func(name: String) -> Value
4143

4244
addString: func(name: String, value: String) {
4345
add(name, StringValue new(value))

mustang/Node.ooc

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import io/Writer
2-
import mustang/Context
2+
import mustang/[Context, Renderer]
33

44
/**
55
Base template node interface.
@@ -34,19 +34,39 @@ VariableNode: class extends TNode {
3434

3535
render: func(context: Context, out: Writer) {
3636
variable := context get(variableName)
37+
if(!variable) {
38+
Exception new("Variable '%s' not found in context!" format(variableName)) throw()
39+
}
40+
3741
out write(variable toString())
3842
}
3943

4044
debug: func -> String { "Variable: name=%s" format(variableName) }
4145
}
4246

4347
SectionNode: class extends TNode {
44-
name: String
48+
variableName: String
4549

46-
init: func(=name) {}
50+
init: func(=variableName) {}
4751

4852
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+
}
4969
}
5070

51-
debug: func -> String { "Section: name=%s" format(name) }
71+
debug: func -> String { "Section: name=%s" format(variableName) }
5272
}

mustang/TagParser.ooc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ SectionParser: class extends TagParser {
5959
isBlock: func -> Bool { true }
6060

6161
parse: func(tag: String) -> TNode {
62-
SectionNode new(tag)
62+
variableName := tag substring(1). trim()
63+
SectionNode new(variableName)
6364
}
6465
}
6566

0 commit comments

Comments
 (0)