-
Notifications
You must be signed in to change notification settings - Fork 11
/
render-doc
executable file
·132 lines (116 loc) · 4.85 KB
/
render-doc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#! /usr/bin/env bash
function cleanup {
echo "Removing gotemplate"
rm -f gotemplate
}
trap cleanup EXIT
go build -o gotemplate
export GOTEMPLATE_NO_STDIN=1
CONTENT_FOLDER="docs/content"
DOC_FOLDER="$CONTENT_FOLDER/docs"
export COLUMNS=108
rm -rf $DOC_FOLDER
mkdir -p $DOC_FOLDER
# Generate usage info
./gotemplate '@-
---
title: CLI Usage
weight: 1
---
<!-- markdownlint-disable MD025 --->
# CLI Usage
```text
@trim(exec("./gotemplate -h"))
```' --nv > $DOC_FOLDER/CLI_Usage.md
# Add basics section
mkdir -p $DOC_FOLDER/basic_features
printf -- '---\nbookFlatSection: true\nweight: 2\n---' > $DOC_FOLDER/basic_features/_index.md
# Add advanced section
mkdir -p $DOC_FOLDER/advanced_features
printf -- '---\nbookFlatSection: true\nweight: 3\n---' > $DOC_FOLDER/advanced_features/_index.md
for file in docs_tests/**/*.md
do
./gotemplate --rd 3 -dP $file > ${file%.*}.razor
./gotemplate --rd 3 -P $file > ${file%.*}.rendered --accept-no-value
done
rsync -av docs_tests/ $DOC_FOLDER -r
# Generate detailed function info
./gotemplate --no-extension --color '
@-define("trim")
@{wrapped} := String(text).Replace("<", "<").Wrap(69)
@-if (indent)
@{wrapped} = $wrapped.IndentN(indent).TrimSpace()
@-end if
@-{wrapped}
@-end define
@-define("GenerateCategory")
@{re} := reCompile(`(?P<name>.*), (?P<url>https://.*)`)
@-println("---\nbookToC: 2\nweight: 2\n---")
@-print("# ", $re.ReplaceAllString(category.Name, `[${name}](${url})`))
@<print("<!-- markdownlint-disable MD033 MD024 --->")
@-foreach ($func := category.Functions())
@{func} = function($func)
@-if (!$func.IsAlias)
@<printf("\n## __%s__\n", $func.Name)
@<print("```go")
@<println("func", include("trim", dict("text", stripColor($func.Signature))))
@-print("```")
@-if ($func.Description)
@<print("\n```")
@<template("trim", dict("text", $func.Description))
@<;```
@-else
@-warning($func.Name, "does not have description")
@-endif
@-if ($func.Aliases)
@<println("\n### Aliases")
@<printf("- _%s_", join("_\n- _", $func.Aliases))
@-endif
@-with ($func.Examples)
@<print("\n### Examples")
@-foreach ($ex := .)
@<print("\n```go")
@-with($ex.Razor) @<printf("Razor: %s", include("trim", dict("text", ., "indent", 10)));
@-with($ex.Template) @<printf("Template: %s", include("trim", dict("text", ., "indent", 10)));
@-with($ex.Result) @<printf("Result: %s", include("trim", dict("text", ., "indent", 10)));
@<print("```")
@-end for
@-end with
@-endif
@-end foreach
@end define
@-completeExamples()
@{re} := reCompile(`(?P<name>.*), https://.*`)
@-foreach ($category := categories())
@{content} := include("GenerateCategory", merge(dict("category", $category), $))
@{name} := $re.ReplaceAllString($category.Name, `${name}`)
@-info("Generating documentation for", $name)
@-save(joinPath(folder, lower($name))+".md", $content)
@--end foreach' -Vfolder=$DOC_FOLDER/functions_reference
printf -- '---\nbookFlatSection: true\nweight: 4\n---' > $DOC_FOLDER/functions_reference/_index.md
./gotemplate --no-extension '
@-println("---\nweight: 1\n---")
@<print("<!-- markdownlint-disable MD033 --->")
@{re} := reCompile(`(?P<name>.*), https://.*`)
@{reClean} := reCompile(`[^\w]+`)
@<print("# All functions")
@-foreach ($category := categories())
@{categoryName} := $re.ReplaceAllString($category.Name, `${name}`)
@<println("\n##", $categoryName)
@{categoryName} = $reClean.ReplaceAllString(lower($categoryName), `-`)
@-foreach ($func := $category.Functions())
@{func} = function($func)
@<printf(`<span class="flink"><a href="/gotemplate/docs/functions_reference/%s#%s">%s</a></span>`, $categoryName, lower($func.RealName), $func.Name)
@-end foreach
@--end foreach
' > $DOC_FOLDER/functions_reference/all_functions.md
# Add structs documentation
mkdir -p $DOC_FOLDER/objects
printf -- '---\nbookFlatSection: true\nweight: 5\n---' > $DOC_FOLDER/objects/_index.md
./gotemplate '@println("# String object\n")```go@<getMethods(String(""))@<;```' > $DOC_FOLDER/objects/string_methods.md
./gotemplate '@println("# StringArray object\n")```go@<getMethods(String("").Split(""))@<;```' > $DOC_FOLDER/objects/string_array_methods.md
./gotemplate '@println("# List object\n")```go@<getMethods(list())@<;```' > $DOC_FOLDER/objects/list_methods.md
./gotemplate '@println("# Dictionary object\n")```go<@getMethods(dict())@<;```' > $DOC_FOLDER/objects/dict_methods.md
# Copy README as the main page
printf -- '---\ntype: docs\n---' > $CONTENT_FOLDER/_index.md
cat README.md >> $CONTENT_FOLDER/_index.md