Appendix B. Generating Documentation with ExDoc
In Chapter 2, you learned how to add documentation to your programs. The ExDoc tool takes that documentation and produces nicely formatted reference documentation in web page format. ExDoc works in conjunction with Mix, a tool for creating, compiling, and testing projects.You can find out more about Mix in Chapter 13.
Using ExDoc with mix
The easiest way to create documentation is to create a project using the mix tool, using a command of the form:
mix new _project_name_
Here is what it looks like when creating the documentation for the code in Example 2-4.
$ mix new combined
* creating README.md
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/combined.ex
* creating test
* creating test/test_helper.exs
* creating test/combined_test.exs
Your mix project was created successfully.
You can use "mix" to compile it, test it, and more:
cd combined
mix test
Run "mix help" for more commands.
Change to the combined directory and put all of your source files (for this example, combined.ex, drop.ex, and convert.ex) into the lib directory. The combined.ex file you have written before will replace the one in that mix created for you in the lib directory.
Now edit the file mix.exs so that the deps function reads as follows:
defdepsdo[{:ex_doc,github:"elixir-lang/ex_doc}]end
Typing mix deps.get will install ExDoc in a directory named deps. If you have not yet installed Hex (Elixir’s package manager), mix will prompt ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access