Skip to content

Commit

Permalink
Rename internal nodes for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Nov 21, 2022
1 parent 5a0aa08 commit a4ea93c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/ex_doc/formatter/html/templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ defmodule ExDoc.Formatter.HTML.Templates do
def module_summary(module_node) do
entries =
[Types: module_node.typespecs] ++
function_groups(module_node.function_groups, module_node.docs)
docs_groups(module_node.docs_groups, module_node.docs)

Enum.reject(entries, fn {_type, nodes} -> nodes == [] end)
end

defp function_groups(groups, docs) do
defp docs_groups(groups, docs) do
for group <- groups, do: {group, Enum.filter(docs, &(&1.group == group))}
end

Expand Down
4 changes: 2 additions & 2 deletions lib/ex_doc/nodes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule ExDoc.ModuleNode do
doc: nil,
rendered_doc: nil,
doc_line: nil,
function_groups: [],
docs_groups: [],
docs: [],
typespecs: [],
source_path: nil,
Expand All @@ -35,7 +35,7 @@ defmodule ExDoc.ModuleNode do
doc: ExDoc.DocAST.t() | nil,
rendered_doc: String.t() | nil,
doc_line: non_neg_integer(),
function_groups: [atom()],
docs_groups: [atom()],
docs: [ExDoc.FunctionNode.t()],
typespecs: [ExDoc.TypeNode.t()],
source_path: String.t(),
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_doc/retriever.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ defmodule ExDoc.Retriever do
groups_for_functions =
config.groups_for_functions ++ [Callbacks: & &1[:__callback__], Functions: fn _ -> true end]

function_groups = Enum.map(groups_for_functions, &elem(&1, 0))
docs_groups = Enum.map(groups_for_functions, &elem(&1, 0))
function_docs = get_docs(module_data, source, groups_for_functions)
docs = function_docs ++ get_callbacks(module_data, source, groups_for_functions)
types = get_types(module_data, source)
Expand All @@ -125,7 +125,7 @@ defmodule ExDoc.Retriever do
module: module,
type: module_data.type,
deprecated: metadata[:deprecated],
function_groups: function_groups,
docs_groups: docs_groups,
docs: ExDoc.Utils.natural_sort_by(docs, &"#{&1.name}/#{&1.arity}"),
doc: moduledoc,
doc_line: doc_line,
Expand Down
15 changes: 8 additions & 7 deletions lib/mix/tasks/docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ defmodule Mix.Tasks.Docs do
A regex or the string name of the module is also supported.
### Grouping functions
### Grouping functions and callbacks
Functions inside a module can also be organized in groups. This is done via
the `:groups_for_functions` configuration which is a keyword list of group
titles and filtering functions that receive the documentation metadata of
functions as argument.
Functions and callbacks inside a module can also be organized in groups.
This is done via the `:groups_for_functions` configuration which is a
keyword list of group titles and filtering functions that receive the
documentation metadata of functions as argument.
For example, imagine that you have an API client library with a large surface
area for all the API endpoints you need to support. It would be helpful to
Expand All @@ -247,8 +247,9 @@ defmodule Mix.Tasks.Docs do
]
A function can belong to a single group only. If multiple group filters match,
the first will take precedence. Functions that don't have a custom group will
be listed under the default "Functions" group.
the first will take precedence. Functions and callbacks that don't have a
custom group will be listed under the default "Functions" and "Callbacks"
group respectively.
## Additional JavaScript config
Expand Down
2 changes: 1 addition & 1 deletion test/ex_doc/retriever/erlang_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule ExDoc.Retriever.ErlangTest do
deprecated: nil,
doc_line: _,
docs: [function1, function2],
function_groups: [:Callbacks, :Functions],
docs_groups: [:Callbacks, :Functions],
group: nil,
id: "mod",
language: ExDoc.Language.Erlang,
Expand Down

0 comments on commit a4ea93c

Please sign in to comment.