1
1
mirror of https://github.com/mcuadros/ascode synced 2024-11-22 17:02:03 +01:00

doc: templates, examples support and Type styling

This commit is contained in:
Máximo Cuadros 2020-03-22 13:49:24 +01:00
parent 10a78e0a1d
commit 6012bbcb5a
No known key found for this signature in database
GPG Key ID: 17A5DFEDC735AE4B
2 changed files with 49 additions and 13 deletions

@ -7,9 +7,11 @@ DEPENDENCIES =
OUTLINE_CMD ?= outline
DOCUMENTATION_PATH ?= _documentation
DOCUMENTATION_RUNTIME_PATH ?= $(DOCUMENTATION_PATH)/runtime
EXAMPLES_PATH ?= starlark/types/testdata/examples
RUNTIME_MODULES = \
github.com/mcuadros/ascode/starlark/module/os \
github.com/mcuadros/ascode/starlark/types \
github.com/mcuadros/ascode/starlark/module/filepath \
github.com/qri-io/starlib/encoding/base64 \
github.com/qri-io/starlib/encoding/csv \
@ -50,7 +52,8 @@ BIN_PATH := $(BUILD_PATH)/bin
documentation: $(RUNTIME_MODULES)
$(RUNTIME_MODULES): $(DOCUMENTATION_RUNTIME_PATH)
@$(OUTLINE_CMD) package -t _scripts/template.md $@ > $(DOCUMENTATION_RUNTIME_PATH)/`basename $@`.md
$(OUTLINE_CMD) package -t _scripts/template.md -d $(EXAMPLES_PATH) $@ \
> $(DOCUMENTATION_RUNTIME_PATH)/`basename $@`.md
$(DOCUMENTATION_RUNTIME_PATH):
mkdir -p $@

@ -1,8 +1,17 @@
{{- define "mdFn" }}
{{- define "functionName" }}
{{- if ne .Receiver "types" -}}
#
{{- end -}}
### def {{ if ne .Receiver "types" -}}
<i>{{ .Receiver }}</i>.
{{- end -}}
<b>{{- (index (split .Signature "(") 0) -}}</b>
{{- end -}}
{{- define "function" }}
#### def <b>{{ (index (split .Signature "(") 0) }}</b>
{{ template "functionName" . }}
```go
{{ .Signature }}
{{if ne .Receiver "types" -}}{{.Receiver}}.{{- end }}{{ .Signature }}
```
{{- if ne .Description "" }}
@ -11,15 +20,26 @@
{{- if gt (len .Params) 0 }}
**parameters:**
###### Arguments
| name | type | description |
|------|------|-------------|
{{ range .Params -}}
| '{{ .Name }}' | '{{ .Type }}' | {{ .Description }} |
| `{{ .Name }}` | `{{ .Type }}` | {{ .Description }} |
{{ end -}}
{{- end -}}
{{- if gt (len .Examples) 0 }}
{{ range .Examples -}}
```python
{{ .Code }}
```
{{ end -}}
{{- end -}}
{{- end -}}
{{- range . -}}
@ -32,7 +52,7 @@ title: '{{ .Path }}'
{{- if gt (len .Functions) 0 }}
## Functions
{{ range .Functions -}}
{{ template "mdFn" . }}
{{ template "function" . }}
{{ end -}}
{{- end }}
@ -41,29 +61,41 @@ title: '{{ .Path }}'
{{ range .Types -}}
### '{{ .Name }}'
### <b>{{ .Name }}</b>
{{ if ne .Description "" }}{{ .Description }}{{ end -}}
{{ if gt (len .Fields) 0 }}
**Fields**
###### Properties
| name | type | description |
|------|------|-------------|
{{ range .Fields -}}
| {{ .Name }} | {{ .Type }} | {{ .Description }} |
| `{{ .Name }}` | `{{ .Type }}` | {{ .Description }} |
{{ end -}}
{{ if gt (len .Examples) 0 }}
###### Examples
{{ range .Examples -}}
{{ .Description }}
```python
{{ .Code }}
```
{{ end -}}
{{ end -}}
{{ end -}}
{{ if gt (len .Methods) 0 }}
**Methods**
###### Methods
{{- range .Methods -}}
{{ template "mdFn" . }}
{{ template "function" . }}
{{ end -}}
{{- if gt (len .Operators) 0 }}
**Operators**
###### Operators
| operator | description |
|----------|-------------|
@ -72,6 +104,7 @@ title: '{{ .Path }}'
{{ end }}
{{ end }}
{{ end }}
{{- end -}}
{{- end -}}