Skip to content
Permalink
Browse files

add constructor functions, factor out package heading

  • Loading branch information...
dmitshur committed May 19, 2019
1 parent ed8b2e9 commit 7f02f450802fc6b9a1b2cc4db9509ec9d1a1df4b
Showing with 27 additions and 10 deletions.
  1. +2 −2 256/_data/style.css
  2. +25 −8 256/frontend/godoc.go
@@ -29,14 +29,14 @@ h2:hover a {
code, pre {
font-family: "Go Mono";
font-size: 0.875em;
tab-size: 4;
}
pre {
padding: 0.75em;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 0.3em;
overflow-x: scroll;
tab-size: 4;
overflow-x: auto;
}

@media (prefers-color-scheme: dark) {
@@ -48,10 +48,16 @@ func serveGodoc(ctx context.Context, query string, mp modulepkg.Proxy) error {
fmt.Println("computeDoc taken:", time.Since(t))
t = time.Now()
var buf bytes.Buffer
err = htmlg.RenderComponents(&buf, godocComponent{
Fset: fset,
Package: d,
})
err = htmlg.RenderComponents(&buf,
htmlg.NodeComponent(*htmlg.H1(htmlg.Text("package " + d.Name))),
htmlg.NodeComponent(*htmlg.P(
htmlg.Code(htmlg.Text("import " + strconv.Quote(d.ImportPath))),
)),
godocComponent{
Fset: fset,
Package: d,
},
)
if err != nil {
return err
}
@@ -116,10 +122,6 @@ type godocComponent struct {

func (p godocComponent) Render() []*html.Node {
ns := []*html.Node{
htmlg.H1(htmlg.Text("package " + p.Name)),
htmlg.P(
htmlg.Code(htmlg.Text("import " + strconv.Quote(p.ImportPath))),
),
htmlg.P(
parseHTML(docHTML(p.Doc)),
),
@@ -192,6 +194,21 @@ func (p godocComponent) Render() []*html.Node {
),
)
}
for _, f := range t.Funcs {
heading := htmlg.H2(htmlg.Text("func "+f.Name+" "), htmlg.A("", "#"+f.Name))
heading.Attr = append(heading.Attr, html.Attribute{
Key: atom.Id.String(), Val: f.Name,
})
ns = append(ns,
heading,
htmlg.Pre(
htmlg.Text(printerutil.SprintAst(p.Fset, f.Decl)),
),
htmlg.P(
parseHTML(docHTML(f.Doc)),
),
)
}
for _, m := range t.Methods {
ns = append(ns,
htmlg.H3(htmlg.Text("func ("+m.Recv+") "+m.Name)),

0 comments on commit 7f02f45

Please sign in to comment.
You can’t perform that action at this time.