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

fix: multine struct field descriptions #520

Open
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions examples/doc/example.docbook
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,14 @@
<entry>daily_hire_rate_dollars</entry>
<entry><link linkend="sint32">sint32</link></entry>
<entry>optional</entry>
<entry><para>Dollars per day.</para><para>Default: 50</para></entry>
<entry><para>Dollars per day.</para><para>Check also cents field.</para><para>Default: 50</para></entry>
</row>

<row>
<entry>daily_hire_rate_cents</entry>
<entry><link linkend="sint32">sint32</link></entry>
<entry>optional</entry>
<entry><para>Cents per day.</para></entry>
<entry><para>Cents per day.</para><para>Check also dollars field.</para></entry>
</row>

</tbody>
Expand Down
18 changes: 9 additions & 9 deletions examples/doc/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ <h3 id="com.example.BookingStatus">BookingStatus</h3>
<td>description</td>
<td><a href="#string">string</a></td>
<td></td>
<td><p>Booking status description. E.g. &#34;Active&#34;. </p></td>
<td><p>Booking status description. E.g. "Active". </p></td>
</tr>

</tbody>
Expand Down Expand Up @@ -669,7 +669,7 @@ <h3 id="com.example.Manufacturer">Manufacturer</h3>
<td>code</td>
<td><a href="#string">string</a></td>
<td>required</td>
<td><p>A manufacturer code, e.g. &#34;DKL4P&#34;. </p></td>
<td><p>A manufacturer code, e.g. "DKL4P". </p></td>
</tr>

<tr>
Expand All @@ -683,7 +683,7 @@ <h3 id="com.example.Manufacturer">Manufacturer</h3>
<td>category</td>
<td><a href="#com.example.Manufacturer.Category">Manufacturer.Category</a></td>
<td>optional</td>
<td><p>Manufacturer category. Default: CATEGORY_EXTERNAL</p></td>
<td><p>Manufacturer category. <br/><br/>Default: CATEGORY_EXTERNAL</p></td>
</tr>

</tbody>
Expand Down Expand Up @@ -714,14 +714,14 @@ <h3 id="com.example.Model">Model</h3>
<td>model_code</td>
<td><a href="#string">string</a></td>
<td>required</td>
<td><p>The car model code, e.g. &#34;PZ003&#34;. </p></td>
<td><p>The car model code, e.g. "PZ003". </p></td>
</tr>

<tr>
<td>model_name</td>
<td><a href="#string">string</a></td>
<td>required</td>
<td><p>The car model name, e.g. &#34;Z3&#34;. </p></td>
<td><p>The car model name, e.g. "Z3". </p></td>
</tr>

<tr>
Expand Down Expand Up @@ -794,14 +794,14 @@ <h3 id="com.example.Vehicle">Vehicle</h3>
<td>daily_hire_rate_dollars</td>
<td><a href="#sint32">sint32</a></td>
<td>optional</td>
<td><p>Dollars per day. Default: 50</p></td>
<td><p>Dollars per day.<br/><br/>Check also cents field. <br/><br/>Default: 50</p></td>
</tr>

<tr>
<td>daily_hire_rate_cents</td>
<td><a href="#sint32">sint32</a></td>
<td>optional</td>
<td><p>Cents per day. </p></td>
<td><p>Cents per day.<br/><br/>Check also dollars field. </p></td>
</tr>

</tbody>
Expand Down Expand Up @@ -843,14 +843,14 @@ <h3 id="com.example.Vehicle.Category">Vehicle.Category</h3>
<td>code</td>
<td><a href="#string">string</a></td>
<td>required</td>
<td><p>Category code. E.g. &#34;S&#34;. </p></td>
<td><p>Category code. E.g. "S". </p></td>
</tr>

<tr>
<td>description</td>
<td><a href="#string">string</a></td>
<td>required</td>
<td><p>Category name. E.g. &#34;Sedan&#34;. </p></td>
<td><p>Category name. E.g. "Sedan". </p></td>
</tr>

