3
0

Tweak adoc templates

- Updates path for generated docs
- Adds adoc codegen for expression and fixes expr_types.gen.adoc.tpl
This commit is contained in:
Vivek Patel
2021-05-07 18:24:59 +05:30
committed by Denis Arh
parent da02e9d9b1
commit 0bfa57acd2
7 changed files with 137 additions and 4 deletions

View File

@@ -216,3 +216,17 @@ func genAutomationFunctions(tpl *template.Template, dd ...*aFuncDefs) (err error
return nil
}
// genAutomationFunctionDocs look for afunc.gen.adoc.tpl and generates afunc.gen.adoc from it
func genAutomationFunctionDocs(tpl *template.Template, docsPath string, dd ...*aFuncDefs) (err error) {
var (
typeGenAdoc = tpl.Lookup("afunc.gen.adoc.tpl")
dst string
)
dst = path.Join(docsPath, "afunc.gen.adoc")
return plainTemplate(dst, typeGenAdoc, map[string]interface{}{
"Definitions": dd,
})
}

View File

@@ -0,0 +1,63 @@
// This file is auto-generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// Definitions file that controls how this file is generated:
{{- range .Definitions }}
// - {{ .Source }}
{{- end }}
{{ range $d := .Definitions }}
= `{{ $d.Name }}`
[cols="2m,4a,3a"]
|===
| Name | Description | I/O
{{- range $f := .Functions }}
{{- if eq $f.Kind "function" }}
| [#fnc-{{ toLower $d.Name }}-{{ toLower $f.Name }}]#<<fnc-{{ toLower $d.Name }}-{{ toLower $f.Name }},{{ if $f.Meta.Short }}{{ $f.Meta.Short }}{{ else }}{{ $f.Name }}{{ end }}>>#
| {{ if $f.Meta.Description }}{{ $f.Meta.Description }}{{ end }}
|
{{- if gt (len $f.Params) 0}}
.Parameters:
{{- range $p := $f.Params}}
* {{ if $p.Required }}#*# {{ end }}`{{ if $p.Meta }}
{{- if $p.Meta.Label }}
{{- $p.Meta.Label }}
{{- else }}
{{- $p.Name }}
{{- end }}
{{- else }}
{{- $p.Name }}
{{- end }}`
({{- range $pti, $pt := $p.Types }}
`{{- $pt.WorkflowType }}`,
{{- end }})
{{- end }}
{{- end }}
{{- if gt (len $f.Results) 0}}
.Results:
{{- range $r := $f.Results}}
* {{ if $r.Meta }}
{{- if $r.Meta.Label }}
{{- $r.Meta.Label }}
{{- else }}
{{- $r.Name }}
{{- end }}
{{- else }}
{{- $r.Name }}
{{- end }} (`{{ $r.WorkflowType }}`)
{{- end }}
{{- end }}
{{- end }}
{{- end }}
|===
{{- end }}

View File

@@ -0,0 +1,32 @@
// This file is auto-generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// Definitions file that controls how this file is generated:
{{- range .Definitions }}
// - {{ .Source }}
{{- end }}
[cols="2m,3a"]
|===
| Type | Structure
{{- range .Definitions }}
{{- range $tName, $tDef := .Types }}
{{- if gt (len $tDef.Struct) 0}}
| [#objref-{{ toLower $tName }}]#<<objref-{{ toLower $tName }},{{ $tName }}>>#
|
{{- if $tDef.Struct }}
[source]
----
{
{{- range $s := .Struct }}
{{ $s.Name }} ({{ $s.ExprType }})
{{- end }}
}
----
{{ end }}
{{- end }}
{{- end }}
{{ end }}
|===

View File

@@ -7,6 +7,7 @@
{{- range .Definitions }}
// - {{ .Source }}
{{- end }}
include::ROOT:partial$variables.adoc[]
{{ range .Definitions }}
= {{ .Docs.Title }}
@@ -24,7 +25,10 @@
{{ if .Default -}}
=== Default
`{{ .Default }}`
[source]
----
{{ .Default }}
----
{{ end -}}
{{ if .Description -}}

10
pkg/codegen/codegen.go generated
View File

@@ -14,7 +14,7 @@ import (
func Proc() {
const (
docGenBase = "/partials/generated"
docGenBase = "/generated/partials"
)
var (
@@ -129,7 +129,7 @@ func Proc() {
}()
if len(docPath) > 0 {
docPath = strings.TrimRight(docPath, "/") + "/src/modules/ROOT"
docPath = strings.TrimRight(docPath, "/") + "/src/modules"
if i, err := os.Stat(docPath); err != nil {
handleError(err)
} else if !i.IsDir() {
@@ -212,6 +212,9 @@ func Proc() {
if genCode {
err = genExprTypes(tpls, exprTypeDefs...)
}
if genDocs && err == nil {
err = genExprTypeDocs(tpls, docPath+docGenBase, exprTypeDefs...)
}
}
if outputErr(err, "failed to process expr types:\n") {
@@ -282,6 +285,9 @@ func Proc() {
err = genAutomationFunctions(tpls, aFuncsDefs...)
}
if genDocs && err == nil {
err = genAutomationFunctionDocs(tpls, docPath+docGenBase, aFuncsDefs...)
}
}
if outputErr(err, "failed to process automation functions:\n") {

View File

@@ -109,6 +109,20 @@ func genExprTypes(tpl *template.Template, dd ...*exprTypesDef) (err error) {
return nil
}
// genExprTypeDocs look for expr_types.gen.adoc.tpl and generates expr_types.gen.adoc from it
func genExprTypeDocs(tpl *template.Template, docsPath string, dd ...*exprTypesDef) (err error) {
var (
typeGenAdoc = tpl.Lookup("expr_types.gen.adoc.tpl")
dst string
)
dst = path.Join(docsPath, "expr-types.gen.adoc")
return plainTemplate(dst, typeGenAdoc, map[string]interface{}{
"Definitions": dd,
})
}
func (s exprTypeDef) Default() string {
if s.RawDefault == "" {
return "nil"