-
Notifications
You must be signed in to change notification settings - Fork 7
/
navprinter.go
98 lines (86 loc) · 2.14 KB
/
navprinter.go
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package webapp
import (
"io"
"strings"
"github.com/monopole/mdrip/tobeinternal/model"
)
// NavPrinter prints leftnav HTML to a Writer.
type NavPrinter struct {
model.TxtPrinter
courseCounter int
lessonCounter int
name []string
}
// NewTutorialNavPrinter returns a new printer for the given writer.
func NewTutorialNavPrinter(w io.Writer) *NavPrinter {
return &NavPrinter{
*model.NewTutorialTxtPrinter(w),
-1, -1, make([]string, 0)}
}
func (v *NavPrinter) navItemStyle() string {
if v.Depth() > 1 {
return "navItemBox"
}
return "navItemTop"
}
// VisitBlockTut does nothing.
// Not expanding blocks in the nav - too busy looking.
func (v *NavPrinter) VisitBlockTut(x *model.BlockTut) {
}
func (v *NavPrinter) addName(t model.Tutorial) {
v.name = append(v.name, t.Name())
}
func (v *NavPrinter) rmName() {
v.name = v.name[:len(v.name)-1]
}
func (v *NavPrinter) path() string {
return strings.Join(v.name, "/")
}
// VisitLessonTut visits a lesson to print it.
func (v *NavPrinter) VisitLessonTut(x *model.LessonTut) {
v.lessonCounter++
v.addName(x)
v.P("<div class='%s'>", v.navItemStyle())
v.Down()
v.P("<div id='NL%d' class='navLessonTitleOff'", v.lessonCounter)
v.P(" onclick='lessonController.assureActiveLesson(%d)'", v.lessonCounter)
v.P(" data-path='%s'>", v.path())
// Could loop over children here - decided not to.
v.Down()
v.P("%s", x.Name())
v.Up()
v.P("</div>")
v.Up()
v.P("</div>")
v.rmName()
}
// VisitCourse visits a course to print it.
func (v *NavPrinter) VisitCourse(x *model.Course) {
v.courseCounter++
v.addName(x)
v.P("<div class='%s'>", v.navItemStyle())
v.Down()
v.P("<div class='navCourseTitle' onclick='lessonController.ncToggle(%d)'>",
v.courseCounter)
v.Down()
v.P("%s", x.Name())
v.Up()
v.P("</div>")
v.P("<div id='NC%d' class='navCourseContent'", v.courseCounter)
v.P(" style='display: none;'>")
v.Down()
for _, c := range x.Children() {
c.Accept(v)
}
v.Up()
v.P("</div>")
v.Up()
v.P("</div>")
v.rmName()
}
// VisitTopCourse visits a course to print its children.
func (v *NavPrinter) VisitTopCourse(x *model.TopCourse) {
for _, c := range x.Children() {
c.Accept(v)
}
}