-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.jl
75 lines (72 loc) · 2.15 KB
/
generate.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
function newline!(results)
if !isempty(results) && !endswith(results[end], "\n")
push!(results, "\n")
end
end
function markdownsource(f, results=[]; doeval=true, exception=exception)
c = []
function code(c)
if isempty(c) return end
newline!(results)
push!(results, "```julia\n")
append!(results, c)
empty!(c)
newline!(results)
push!(results, "``` \n")
end
for l in eachline(f, keep=true)
if startswith(l, "#md#")
code(c)
push!(results, l[6:end])
elseif startswith(l, "#eval#")
if doeval
try
eval(Meta.parse(l[8:end]))
catch ex
if exception
throw(ex)
else
@warn ex
end
end
end
else
push!(c, l)
end
end
code(c)
results
end
using WordCloud
eval.(Meta.parse.(ARGS))
doeval = (@isdefined doeval) ? doeval : true
exception = (@isdefined exception) ? exception : true
function examplesmarkdown(examples=WordCloud.EXAMPLES; doeval=doeval, exception=exception)
mds= [
"# WordCloud-Gallery\n"
"This is a gallery of [WordCloud.jl](https://github.com/guo-yong-zhi/WordCloud), which is automatically generated from `WordCloud.EXAMPLES` (WordCloud v$(pkgversion(WordCloud))). "
"Run `evalfile(\"generate.jl\", [\"doeval=true\", \"exception=true\"])` in julia REPL to create this file. \n"
["- [$e](#$(lowercase(replace(e, " "=>"-"))))\n" for e in examples]...
]
doeval = doeval isa Bool ? doeval : Set(string.(doeval))
for e in examples
println("#"^10, e, "#"^10)
try
push!(mds, "# $e\n")
de = doeval isa Bool ? doeval : e in doeval
markdownsource(pkgdir(WordCloud)*"/examples/$e.jl", mds, doeval=de)
newline!(mds)
catch ex
if exception
throw(ex)
else
@warn ex
end
end
end
mds
end
function main()
write("README.md", examplesmarkdown()...);
end
main()