Skip to content

Commit

Permalink
add constructor functions, factor out package heading
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitshur committed Jul 18, 2019
1 parent ed8b2e9 commit 7f02f45
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions 256/_data/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
33 changes: 25 additions & 8 deletions 256/frontend/godoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)),
),
Expand Down Expand Up @@ -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)),
Expand Down

0 comments on commit 7f02f45

Please sign in to comment.