-
Notifications
You must be signed in to change notification settings - Fork 26
/
app.go
76 lines (66 loc) · 1.87 KB
/
app.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
package docs
import (
"gnd.la/app"
"gnd.la/app/reusableapp"
"gnd.la/apps/docs/doc"
_ "gnd.la/template/assets/sass" // import the scss compiler for docs.scss
)
// Group represents a group of packages to be displayed under the same
// title. Note that all subpackages of any included package will also
// be listed. Packages must be referred by their import path (e.g.
// example.com/pkg).
type Group struct {
Title string
Packages []string
}
type Options struct {
Groups []*Group
}
type appData struct {
Groups []*Group
Environment *doc.Environment
}
type App struct {
reusableapp.App
}
func (a *App) Environment() *doc.Environment {
return a.Data().(*appData).Environment
}
func New(opts Options) *App {
data := &appData{
Groups: opts.Groups,
}
a := reusableapp.New(reusableapp.Options{
Name: "Docs",
AssetsData: assetsData,
TemplatesData: tmplData,
Data: data,
})
a.Prefix = "/doc/"
reverseDoc := func(s string) string { return a.MustReverse(PackageHandlerName, s) }
reverseSource := func(s string) string { return a.MustReverse(SourceHandlerName, s) }
data.Environment = doc.NewEnvironment(reverseDoc, reverseSource)
data.Environment.Set(envAppKey, a)
a.AddTemplateVars(map[string]interface{}{
"List": ListHandlerName,
"StdList": StdListHandlerName,
"Package": PackageHandlerName,
"Source": SourceHandlerName,
})
a.Handle("^/$", ListHandler, app.NamedHandler(ListHandlerName))
a.Handle("^/pkg/std/?", StdListHandler, app.NamedHandler(StdListHandlerName))
a.Handle("^/pkg/(.+)", PackageHandler, app.NamedHandler(PackageHandlerName))
a.Handle("^/src/(.+)", SourceHandler, app.NamedHandler(SourceHandlerName))
return &App{App: *a}
}
func appDocGroups(ctx *app.Context) []*Group {
data, _ := reusableapp.Data(ctx).(*appData)
if data != nil {
return data.Groups
}
return nil
}
type envKey int
const (
envAppKey envKey = iota
)