-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenerate_readme.jl
executable file
·109 lines (84 loc) · 2.54 KB
/
generate_readme.jl
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
#!/bin/bash
# -*- mode: julia -*-
#=
JULIA="${JULIA:-julia}"
JULIA_CMD="${JULIA_CMD:-${JULIA} --color=yes --startup-file=no}"
thisdir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
rootdir="$(dirname "$thisdir")"
export JULIA_PROJECT="$thisdir"
export JULIA_LOAD_PATH="@"
set -ex
${JULIA_CMD} \
-e 'using Pkg; Pkg.develop(name="InteractiveCodeSearch", url=ARGS[1])' \
"$rootdir"
exec ${JULIA_CMD} "${BASH_SOURCE[0]}" "$@"
=#
header = """
[![Build Status][ci-img]][ci-url]
[![codecov.io][codecov-img]][codecov-url]

"""
footer = """
[ci-img]: https://github.com/tkf/InteractiveCodeSearch.jl/actions/workflows/test.yml/badge.svg
[ci-url]: https://github.com/tkf/InteractiveCodeSearch.jl/actions/workflows/test.yml
[codecov-img]: http://codecov.io/github/tkf/InteractiveCodeSearch.jl/coverage.svg?branch=master
[codecov-url]: http://codecov.io/github/tkf/InteractiveCodeSearch.jl?branch=master
<!--
Generated by `./scripts/generate_readme.jl README.md`.
-->
"""
using Base.Docs: doc
import Markdown
using Documenter.Writers.MarkdownWriter: dropheaders
import InteractiveCodeSearch
function generate_readme(io::IO = stdout)
text = sprint(show, "text/markdown", @doc InteractiveCodeSearch)
lines = split(text, "\n")
println(io, lines[1])
println(io, header)
for line in lines[2:end]
println(io, line)
end
println(io, "## Reference")
println(io)
function loc(f)
m1, = methods(f).ms
return (m1.file, m1.line)
end
exports = [
(name, getproperty(InteractiveCodeSearch, name))
for name in names(InteractiveCodeSearch)
]
exports = filter((x -> x[2] isa Function), exports)
exports = sort(collect(exports), by=x -> loc(x[2]))
for (name, exported) in exports
md = dropheaders(doc(exported))
println(io, "### `$name`")
println(io)
show(io, "text/markdown", md)
println(io)
println(io)
end
println(io, "### `InteractiveCodeSearch.CONFIG`")
show(io, "text/markdown", dropheaders(@doc InteractiveCodeSearch.CONFIG))
println(io)
println(io)
print(io, footer)
end
function generate_readme(filename::AbstractString)
open(filename, "w") do io
generate_readme(io)
end
end
function rerender()
io = IOBuffer()
generate_readme(io)
seek(io, 0)
return Markdown.parse(io)
end
if isinteractive()
# so that it can be called via `include("scripts/generate_readme.jl")()`
generate_readme
else
generate_readme(ARGS...)
end