Skip to content

Commit

Permalink
render godocs from parsed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJenicek committed Mar 11, 2024
1 parent d2cd495 commit f656ebe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion field.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
[]{{template "field" dict "Name" $name "Type" (listElemType $type) "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $typeMeta}}

{{- else if isCoreType $type -}}

{{if $optional}}*{{end}}{{ get $typeMap $type }}

{{- else -}}{{- /* structs */ -}}
Expand Down
9 changes: 7 additions & 2 deletions struct.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
{{- $typePrefix := .TypePrefix -}}

type {{$name}} struct {
{{range $_, $field := $fields -}}
{{template "field" dict "Name" $field.Name "PrintName" true "Type" $field.Type "Optional" $field.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $field.Meta "JsonTags" true "StructTags" true}}
{{- range $_, $field := $fields -}}
{{- if gt (len $field.Comments) 0 -}}
{{- range $_, $comment := $field.Comments }}
// {{ replaceAll $comment "\"" "'" }}
{{- end }}
{{- end }}
{{template "field" dict "Name" $field.Name "PrintName" true "Type" $field.Type "Optional" $field.Optional "TypeMap" $typeMap "TypePrefix" $typePrefix "TypeMeta" $field.Meta "JsonTags" true "StructTags" true -}}
{{end -}}
}
{{- end }}
5 changes: 5 additions & 0 deletions types.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
{{ end -}}

{{- if and (eq $type.Kind "struct") $opts.types }}
{{- if gt (len $type.Comments) 0 }}
{{- range $_, $comment := $type.Comments }}
// {{ replaceAll $comment "\"" "'" }}
{{- end }}
{{- end }}
{{template "struct" dict "Name" $type.Name "TypeMap" $typeMap "TypePrefix" $typePrefix "Fields" $type.Fields}}
{{ end -}}

Expand Down

0 comments on commit f656ebe

Please sign in to comment.