Skip to content

Conversation

davidsulc
Copy link
Contributor

(Tests and documentation still need to be written, this is just for preliminary feedback.)

A basic implementation for #834

It leverages groups_for_modules to provide the usual UI presentation, and to leverage the current ordering ability. As suggested by José, a nest_module_aliases key was added to the docs config.

This new value is an array of alias configs, each of which is one of:

  • ModuleName (equivalent to {ModuleName, as: ModuleName})
  • {Super.Duper.Really.Long.ModuleName, as: Some.ModuleName}
  • {Super.Duper.Really.Long.ModuleName, as: "My module"}

The as: values are used as group names (as if they had been provided to groups_for_modules) and are removed from the module's displayed title.

Hopefully, this will be familiar to language users as it combine the as: syntax of module aliases with the multiple value formats as can be used when specifying child configs in supervisors.

The objective for this first implementation is to provide enough flexibility while keeping the code changes simple. It is to be noted that the aliasing is very naive: the first match is kept, without attempting to find the longest prefix possible.

With these modifications, nesting could be specified like this (adapted from ExDoc's mix.exs):

      groups_for_modules: [
        "Markdown": [],
        "Formatter API": [
          ExDoc.Config,
          ExDoc.FunctionNode,
          ExDoc.ModuleNode,
          ExDoc.TypeNode
        ],
        "ExDoc.Formatter": []
      ],
      nest_module_aliases: [
        {ExDoc.Markdown, as: Markdown},
        #{ExDoc.Markdown, as: "Foo bar"},
        ExDoc.Formatter
      ]

Adding empty groups matching as: values (or the module name, if absent) in nest_modules_aliases allows controlling the ordering of the blocks of nested modules.

Here's the generated result:

nested_ex_doc

options
|> Keyword.get(:nest_module_aliases)
|> Enum.map(&normalize_nest_module_alias/1)
|> Enum.into(%{})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum.into/3 is more efficient than Enum.map/2 |> Enum.into/2

@sourcelevel-bot
Copy link

Ebert has finished reviewing this Pull Request and has found:

  • 1 possible new issue (including those that may have been commented here).

You can see more details about this review at https://ebertapp.io/github/elixir-lang/ex_doc/pulls/905.

@davidsulc davidsulc closed this Oct 15, 2018
@davidsulc davidsulc deleted the nest-module-aliases branch October 15, 2018 22:39
@davidsulc
Copy link
Contributor Author

Sorry, meant to open this in my forked repo. I will open a PR here once it is finalized (with tests and docs)

@davidsulc davidsulc restored the nest-module-aliases branch October 15, 2018 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant