-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlister.jl
119 lines (102 loc) · 2.93 KB
/
lister.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
110
111
112
113
114
115
116
117
118
119
import Markdown
const _unexported_public_api = Any[
## ../docs/src/manual.md
# Experimental
channel_unordered,
append_unordered!,
ZipSource,
GetIndex,
SetIndex,
Inject,
## ../docs/src/interface.md
# Core interface for transducers
Transducer,
AbstractFilter,
R_,
inner,
xform,
start,
next,
complete,
# Helpers for stateful transducers
wrap,
unwrap,
wrapping,
# Interface for reducibles
__foldl__,
getproperty(@__MODULE__, Symbol("@return_if_reduced")),
getproperty(@__MODULE__, Symbol("@next")),
]
const _explicit_internal_list = Any[
# Manually list some internal objects to avoid Documenter.jl's
# "docstring potentially missing" warning:
DefaultInit,
]
is_internal(@nospecialize(t)) =
t ∈ _explicit_internal_list ||
(parentmodule(t) === @__MODULE__) && t ∉ _unexported_public_api
is_transducer_type(t) = t isa Type && t <: Transducer && t !== Transducer
is_transducer_type(::typeof(Zip)) = true
struct TransducerLister
m::Module
end
TransducerLister() = TransducerLister(@__MODULE__)
Transducer(tl::TransducerLister) = opcompose(
Filter() do x
t = getproperty(tl.m, x)
is_transducer_type(t)
end,
Map(x -> Docs.Binding(tl.m, x)),
)
(tl::TransducerLister)() = eduction(Transducer(tl), names(tl.m))
header_code(m::Markdown.MD) =
if !isempty(m.content)
header_code(m.content[1])
end
header_code(c::Markdown.Code) = c
header_code(::Any) = nothing
first_paragraph(m::Markdown.MD) =
if length(m.content) == 1
first_paragraph(m.content[1])
elseif length(m.content) > 1
first_paragraph(m.content[2])
end
first_paragraph(p::Markdown.Paragraph) = p
first_paragraph(::Any) = nothing
hasdoc(m::Module, b::Docs.Binding) = haskey(Docs.meta(m), b)
function Base.show(io::IO, ::MIME"text/markdown", tl::TransducerLister)
println(io, "| **Transducer** | **Summary** |")
println(io, "|:-- |:-- |")
foreach(tl()) do binding
hasdoc(tl.m, binding) || return
d = Docs.doc(binding)
h = header_code(d)
if h === nothing
shown = binding.var
else
shown, = split(h.code, "\n", limit=2)
end
p = first_paragraph(d)
if p === nothing
gist = ""
else
gist, = split(sprint(show, "text/markdown", Markdown.MD(p)),
"\n", limit=2)
end
println(io,
"| [`", shown, "`](@ref ", binding, ")",
" | ", gist,
" |")
end
end
function Markdown.MD(tl::TransducerLister)
io = IOBuffer()
show(io, "text/markdown", tl)
seek(io, 0)
return Markdown.parse(io)
end
Base.show(io::IO, mime::MIME"text/plain", tl::TransducerLister) =
_show(io, mime, tl)
Base.show(io::IO, mime::MIME"text/html", tl::TransducerLister) =
_show(io, mime, tl)
_show(io, mime, tl) = show(io, mime, Markdown.MD(tl))