Skip to content

Commit ed109f0

Browse files
committed
Simplify skipping modules
1 parent 5887fb1 commit ed109f0

File tree

4 files changed

+34
-53
lines changed

4 files changed

+34
-53
lines changed

lib/ex_doc/language.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ defmodule ExDoc.Language do
1818
1919
* `:type` - module type
2020
21-
* `:skip` - whether module should be skipped from generating the docs
22-
2321
* `:line` - the line where the code is located
2422
2523
* `:callback_types` - a list of types that are considered callbacks
@@ -36,7 +34,6 @@ defmodule ExDoc.Language do
3634
id: String.t(),
3735
title: String.t(),
3836
type: atom() | nil,
39-
skip: boolean(),
4037
line: non_neg_integer(),
4138
callback_types: [atom()],
4239
nesting_info: {String.t(), String.t()} | nil,
@@ -46,7 +43,7 @@ defmodule ExDoc.Language do
4643
@doc """
4744
Returns a map with module information.
4845
"""
49-
@callback module_data(module(), tuple(), ExDoc.Config.t()) :: module_data()
46+
@callback module_data(module(), tuple(), ExDoc.Config.t()) :: module_data() | :skip
5047

5148
@doc """
5249
Returns a map with function information.

lib/ex_doc/language/elixir.ex

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,32 @@ defmodule ExDoc.Language.Elixir do
1212
@impl true
1313
def module_data(module, docs_chunk, config) do
1414
{type, skip} = module_type_and_skip(module)
15-
title = module_title(module, type)
16-
abst_code = Erlang.get_abstract_code(module)
17-
line = Erlang.find_module_line(module, abst_code)
1815

19-
%{
20-
module: module,
21-
docs: docs_chunk,
22-
language: __MODULE__,
23-
id: inspect(module),
24-
title: title,
25-
type: type,
26-
skip: skip,
27-
line: line,
28-
callback_types: [:callback, :macrocallback],
29-
nesting_info: nesting_info(title, config.nest_modules_by_prefix),
30-
private: %{
31-
abst_code: abst_code,
32-
specs: Erlang.get_specs(module),
33-
callbacks: Erlang.get_callbacks(module),
34-
impls: get_impls(module)
16+
if skip do
17+
:skip
18+
else
19+
title = module_title(module, type)
20+
abst_code = Erlang.get_abstract_code(module)
21+
line = Erlang.find_module_line(module, abst_code)
22+
23+
%{
24+
module: module,
25+
docs: docs_chunk,
26+
language: __MODULE__,
27+
id: inspect(module),
28+
title: title,
29+
type: type,
30+
line: line,
31+
callback_types: [:callback, :macrocallback],
32+
nesting_info: nesting_info(title, config.nest_modules_by_prefix),
33+
private: %{
34+
abst_code: abst_code,
35+
specs: Erlang.get_specs(module),
36+
callbacks: Erlang.get_callbacks(module),
37+
impls: get_impls(module)
38+
}
3539
}
36-
}
40+
end
3741
end
3842

3943
@impl true

lib/ex_doc/language/erlang.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ defmodule ExDoc.Language.Erlang do
1818
id: id,
1919
title: id,
2020
type: module_type(module),
21-
skip: false,
2221
line: line,
2322
callback_types: [:callback],
2423
nesting_info: nil,

lib/ex_doc/retriever.ex

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,20 @@ defmodule ExDoc.Retriever do
5151
String.to_atom(name)
5252
end
5353

54-
# Get all the information from the module and compile
55-
# it. If there is an error while retrieving the information (like
56-
# the module is not available or it was not compiled
57-
# with --docs flag), we raise an exception.
5854
defp get_module(module, config) do
59-
if docs_chunk = docs_chunk(module) do
60-
module_data =
61-
module
62-
|> get_module_data(docs_chunk, config)
63-
|> maybe_skip(config.filter_prefix)
64-
65-
if not module_data.skip do
66-
[generate_node(module, module_data, config)]
67-
else
68-
[]
69-
end
55+
with {:docs_v1, _, language, _, _, _, _} = docs_chunk <- docs_chunk(module),
56+
language = ExDoc.Language.get(language),
57+
%{} = module_data <- language.module_data(module, docs_chunk, config),
58+
false <- skip_module?(module_data, config) do
59+
[generate_node(module, module_data, config)]
7060
else
71-
[]
61+
_ ->
62+
[]
7263
end
7364
end
7465

75-
defp maybe_skip(module_data, filter_prefix) do
76-
if filter_prefix && not String.starts_with?(module_data.id, filter_prefix) do
77-
%{module_data | skip: true}
78-
else
79-
module_data
80-
end
66+
defp skip_module?(module_data, config) do
67+
!!config.filter_prefix and not String.starts_with?(module_data.id, config.filter_prefix)
8168
end
8269

8370
defp docs_chunk(module) do
@@ -170,12 +157,6 @@ defmodule ExDoc.Retriever do
170157

171158
# Module Helpers
172159

173-
defp get_module_data(module, docs_chunk, config) do
174-
{:docs_v1, _, language, _, _, _, _} = docs_chunk
175-
language = ExDoc.Language.get(language)
176-
language.module_data(module, docs_chunk, config)
177-
end
178-
179160
defp get_module_docs(module_data, source_path) do
180161
{:docs_v1, anno, _, content_type, moduledoc, metadata, _} = module_data.docs
181162
doc_line = anno_line(anno)

0 commit comments

Comments
 (0)