Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReStructuredText output #502

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ build/examples: bin/protoc build tmp/googleapis examples/proto/*.proto examples/
@$(EXAMPLE_CMD) --doc_opt=html,example.html:Ignore* examples/proto/*.proto
@$(EXAMPLE_CMD) --doc_opt=json,example.json:Ignore* examples/proto/*.proto
@$(EXAMPLE_CMD) --doc_opt=markdown,example.md:Ignore* examples/proto/*.proto
@$(EXAMPLE_CMD) --doc_opt=restructuredtext,example.rst:Ignore* examples/proto/*.proto
@$(EXAMPLE_CMD) --doc_opt=examples/templates/asciidoc.tmpl,example.txt:Ignore* examples/proto/*.proto

##@: Dev
Expand Down Expand Up @@ -71,6 +72,7 @@ test/docker: bin/protoc tmp/googleapis release/snapshot ## Run the docker e2e te
@$(DOCKER_CMD) --doc_opt=html,example.html:Ignore*
@$(DOCKER_CMD) --doc_opt=json,example.json:Ignore*
@$(DOCKER_CMD) --doc_opt=markdown,example.md:Ignore*
@$(DOCKER_CMD) --doc_opt=restructuredtext,example.md:Ignore*
@$(DOCKER_CMD) --doc_opt=/templates/asciidoc.tmpl,example.txt:Ignore*

##@: Release
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/pseudomuto/protoc-gen-doc
module github.com/nside/protoc-gen-doc

go 1.17

Expand Down
7 changes: 7 additions & 0 deletions renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
RenderTypeHTML
RenderTypeJSON
RenderTypeMarkdown
RenderTypeReStructuredText
)

// NewRenderType creates a RenderType from the supplied string. If the type is not known, (0, error) is returned. It is
Expand All @@ -34,6 +35,8 @@ func NewRenderType(renderType string) (RenderType, error) {
return RenderTypeJSON, nil
case "markdown":
return RenderTypeMarkdown, nil
case "restructuredtext":
return RenderTypeReStructuredText, nil
}

return 0, errors.New("Invalid render type")
Expand All @@ -54,6 +57,8 @@ func (rt RenderType) renderer() (Processor, error) {
return new(jsonRenderer), nil
case RenderTypeMarkdown:
return &htmlRenderer{string(tmpl)}, nil
case RenderTypeReStructuredText:
return &htmlRenderer{string(tmpl)}, nil
}

return nil, errors.New("Unable to create a processor")
Expand All @@ -69,6 +74,8 @@ func (rt RenderType) template() ([]byte, error) {
return nil, nil
case RenderTypeMarkdown:
return markdownTmpl, nil
case RenderTypeReStructuredText:
return reStructuredTextTmpl, nil
}

return nil, errors.New("Couldn't find template for render type")
Expand Down
2 changes: 2 additions & 0 deletions resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var (
htmlTmpl []byte
//go:embed resources/markdown.tmpl
markdownTmpl []byte
//go:embed resources/restructuredtext.tmpl
reStructuredTextTmpl []byte
//go:embed resources/scalars.json
scalarsJSON []byte
)
119 changes: 119 additions & 0 deletions resources/restructuredtext.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
######################
Protocol Documentation
######################

{{range .Files}}
{{$file_name := .Name}}

.. _ref_{{.Name}}:

{{.Name}}
==================================================================

{{.Description}}

{{range .Messages}}

.. _ref_{{.FullName}}:

{{.LongName}}
------------------------------------------------------------------

{{.Description}}

{{if .HasFields}}

.. csv-table:: {{.LongName}} type fields
:header: "Field", "Type", "Label", "Description"
:widths: auto
{{range .Fields }}
"{{.Name}}", ":ref:`ref_{{.FullType}}`", "{{.Label}}", "{{if (index .Options "deprecated"|default false)}}**Deprecated.** {{end}}{{nobr .Description}}{{if .DefaultValue}} Default: {{.DefaultValue}}{{end}}"
{{- end}}
{{end}}


{{if .HasExtensions}}

.. csv-table:: {{.LongName}} type extensions
:header: "Extension", "Type", "Base", "Number", "Description"
:widths: auto
{{range .Extensions }}
"{{.Name}}", "{{.LongType}}", "{{.ContainingLongType}}", "{{.Number}}", "{{nobr .Description}}{{if .DefaultValue}} Default: {{.DefaultValue}}{{end}}"
{{- end}}
{{end}}

{{end}} <!-- end messages -->

{{range .Enums}}

.. _ref_{{.FullName}}:

{{.LongName}}
------------------------------------------------------------------

{{.Description}}

.. csv-table:: Enum {{.LongName}} values
:header: "Name", "Number", "Description"
:widths: auto
{{range .Values }}
"{{.Name}}", "{{.Number}}", "{{nobr .Description}}"
{{- end}}

{{end}} <!-- end enums -->

{{if .HasExtensions}}

.. _ref_{{$file_name}}_extensions:

File-level Extensions
--------------------------------------------------------------------------------

.. csv-table:: {{.Name}} file-level Extensions
:header: "Extension", "Type", "Base", "Number", "Description"
:widths: auto
{{range .Extensions}}
"{{.Name}}", "{{.LongType}}", "{{.ContainingLongType}}", "{{.Number}}", "{{nobr .Description}}{{if .DefaultValue}} Default: `{{.DefaultValue}}`{{end}}"
{{- end}}
{{end}} <!-- end HasExtensions -->

{{range .Services}}

.. _ref_{{.FullName}}:

{{.Name}}
------------------------------------------------------------------

{{.Description}}

.. csv-table:: {{.Name}} service methods
:header: "Method Name", "Request Type", "Response Type", "Description"
:widths: auto
{{range .Methods}}
"{{.Name}}", ":ref:`ref_{{.RequestFullType}}`{{if .RequestStreaming}} stream{{end}}", ":ref:`ref_{{.ResponseFullType}}`{{if .ResponseStreaming}} stream{{end}}", "{{nobr .Description}}"
{{- end}}
{{end}} <!-- end services -->

{{end}}

.. _ref_scala_types:

Scalar Value Types
==================

{{range .Scalars}}

.. _ref_{{.ProtoType}}:

{{.ProtoType}}
-----------------------------

{{.Notes}}

.. csv-table:: {{.ProtoType}} language representation
:header: ".proto Type", "C++", "Java", "Python", "Go", "C#", "PHP", "Ruby"
:widths: auto

"{{.ProtoType}}", "{{.CppType}}", "{{.JavaType}}", "{{.PythonType}}", "{{.GoType}}", "{{.CSharp}}", "{{.PhpType}}", "{{.RubyType}}"

{{end}} <!-- end scalars -->