Skip to content

Commit

Permalink
Merge pull request #129 from alexandregv/no_ellipsis
Browse files Browse the repository at this point in the history
Add -render-type-content option to render full type content instead of an ellipsis (`{ ... }`)
  • Loading branch information
posener authored Apr 3, 2024
2 parents 6a625d6 + 1ef7e79 commit 92aad77
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/goreadme/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func init() {
flag.StringVar(&cfg.Title, "title", "", "Override readme title. Default is package name.")
flag.StringVar(&cfg.GoDocURL, "godoc-url", "https://pkg.go.dev", "Go Doc URL for GoDoc badge.")
flag.BoolVar(&cfg.RecursiveSubPackages, "recursive", false, "Load docs recursively.")
flag.BoolVar(&cfg.RenderTypeContent, "render-type-content", false, "If 'types' is specified, render full type content.")
flag.BoolVar(&cfg.Consts, "constants", false, "Write package constants section, and if 'types' is specified, also write per-type constants section.")
flag.BoolVar(&cfg.Vars, "variables", false, "Write package variables section, and if 'types' is specified, also write per-type variables section.")
flag.BoolVar(&cfg.Functions, "functions", false, "Write functions section.")
Expand Down
2 changes: 2 additions & 0 deletions goreadme.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ type Config struct {
GoDocURL string `json:"godoc_url"`
// Use the standard library comment parser introduced in Go 1.19 to generate the markdown output.
StdMarkdown bool `json:"std_markdown"`
// RenderTypeContent will render fulll type content instead of an ellipsis (`{ ... }`).
RenderTypeContent bool `json:"render_type_content"`
// Consts will make constants documentation to be added to the README.
// If Types is specified, constants for each type will also be added to the README.
Consts bool `json:"consts"`
Expand Down
4 changes: 4 additions & 0 deletions internal/template/types.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

### type [{{ .Name }}]({{ urlOrName (index $.Files .Pos.File) }}#L{{ .Pos.Line }})

{{ if config.RenderTypeContent }}
{{ gocode .Decl.Text }}
{{ else }}
{{ gocodeEllipsis .Decl.Text }}
{{ end }}

{{ doc .Doc }}

Expand Down
39 changes: 39 additions & 0 deletions testdata/pkg15_render_type_content/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# pkg15

Package pkg15 is a testing package.

## Types

### type [ExampleType](/pkg.go#L5)

```go
type ExampleType struct {
ExportedVal int

ExampleInterface interface{}
// contains filtered or unexported fields
}
```

ExampleType is a type

### type [ExampleType2](/pkg.go#L21)

```go
type ExampleType2 struct {
ExampleInterface interface{}
// contains filtered or unexported fields
}
```

ExampleType2 is a type with an array

### type [ExampleTypeInt](/pkg.go#L27)

```go
type ExampleTypeInt struct {
// contains filtered or unexported fields
}
```

ExampleTypeInt is a one-liner type
3 changes: 3 additions & 0 deletions testdata/pkg15_render_type_content/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module pkg15

go 1.15
4 changes: 4 additions & 0 deletions testdata/pkg15_render_type_content/goreadme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"types": true,
"render_type_content": true
}
27 changes: 27 additions & 0 deletions testdata/pkg15_render_type_content/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Package pkg15 is a testing package.
package pkg15

// ExampleType is a type
type ExampleType struct {
ExportedVal int
val int
ExampleInterface interface{}
}

// ExampleTypeFactory is a factory function for ExampleType.
func ExampleTypeFactory() ExampleType {
return ExampleType{1, 1, "test"}
}

// ExampleMethod is a method on ExampleType.
func (e ExampleType) ExampleMethod() {
}

// ExampleType2 is a type with an array
type ExampleType2 struct {
val []int
ExampleInterface interface{}
}

// ExampleTypeInt is a one-liner type
type ExampleTypeInt struct{ val int }

0 comments on commit 92aad77

Please sign in to comment.