Skip to content

Commit 3674cb3

Browse files
committed
Get partials working.
1 parent 9465ac9 commit 3674cb3

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

mustang/Node.ooc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import io/Writer
22
import structs/[List, HashMap]
3-
import mustang/[Context, Value, Renderer]
3+
import mustang/[Context, Value, Renderer, Template]
44

55
/**
66
Base template node interface.
@@ -84,3 +84,15 @@ SectionNode: class extends TNode {
8484

8585
debug: func -> String { "Section: name=%s" format(variableName) }
8686
}
87+
88+
PartialNode: class extends TNode {
89+
partialTemplate: Template
90+
91+
init: func(=partialTemplate) {}
92+
93+
render: func(context: Context, out: Writer) {
94+
partialTemplate render(context, out)
95+
}
96+
97+
debug: func -> String { "Partial" }
98+
}

mustang/TagParser.ooc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import structs/List
2-
import mustang/Node
2+
import mustang/[Node, Template]
33

44
/**
55
Used by TemplateParser for parsing tags.
@@ -59,7 +59,7 @@ SectionParser: class extends TagParser {
5959
isBlock: func -> Bool { true }
6060

6161
parse: func(tag: String) -> TNode {
62-
variableName := tag substring(1). trim()
62+
variableName := tag substring(1) trim()
6363
SectionNode new(variableName)
6464
}
6565
}
@@ -73,8 +73,11 @@ PartialParser: class extends TagParser {
7373
matches: func(tag: String) -> Bool { tag first() == '>' }
7474

7575
parse: func(tag: String) -> TNode {
76-
"Parsed parital tag!" println()
77-
null
76+
//TODO: better template path lookups
77+
templateName := tag substring(1) trim()
78+
template := Template loadFromFile("%s.mustache" format(templateName))
79+
80+
PartialNode new(template)
7881
}
7982
}
8083

mustang/TemplateReader.ooc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ TemplateReader: class {
1212
return new(buffer)
1313
}
1414

15+
getReaderFromPath: static func(path: String) -> This {
16+
getReaderFromFile(File new(path))
17+
}
18+
1519
init: func(=content) {
1620
index = 0
1721
}

0 commit comments

Comments
 (0)