Skip to content

Commit

Permalink
fix: Add support for empty output
Browse files Browse the repository at this point in the history
Signed-off-by: Trevor Taubitz <[email protected]>
  • Loading branch information
terrabitz committed Nov 25, 2020
1 parent 096e8df commit 5b2217a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
9 changes: 9 additions & 0 deletions lang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Package lang provides constructs for defining golang language constructs and ext
- [func NewExample(cfg *Config, name string, doc *doc.Example) *Example](<#func-newexample>)
- [func (ex *Example) Code() (string, error)](<#func-example-code>)
- [func (ex *Example) Doc() *Doc](<#func-example-doc>)
- [func (ex *Example) HasOutput() bool](<#func-example-hasoutput>)
- [func (ex *Example) Level() int](<#func-example-level>)
- [func (ex *Example) Location() Location](<#func-example-location>)
- [func (ex *Example) Name() string](<#func-example-name>)
Expand Down Expand Up @@ -272,6 +273,14 @@ func (ex *Example) Doc() *Doc

Doc provides the structured contents of the documentation comment for the example\.

### func \(\*Example\) [HasOutput](<https://github.com/princjef/gomarkdoc/blob/master/lang/example.go#L87>)

```go
func (ex *Example) HasOutput() bool
```

HasOutput indicates whether the example contains any example output\.

### func \(\*Example\) [Level](<https://github.com/princjef/gomarkdoc/blob/master/lang/example.go#L25>)

```go
Expand Down
5 changes: 5 additions & 0 deletions lang/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ func (ex *Example) Code() (string, error) {
func (ex *Example) Output() string {
return ex.doc.Output
}

// HasOutput indicates whether the example contains any example output.
func (ex *Example) HasOutput() bool {
return ex.doc.Output != "" && !ex.doc.EmptyOutput
}
8 changes: 6 additions & 2 deletions templates.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions templates/example.gotxt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

{{- codeBlock "go" .Code }}

Output:
{{- if .HasOutput -}}

{{ codeBlock "" .Output -}}
{{- header 4 "Output" -}}

{{- codeBlock "" .Output -}}

{{- end -}}

{{- accordionTerminator -}}

0 comments on commit 5b2217a

Please sign in to comment.