-
Notifications
You must be signed in to change notification settings - Fork 341
/
Copy pathex_doc.ex
55 lines (46 loc) · 1.52 KB
/
ex_doc.ex
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
defmodule ExDoc do
@moduledoc false
@ex_doc_version Mix.Project.config()[:version]
@doc """
Returns the ExDoc version (used in templates).
"""
@spec version :: String.t()
def version, do: @ex_doc_version
@doc """
Generates documentation for the given `project`, `vsn` (version)
and `options`.
"""
@spec generate_docs(String.t(), String.t(), Keyword.t()) :: atom
def generate_docs(project, vsn, options)
when is_binary(project) and is_binary(vsn) and is_list(options) do
config = ExDoc.Config.build(project, vsn, options)
if processor = options[:markdown_processor] do
ExDoc.Markdown.put_markdown_processor(processor)
end
{module_nodes, filtered_nodes} = config.retriever.docs_from_dir(config.source_beam, config)
find_formatter(config.formatter).run(module_nodes, filtered_nodes, config)
end
# Short path for programmatic interface
defp find_formatter(modname) when is_atom(modname), do: modname
defp find_formatter("ExDoc.Formatter." <> _ = name) do
[name]
|> Module.concat()
|> check_formatter_module(name)
end
defp find_formatter(name) do
[ExDoc.Formatter, modname(name)]
|> Module.concat()
|> check_formatter_module(name)
end
defp modname("epub"), do: EPUB
defp modname("html"), do: HTML
defp modname("markdown"), do: Markdown
defp modname(_), do: nil
defp check_formatter_module(modname, argname) do
if Code.ensure_loaded?(modname) do
modname
else
raise "formatter module #{inspect(argname)} not found"
end
end
end