</tbody>
Expand Down
4 changes: 2 additions & 2 deletions examples/doc/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@
},
{
"name": "daily_hire_rate_dollars",
"description": "Dollars per day.",
"description": "Dollars per day.\n\nCheck also cents field.",
"label": "optional",
"type": "sint32",
"longType": "sint32",
Expand All @@ -703,7 +703,7 @@
},
{
"name": "daily_hire_rate_cents",
"description": "Cents per day.",
"description": "Cents per day.\n\nCheck also dollars field.",
"label": "optional",
"type": "sint32",
"longType": "sint32",
Expand Down
20 changes: 10 additions & 10 deletions examples/doc/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Represents the status of a vehicle booking.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| id | [int32](#int32) | | Unique booking status ID. |
| description | [string](#string) | | Booking status description. E.g. &#34;Active&#34;. |
| description | [string](#string) | | Booking status description. E.g. "Active". |



Expand Down Expand Up @@ -195,9 +195,9 @@ Represents a manufacturer of cars.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| id | [int32](#int32) | required | The unique manufacturer ID. |
| code | [string](#string) | required | A manufacturer code, e.g. &#34;DKL4P&#34;. |
| code | [string](#string) | required | A manufacturer code, e.g. "DKL4P". |
| details | [string](#string) | optional | Manufacturer details (minimum orders et.c.). |
| category | [Manufacturer.Category](#com-example-Manufacturer-Category) | optional | Manufacturer category. Default: CATEGORY_EXTERNAL |
| category | [Manufacturer.Category](#com-example-Manufacturer-Category) | optional | Manufacturer category.<br/><br/>Default: CATEGORY_EXTERNAL |



Expand All @@ -213,8 +213,8 @@ Represents a vehicle model.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| id | [string](#string) | required | The unique model ID. |
| model_code | [string](#string) | required | The car model code, e.g. &#34;PZ003&#34;. |
| model_name | [string](#string) | required | The car model name, e.g. &#34;Z3&#34;. |
| model_code | [string](#string) | required | The car model code, e.g. "PZ003". |
| model_name | [string](#string) | required | The car model name, e.g. "Z3". |
| daily_hire_rate_dollars | [sint32](#sint32) | required | Dollars per day. |
| daily_hire_rate_cents | [sint32](#sint32) | required | Cents per day. |

Expand All @@ -236,8 +236,8 @@ Represents a vehicle that can be hired.
| reg_number | [string](#string) | required | Vehicle registration number. |
| mileage | [sint32](#sint32) | optional | Current vehicle mileage, if known. |
| category | [Vehicle.Category](#com-example-Vehicle-Category) | optional | Vehicle category. |
| daily_hire_rate_dollars | [sint32](#sint32) | optional | Dollars per day. Default: 50 |
| daily_hire_rate_cents | [sint32](#sint32) | optional | Cents per day. |
| daily_hire_rate_dollars | [sint32](#sint32) | optional | Dollars per day.<br/><br/>Check also cents field.<br/><br/>Default: 50 |
| daily_hire_rate_cents | [sint32](#sint32) | optional | Cents per day.<br/><br/>Check also dollars field. |



Expand All @@ -257,8 +257,8 @@ Represents a vehicle category. E.g. &#34;Sedan&#34; or &#34;Truck&#34;.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| code | [string](#string) | required | Category code. E.g. &#34;S&#34;. |
| description | [string](#string) | required | Category name. E.g. &#34;Sedan&#34;. |
| code | [string](#string) | required | Category code. E.g. "S". |
| description | [string](#string) | required | Category name. E.g. "Sedan". |



Expand Down Expand Up @@ -286,7 +286,7 @@ Manufacturer category. A manufacturer may be either inhouse or external.
### File-level Extensions
| Extension | Type | Base | Number | Description |
| --------- | ---- | ---- | ------ | ----------- |
| country | string | Manufacturer | 100 | Manufacturer country. Default: `China` |
| country | string | Manufacturer | 100 | Manufacturer country.<br/><br/>Default: `China` |



Expand Down
4 changes: 4 additions & 0 deletions examples/doc/example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ Represents a vehicle that can be hired.

|daily_hire_rate_dollars | <<sint32,sint32>> |optional |Dollars per day.

Check also cents field.

|daily_hire_rate_cents | <<sint32,sint32>> |optional |Cents per day.

Check also dollars field.

|===========================================


Expand Down
4 changes: 4 additions & 0 deletions examples/proto/Vehicle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ message Vehicle {

/**
* Dollars per day.
*
* Check also cents field.
*/
optional sint32 daily_hire_rate_dollars = 6 [default = 50];

/**
* Cents per day.
*
* Check also dollars field.
*/
optional sint32 daily_hire_rate_cents = 7;

Expand Down
6 changes: 6 additions & 0 deletions filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
// PFilter splits the content by new lines and wraps each one in a <p> tag.
func PFilter(content string) template.HTML {
paragraphs := paraPattern.Split(content, -1)

return template.HTML(fmt.Sprintf("<p>%s</p>", strings.Join(paragraphs, "</p><p>")))
}

Expand All @@ -38,6 +39,11 @@ func NoBrFilter(content string) string {
return strings.Join(paragraphs, "\n\n")
}

// BrFilter uses NoBrFilter to remove single CR and LF and then replaces \n\n with <br/><br/>
func BrFilter(content string) template.HTML {
return template.HTML(strings.Replace(NoBrFilter(content), "\n\n", "<br/><br/>", -1))
}

// AnchorFilter replaces all special characters with URL friendly dashes
func AnchorFilter(str string) string {
return specialCharsPattern.ReplaceAllString(strings.ReplaceAll(str, "/", "_"), "-")
Expand Down
7 changes: 5 additions & 2 deletions renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var funcMap = map[string]interface{}{
"p": PFilter,
"para": ParaFilter,
"nobr": NoBrFilter,
"br": BrFilter,
"anchor": AnchorFilter,
}

Expand All @@ -90,10 +91,12 @@ type Processor interface {
// supplying a non-empty string as the last parameter.
//
// Example: generating an HTML template (assuming you've got a Template object)
// data, err := RenderTemplate(RenderTypeHTML, &template, "")
//
// data, err := RenderTemplate(RenderTypeHTML, &template, "")
//
// Example: generating a custom template (assuming you've got a Template object)
// data, err := RenderTemplate(RenderTypeHTML, &template, "{{range .Files}}{{.Name}}{{end}}")
//
// data, err := RenderTemplate(RenderTypeHTML, &template, "{{range .Files}}{{.Name}}{{end}}")
func RenderTemplate(kind RenderType, template *Template, inputTemplate string) ([]byte, error) {
if inputTemplate != "" {
processor := &textRenderer{inputTemplate}
Expand Down
2 changes: 1 addition & 1 deletion resources/html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
<td>{{.Name}}</td>
<td><a href="#{{.FullType}}">{{.LongType}}</a></td>
<td>{{.Label}}</td>
<td><p>{{if (index .Options "deprecated"|default false)}}<strong>Deprecated.</strong> {{end}}{{.Description}} {{if .DefaultValue}}Default: {{.DefaultValue}}{{end}}</p></td>
<td><p>{{if (index .Options "deprecated"|default false)}}<strong>Deprecated.</strong> {{end}}{{br .Description}} {{if .DefaultValue}}<br/><br/>Default: {{.DefaultValue}}{{end}}</p></td>
</tr>
{{end}}
</tbody>
Expand Down
10 changes: 5 additions & 5 deletions resources/markdown.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
{{range .Fields -}}
| {{.Name}} | [{{.LongType}}](#{{.FullType | anchor}}) | {{.Label}} | {{if (index .Options "deprecated"|default false)}}**Deprecated.** {{end}}{{nobr .Description}}{{if .DefaultValue}} Default: {{.DefaultValue}}{{end}} |
| {{.Name}} | [{{.LongType}}](#{{.FullType | anchor}}) | {{.Label}} | {{if (index .Options "deprecated"|default false)}}**Deprecated.** {{end}}{{br .Description}}{{if .DefaultValue}}<br/><br/>Default: {{.DefaultValue}}{{end}} |
{{end}}
{{end}}

{{if .HasExtensions}}
| Extension | Type | Base | Number | Description |
| --------- | ---- | ---- | ------ | ----------- |
{{range .Extensions -}}
| {{.Name}} | {{.LongType}} | {{.ContainingLongType}} | {{.Number}} | {{nobr .Description}}{{if .DefaultValue}} Default: {{.DefaultValue}}{{end}} |
| {{.Name}} | {{.LongType}} | {{.ContainingLongType}} | {{.Number}} | {{br .Description}}{{if .DefaultValue}}<br/><br/>Default: {{.DefaultValue}}{{end}} |
{{end}}
{{end}}

Expand All @@ -64,7 +64,7 @@
| Name | Number | Description |
| ---- | ------ | ----------- |
{{range .Values -}}
| {{.Name}} | {{.Number}} | {{nobr .Description}} |
| {{.Name}} | {{.Number}} | {{br .Description}} |
{{end}}

{{end}} <!-- end enums -->
Expand All @@ -76,7 +76,7 @@
| Extension | Type | Base | Number | Description |
| --------- | ---- | ---- | ------ | ----------- |
{{range .Extensions -}}
| {{.Name}} | {{.LongType}} | {{.ContainingLongType}} | {{.Number}} | {{nobr .Description}}{{if .DefaultValue}} Default: `{{.DefaultValue}}`{{end}} |
| {{.Name}} | {{.LongType}} | {{.ContainingLongType}} | {{.Number}} | {{br .Description}}{{if .DefaultValue}}<br/><br/>Default: `{{.DefaultValue}}`{{end}} |
{{end}}
{{end}} <!-- end HasExtensions -->

Expand All @@ -89,7 +89,7 @@
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
{{range .Methods -}}
| {{.Name}} | [{{.RequestLongType}}](#{{.RequestFullType | anchor}}){{if .RequestStreaming}} stream{{end}} | [{{.ResponseLongType}}](#{{.ResponseFullType | anchor}}){{if .ResponseStreaming}} stream{{end}} | {{nobr .Description}} |
| {{.Name}} | [{{.RequestLongType}}](#{{.RequestFullType | anchor}}){{if .RequestStreaming}} stream{{end}} | [{{.ResponseLongType}}](#{{.ResponseFullType | anchor}}){{if .ResponseStreaming}} stream{{end}} | {{br .Description}} |
{{end}}
{{end}} <!-- end services -->

Expand Down