Skip to content

Commit

Permalink
Simplify skipping modules
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach committed Jul 28, 2021
1 parent 5887fb1 commit ed109f0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 53 deletions.
5 changes: 1 addition & 4 deletions lib/ex_doc/language.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ defmodule ExDoc.Language do
* `:type` - module type
* `:skip` - whether module should be skipped from generating the docs
* `:line` - the line where the code is located
* `:callback_types` - a list of types that are considered callbacks
Expand All @@ -36,7 +34,6 @@ defmodule ExDoc.Language do
id: String.t(),
title: String.t(),
type: atom() | nil,
skip: boolean(),
line: non_neg_integer(),
callback_types: [atom()],
nesting_info: {String.t(), String.t()} | nil,
Expand All @@ -46,7 +43,7 @@ defmodule ExDoc.Language do
@doc """
Returns a map with module information.
"""
@callback module_data(module(), tuple(), ExDoc.Config.t()) :: module_data()
@callback module_data(module(), tuple(), ExDoc.Config.t()) :: module_data() | :skip

@doc """
Returns a map with function information.
Expand Down
44 changes: 24 additions & 20 deletions lib/ex_doc/language/elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,32 @@ defmodule ExDoc.Language.Elixir do
@impl true
def module_data(module, docs_chunk, config) do
{type, skip} = module_type_and_skip(module)
title = module_title(module, type)
abst_code = Erlang.get_abstract_code(module)
line = Erlang.find_module_line(module, abst_code)

%{
module: module,
docs: docs_chunk,
language: __MODULE__,
id: inspect(module),
title: title,
type: type,
skip: skip,
line: line,
callback_types: [:callback, :macrocallback],
nesting_info: nesting_info(title, config.nest_modules_by_prefix),
private: %{
abst_code: abst_code,
specs: Erlang.get_specs(module),
callbacks: Erlang.get_callbacks(module),
impls: get_impls(module)
if skip do
:skip
else
title = module_title(module, type)
abst_code = Erlang.get_abstract_code(module)
line = Erlang.find_module_line(module, abst_code)

%{
module: module,
docs: docs_chunk,
language: __MODULE__,
id: inspect(module),
title: title,
type: type,
line: line,
callback_types: [:callback, :macrocallback],
nesting_info: nesting_info(title, config.nest_modules_by_prefix),
private: %{
abst_code: abst_code,
specs: Erlang.get_specs(module),
callbacks: Erlang.get_callbacks(module),
impls: get_impls(module)
}
}
}
end
end

@impl true
Expand Down
1 change: 0 additions & 1 deletion lib/ex_doc/language/erlang.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ defmodule ExDoc.Language.Erlang do
id: id,
title: id,
type: module_type(module),
skip: false,
line: line,
callback_types: [:callback],
nesting_info: nil,
Expand Down
37 changes: 9 additions & 28 deletions lib/ex_doc/retriever.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,20 @@ defmodule ExDoc.Retriever do
String.to_atom(name)
end

# Get all the information from the module and compile
# it. If there is an error while retrieving the information (like
# the module is not available or it was not compiled
# with --docs flag), we raise an exception.
defp get_module(module, config) do
if docs_chunk = docs_chunk(module) do
module_data =
module
|> get_module_data(docs_chunk, config)
|> maybe_skip(config.filter_prefix)

if not module_data.skip do
[generate_node(module, module_data, config)]
else
[]
end
with {:docs_v1, _, language, _, _, _, _} = docs_chunk <- docs_chunk(module),
language = ExDoc.Language.get(language),
%{} = module_data <- language.module_data(module, docs_chunk, config),
false <- skip_module?(module_data, config) do
[generate_node(module, module_data, config)]
else
[]
_ ->
[]
end
end

defp maybe_skip(module_data, filter_prefix) do
if filter_prefix && not String.starts_with?(module_data.id, filter_prefix) do
%{module_data | skip: true}
else
module_data
end
defp skip_module?(module_data, config) do
!!config.filter_prefix and not String.starts_with?(module_data.id, config.filter_prefix)
end

defp docs_chunk(module) do
Expand Down Expand Up @@ -170,12 +157,6 @@ defmodule ExDoc.Retriever do

# Module Helpers

defp get_module_data(module, docs_chunk, config) do
{:docs_v1, _, language, _, _, _, _} = docs_chunk
language = ExDoc.Language.get(language)
language.module_data(module, docs_chunk, config)
end

defp get_module_docs(module_data, source_path) do
{:docs_v1, anno, _, content_type, moduledoc, metadata, _} = module_data.docs
doc_line = anno_line(anno)
Expand Down

0 comments on commit ed109f0

Please sign in to comment.