-
Notifications
You must be signed in to change notification settings - Fork 11
/
render-doc
executable file
·89 lines (72 loc) · 2.42 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
#! /usr/bin/env bash
go build -o gotemplate
CONTENT_FOLDER="docs/content"
DOC_FOLDER="$CONTENT_FOLDER/docs"
export COLUMNS=1024
rm -rf $DOC_FOLDER
mkdir -p $DOC_FOLDER
# Generate usage info
echo '---
title: CLI Usage
weight: 1
---' > $DOC_FOLDER/CLI_Usage.md
COLUMNS=150 ./gotemplate '```text@<trim(exec("./gotemplate -h"))@<;```' --nv >> $DOC_FOLDER/CLI_Usage.md
# Generate detailed function info
./gotemplate --no-extension '## Functions
@completeExamples()
@foreach ($category := categories())
@-// We have to make a trick here by adding {{ "" }} otherwise, the entire line will be considered as a comment
### {{ "" }}@($category.Name)
@-foreach ($func := $category.Functions())
@{func} := function($func)
@-if (!$func.IsAlias)
@<;@<;```go
@-if ($func.Description)
@<;// @(String($func.Description).Lines.Join("\n// "))
@-endif
@-if ($func.Aliases)
@<;// Aliases: @join(", ", $func.Aliases)
@-endif
@<;func @{func.Signature}
@--{func.Examples}
@<;```
@-endif
@-end foreach
@end foreach' > $DOC_FOLDER/function_reference.md
# Add basics section
mkdir -p $DOC_FOLDER/basic_features
echo '---
bookFlatSection: true
weight: 2
---' > $DOC_FOLDER/basic_features/_index.md
# Add advanced section
mkdir -p $DOC_FOLDER/advanced_features
echo '---
bookFlatSection: true
weight: 3
---' > $DOC_FOLDER/advanced_features/_index.md
for file in docs_tests/**/*.md
do
./gotemplate -dP $file > ${file%.*}.razor
./gotemplate -P $file > ${file%.*}.rendered --accept-no-value
done
rsync -av docs_tests/ $DOC_FOLDER -r
# Add structs documentation
mkdir -p $DOC_FOLDER/Structs
echo '---
bookFlatSection: true
weight: 3
---' > $DOC_FOLDER/Structs/_index.md
# Generate methods on String objects
./gotemplate '```go@<getMethods(String(""))@<;```' > $DOC_FOLDER/Structs/string_methods.md
# Generate methods on StringArray objects
./gotemplate '```go@<getMethods(String("").Split(""))@<;```' > $DOC_FOLDER/Structs/string_array_methods.md
# Generate methods on List objects
./gotemplate '```go@<@getMethods(list())@<;```' > $DOC_FOLDER/Structs/list_methods.md
# Generate methods on Dictionary objects
./gotemplate '```go@<@getMethods(dict())@<;```' > $DOC_FOLDER/Structs/dict_methods.md
# Copy README as the main page
echo '---
type: docs
---' > $CONTENT_FOLDER/_index.md
cat README.md >> $CONTENT_FOLDER/_index.md