-
Notifications
You must be signed in to change notification settings - Fork 351
Add grouping of modules #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add grouping of modules #780
Conversation
@@ -0,0 +1,2 @@ | |||
defmodule GroupedImplicitlyRegex do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modules should have a @moduledoc tag.
@@ -0,0 +1,2 @@ | |||
defmodule GroupedExplicitlyString do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modules should have a @moduledoc tag.
@@ -0,0 +1,2 @@ | |||
defmodule GroupedExplicitlyAtom do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modules should have a @moduledoc tag.
test/ex_doc/retriever_test.exs
Outdated
files = Enum.map names, fn(n) -> "test/tmp/Elixir.#{n}.beam" end | ||
config = %ExDoc.Config{source_url_pattern: url_pattern, source_root: File.cwd!} | ||
config = %ExDoc.Config{ | ||
source_url_pattern: url_pattern, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
test/ex_doc/retriever_test.exs
Outdated
[module_node] = docs_from_files ["CompiledWithDocs"] | ||
assert module_node.module == CompiledWithDocs | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
lib/ex_doc/retriever.ex
Outdated
|
||
defp module_group(module, group_patterns) do | ||
group_patterns | ||
|> Enum.find_value(fn {group, patterns} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a function call when a pipeline is only one function long
lib/ex_doc/retriever.ex
Outdated
|
||
defstruct id: nil, title: nil, module: nil, doc: nil, doc_line: nil, | ||
docs: [], typespecs: [], source_path: nil, source_url: nil, type: nil | ||
defstruct id: nil, title: nil, module: nil, group: nil, doc: nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
lib/ex_doc/retriever.ex
Outdated
defstruct id: nil, title: nil, module: nil, doc: nil, doc_line: nil, | ||
docs: [], typespecs: [], source_path: nil, source_url: nil, type: nil | ||
defstruct id: nil, title: nil, module: nil, group: nil, doc: nil, | ||
doc_line: nil, docs: [], typespecs: [], source_path: nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
lib/ex_doc/retriever.ex
Outdated
|
||
defp module_group(module, group_patterns) do | ||
group_patterns | ||
|> Enum.find_value(fn {group, patterns} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
lib/ex_doc/retriever.ex
Outdated
defp module_in_patterns(module, patterns) do | ||
"Elixir." <> module_string = Atom.to_string module | ||
|
||
Enum.any?(patterns, fn pattern -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
40dcf34
to
9fbdde0
Compare
test/ex_doc/retriever_test.exs
Outdated
assert functions == ["plus_one/1", "plus_two/1"] | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a final \n at the end of each file.
9fbdde0
to
5fe54cd
Compare
5fe54cd
to
a59e346
Compare
lib/ex_doc/retriever.ex
Outdated
|> Enum.map(&get_module(&1, config)) | ||
|> Enum.filter(&(&1)) | ||
|> Enum.sort(&(&1.id <= &2.id)) | ||
|> Enum.sort_by(&({&1.group, &1.id})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should order them by the group index in module_groups
. So the first group will be first, etc. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By now order was alphabetically by module name, so I feel like having groups sorted alphabetically isn't to bad. Also if you look at the example above in the PR description I've used a less strict regex as last group to catch all phoenix related modules, which weren't caught by the more precise earlier ones. So the order of groups might be useful for "catch-all" cases more so than for sorting order of the groups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But looking at the way groups worked with pages before, they are ordered by the order of first occurrence of a group, which might be a needed feature. Especially if we make the setup of both the same and deprecate the old way of grouping pages we should look out for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But looking at the way groups worked with pages before, they are ordered by the order of first occurrence of a group, which might be a needed feature.
Yup, precisely.
Plus if we give them control, they can keep it alphabetically. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really like to retain the user-defined "order of matching" as well, because otherwise the regex patterns might have to be more complex in places. Anything like "group all the remaining modules starting with MyAppWeb" won't be easy if the order in the list does determine the frontend order instead of the matching order. Having a regex exclude the matches of possibly multiple regexes can be quite a pain.
But maybe that's a topic for a later enhancement to the implementation.
lib/ex_doc/retriever.ex
Outdated
end | ||
|
||
defp module_in_patterns(module, patterns) do | ||
"Elixir." <> module_string = Atom.to_string module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not assume the module name is "Elixir." because of Erlang modules. You should probably use the module id or title.
lib/ex_doc/retriever.ex
Outdated
case pattern do | ||
%Regex{} = regex -> Regex.match?(regex, module_string) | ||
string when is_binary(string) -> module_string === string | ||
atom -> atom === module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use ==
and above. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can certainly do this. I'm just curious, how would/should one decide between ==
and ===
?
@@ -0,0 +1,3 @@ | |||
defmodule GroupedExplicitlyAtom do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to define new features. You can use the existing features and instead change the configuration every time you generate the docs. This can probably be done by changing this function to receive a keyword list that is merged into ExDoc.Config. then you just pass the module groups.
@LostKobrakai this looks really nice, I have added some comments. Regarding the templates tests, a unit test will suffice for now, just set the group manually. |
test/ex_doc/retriever_test.exs
Outdated
config = %ExDoc.Config{source_url_pattern: url_pattern, source_root: File.cwd!} | ||
config = | ||
%ExDoc.Config{source_url_pattern: "http://example.com/%{path}#L%{line}", source_root: File.cwd!} | ||
|> struct(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a function call when a pipeline is only one function long
test/ex_doc/retriever_test.exs
Outdated
defp docs_from_files(names, config \\ []) do | ||
files = Enum.map names, fn(n) -> "test/tmp/Elixir.#{n}.beam" end | ||
config = %ExDoc.Config{source_url_pattern: url_pattern, source_root: File.cwd!} | ||
config = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
source_url: source_url(), | ||
output: "test/tmp/html_templates" | ||
} | ||
|> struct(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a function call when a pipeline is only one function long
assert content =~ ~r("id":"CompiledWithDocs".*"functions":.*"example_without_docs/0")ms | ||
assert content =~ ~r("id":"CompiledWithDocs.Nested")ms | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
test/ex_doc/group_matcher_test.exs
Outdated
assert "Group" == match_module(patterns, :lists, ":lists") | ||
assert nil == match_module(patterns, MyApp.SomeOtherModule, "MyApp.SomeOtherModule") | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
test/ex_doc/group_matcher_test.exs
Outdated
assert nil == match_extra(patterns, "docs/introduction.md") | ||
end | ||
end | ||
end No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a final \n at the end of each file.
test/ex_doc/formatter/html_test.exs
Outdated
content = read_wildcard!("#{output_dir()}/dist/sidebar_items-*.js") | ||
assert content =~ ~r{"id":"readme","title":"README","group":"Intro"} | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
lib/ex_doc/group_matcher.ex
Outdated
end | ||
end) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no trailing white-space at the end of a line.
lib/ex_doc/group_matcher.ex
Outdated
defp match_patterns(patterns, matcher) do | ||
Enum.any?(patterns, matcher) || nil | ||
end | ||
end No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a final \n at the end of each file.
end | ||
|
||
defp build_extra(input, id, title, group, project_nodes, extension) do | ||
defp build_extra(input, id, title, group, project_nodes, extension, config) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function takes too many parameters (arity is 7, max is 5).
7ada3c5
to
41d299a
Compare
❤️ 💚 💙 💛 💜 |
Regarding #779.
By now I've just added grouping for modules. I can add the changes for the grouping of pages at a later time. Also I'm not sure where/how to test the changes to
ExDoc.Formatter.HTML.Templates
.Also:
Damn is it nice to use it even just for the following groups in phoenix projects.