Skip to content

Commit

Permalink
Fixes and add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusmuller committed Sep 7, 2023
1 parent c8310b5 commit c7d5ac6
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/ex_doc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ defmodule ExDoc 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, config)
{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
Expand Down
5 changes: 4 additions & 1 deletion lib/ex_doc/autolink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ defmodule ExDoc.Autolink do
# * `:skip_undefined_reference_warnings_on` - list of modules to skip the warning on
#
# * `:skip_code_autolink_to` - list of terms that will be skipped when autolinking (e.g: "PrivateModule")
#
# * `:filtered_modules` - A list of module nodes that were filtered by the retriever

defstruct [
:current_module,
Expand All @@ -35,7 +37,8 @@ defmodule ExDoc.Autolink do
ext: ".html",
siblings: [],
skip_undefined_reference_warnings_on: [],
skip_code_autolink_to: []
skip_code_autolink_to: [],
filtered_modules: []
]

@hexdocs "https://hexdocs.pm/"
Expand Down
8 changes: 6 additions & 2 deletions lib/ex_doc/formatter/epub.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ defmodule ExDoc.Formatter.EPUB do
Generate EPUB documentation for the given modules.
"""
@spec run(list, ExDoc.Config.t()) :: String.t()
def run(project_nodes, config) when is_map(config) do
def run(project_nodes, config) when is_list(project_nodes) and is_map(config) do
run({project_nodes, []}, config)
end

def run({project_nodes, filtered_modules}, config) when is_map(config) do
parent = config.output
config = normalize_config(config)

Expand All @@ -19,7 +23,7 @@ defmodule ExDoc.Formatter.EPUB do
&create_output_dir(&1, config)
)

project_nodes = HTML.render_all(project_nodes, ".xhtml", config, highlight_tag: "samp")
project_nodes = HTML.render_all(project_nodes, filtered_modules, ".xhtml", config, highlight_tag: "samp")

nodes_map = %{
modules: HTML.filter_list(:module, project_nodes),
Expand Down
21 changes: 16 additions & 5 deletions lib/ex_doc/formatter/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ defmodule ExDoc.Formatter.HTML do
@doc """
Generate HTML documentation for the given modules.
"""
@spec run(list, ExDoc.Config.t()) :: String.t()
def run(project_nodes, config) when is_map(config) do
# TODO: improve this spec
@spec run(
[ExDoc.ModuleNode.t()]
| {[ExDoc.ModuleNode.t()], [ExDoc.ModuleNode.t()]},
ExDoc.Config.t()
) :: String.t()

def run(project_nodes, config) when is_list(project_nodes) and is_map(config) do
run({project_nodes, []}, config)
end

def run({project_nodes, filtered_modules}, config) when is_map(config) do
config = normalize_config(config)
config = %{config | output: Path.expand(config.output)}

build = Path.join(config.output, ".build")
setup_output(config.output, &cleanup_output_dir(&1, config), &create_output_dir(&1, config))

project_nodes = render_all(project_nodes, ".html", config, [])
project_nodes = render_all(project_nodes, filtered_modules, ".html", config, [])
extras = build_extras(config, ".html")

# Generate search early on without api reference in extras
Expand Down Expand Up @@ -64,14 +74,15 @@ defmodule ExDoc.Formatter.HTML do
@doc """
Autolinks and renders all docs.
"""
def render_all(project_nodes, ext, config, opts) do
def render_all(project_nodes, filtered_modules, ext, config, opts) do
base = [
apps: config.apps,
deps: config.deps,
ext: ext,
extras: extra_paths(config),
skip_undefined_reference_warnings_on: config.skip_undefined_reference_warnings_on,
skip_code_autolink_to: config.skip_code_autolink_to
skip_code_autolink_to: config.skip_code_autolink_to,
filtered_modules: filtered_modules
]

project_nodes
Expand Down
6 changes: 5 additions & 1 deletion lib/ex_doc/language/elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,16 @@ defmodule ExDoc.Language.Elixir do
(\(.*\)) # Arguments <rest />
}x

Regex.replace(regex, string, fn _all, call_string, module_string, name_string, rest ->
Regex.replace(regex, string, fn all, call_string, module_string, name_string, rest ->
module = string_to_module(module_string)
name = String.to_atom(name_string)
arity = count_args(rest, 0, 0)
original_text = call_string <> "()"

if Enum.any?(config.filtered_modules, &(&1.id == module_string)) do
warn("Typespec references filtered module: #{all}", {config.file, config.line}, config.id)
end

url =
if module do
remote_url({:type, module, name, arity}, config, original_text)
Expand Down
2 changes: 1 addition & 1 deletion test/ex_doc/formatter/epub/templates_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule ExDoc.Formatter.EPUB.TemplatesTest do
defp get_module_page(names, config \\ []) do
config = doc_config(config)
{mods, []} = ExDoc.Retriever.docs_from_modules(names, config)
[mod | _] = HTML.render_all(mods, ".xhtml", config, highlight_tag: "samp")
[mod | _] = HTML.render_all(mods, [], ".xhtml", config, highlight_tag: "samp")
Templates.module_page(config, mod)
end

Expand Down
4 changes: 2 additions & 2 deletions test/ex_doc/formatter/html/templates_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule ExDoc.Formatter.HTML.TemplatesTest do
defp get_module_page(names, context, config \\ []) do
config = doc_config(context, config)
{mods, []} = ExDoc.Retriever.docs_from_modules(names, config)
[mod | _] = HTML.render_all(mods, ".html", config, [])
[mod | _] = HTML.render_all(mods, [], ".html", config, [])
Templates.module_page(mod, @empty_nodes_map, config)
end

Expand Down Expand Up @@ -421,7 +421,7 @@ defmodule ExDoc.Formatter.HTML.TemplatesTest do
names = [CompiledWithDocs, CompiledWithoutDocs, DuplicateHeadings]
config = doc_config(context)
{nodes, []} = ExDoc.Retriever.docs_from_modules(names, config)
nodes = HTML.render_all(nodes, ".html", config, [])
nodes = HTML.render_all(nodes, [], ".html", config, [])

[compiled_with_docs, compiled_without_docs, duplicate_headings] =
create_sidebar_items(%{modules: nodes}, [])["modules"]
Expand Down
2 changes: 1 addition & 1 deletion test/ex_doc_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ defmodule ExDocTest do
source_beam: "beam_dir"
]

{source_dir, _config} = ExDoc.generate_docs("Elixir", "1", options)
assert {{source_dir, _retr_config}, _config} = ExDoc.generate_docs("Elixir", "1", options)
assert source_dir == options[:source_beam]
end

Expand Down

0 comments on commit c7d5ac6

Please sign in to comment.