O'Reilly logo

Introducing Elixir by J. David Eisenberg, Simon St. Laurent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

def deps do
  [{: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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required