-
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
Merged
josevalim
merged 8 commits into
elixir-lang:master
from
LostKobrakai:feature/module_grouping
Sep 30, 2017
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a59e346
Add grouping of modules
LostKobrakai f4d04fc
Update retriever / tests according to José's comments
LostKobrakai 1526947
Add templates unit tests for groups of modules
LostKobrakai 6f0c182
Fix code formatting issues
LostKobrakai 50a822a
Sort groups by the order of setup
LostKobrakai 51ca972
Implement the new config setup for grouping extra pages
LostKobrakai 41d299a
Extract the matching logic into a new module
LostKobrakai fb72336
Rename config keys
LostKobrakai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
defmodule ExDoc.GroupMatcher do | ||
@moduledoc """ | ||
Match modules or extra pages to groups. | ||
|
||
Matching does happen by explicitly matching names or using regular expressions. | ||
""" | ||
@type pattern :: Regex.t | module() | String.t | ||
@type patterns :: pattern | [pattern] | ||
@type group_patterns :: keyword(patterns) | ||
|
||
@doc """ | ||
Does try to find a matching group for the given module name or id | ||
""" | ||
@spec match_module(group_patterns, module(), String.t) :: String.t | nil | ||
def match_module(group_patterns, module, id) do | ||
match_group_patterns(group_patterns, fn pattern -> | ||
case pattern do | ||
%Regex{} = regex -> Regex.match?(regex, id) | ||
string when is_binary(string) -> id == string | ||
atom -> atom == module | ||
end | ||
end) | ||
end | ||
|
||
@doc """ | ||
Does try to find a matching group for the given extra filename | ||
""" | ||
@spec match_extra(group_patterns, String.t) :: String.t | nil | ||
def match_extra(group_patterns, filename) do | ||
match_group_patterns(group_patterns, fn pattern -> | ||
case pattern do | ||
%Regex{} = regex -> Regex.match?(regex, filename) | ||
string when is_binary(string) -> filename == string | ||
end | ||
end) | ||
end | ||
|
||
defp match_group_patterns(group_patterns, matcher) do | ||
Enum.find_value(group_patterns, fn {group, patterns} -> | ||
patterns = List.wrap patterns | ||
match_patterns(patterns, matcher) && Atom.to_string(group) | ||
end) | ||
end | ||
|
||
defp match_patterns(patterns, matcher) do | ||
Enum.any?(patterns, matcher) || nil | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
defmodule ExDoc.GroupMatcherTest do | ||
use ExUnit.Case, async: true | ||
import ExDoc.GroupMatcher | ||
|
||
describe "module matching" do | ||
test "it can match modules by their atom names" do | ||
patterns = [ | ||
"Group": [MyApp.SomeModule, :lists] | ||
] | ||
assert "Group" == match_module(patterns, MyApp.SomeModule, "MyApp.SomeModule") | ||
assert "Group" == match_module(patterns, :lists, ":lists") | ||
assert nil == match_module(patterns, MyApp.SomeOtherModule, "MyApp.SomeOtherModule") | ||
end | ||
|
||
test "it can match modules by their string names" do | ||
patterns = [ | ||
"Group": ["MyApp.SomeModule", ":lists"] | ||
] | ||
assert "Group" == match_module(patterns, MyApp.SomeModule, "MyApp.SomeModule") | ||
assert "Group" == match_module(patterns, :lists, ":lists") | ||
assert nil == match_module(patterns, MyApp.SomeOtherModule, "MyApp.SomeOtherModule") | ||
end | ||
|
||
test "it can match modules by regular expressions" do | ||
patterns = [ | ||
"Group": ~r/MyApp\..?/ | ||
] | ||
assert "Group" == match_module(patterns, MyApp.SomeModule, "MyApp.SomeModule") | ||
assert "Group" == match_module(patterns, MyApp.SomeOtherModule, "MyApp.SomeOtherModule") | ||
assert nil == match_module(patterns, MyAppWeb.SomeOtherModule, "MyAppWeb.SomeOtherModule") | ||
end | ||
end | ||
|
||
describe "extras matching" do | ||
test "it can match extra files by their string names" do | ||
patterns = [ | ||
"Group": ["docs/handling/testing.md"] | ||
] | ||
assert "Group" == match_extra(patterns, "docs/handling/testing.md") | ||
assert nil == match_extra(patterns, "docs/handling/setup.md") | ||
end | ||
|
||
test "it can match extra files by regular expressions" do | ||
patterns = [ | ||
"Group": ~r/docs\/handling?/ | ||
] | ||
assert "Group" == match_extra(patterns, "docs/handling/testing.md") | ||
assert "Group" == match_extra(patterns, "docs/handling/setup.md") | ||
assert nil == match_extra(patterns, "docs/introduction.md") | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).