Skip to main content

Generate static documentation for your Elm application

Project description

elm-doc

Generate static documentation of your Elm application project.

Requires Python >= 3.5, rsync >= 2.6.7, and macOS or Linux. It may work on Windows but it's untested.

Supported Elm versions:

  • elm-doc version < 1.0: Elm 0.18
  • elm-doc version >= 1.0.0: Elm 0.19

You will need to enable the --pre flag if you're installing the latest version through the pip command.

Usage

Simplest invocation:

$ elm-doc . --output docs --fake-license 'SPDX license name'

The license name is required because elm-doc uses the official Elm binary to validate and generate docs; the official Elm binary only generates docs for a package project, and a package project requires a license to be set. While the license name will not be part of the generated doc, it will be associated with the project in the temporary elm.json file elm-doc generates during the build / validation.

Do no use elm-doc if you'd rather not risk the legal consequences of this fact. (IANAL: my understanding is OSS license doesn't take effect unless you distribute the code it's attached to.)

To view the generated docs, you'll need an HTTP server that can detect mimetypes based on file contents, rather than file extensions.

I personally use spark:

$ (cd doc && ~/go/bin/spark)

You can specify other attributes of the project with --fake-user, --fake-project, and --fake-version.

elm-doc creates a build directory named .elm-doc at the root of the project. You may want to ignore it in your SCM config, or you can change its path with --build-dir.

--validate can check if you have all the necessary documentation in place:

$ elm-doc . \
    --elm-path ./node_modules/.bin/elm \
    --validate

elm-doc assumes you're working on an app, not a package; it will try to generate documentation for all modules found in the application source directories.

You can --exclude-modules by using fnmatch patterns:

$ elm-doc . --output docs --fake-license 'SPDX license name' \
    --exclude-modules '*.Private.*,Blacklist.*'

or --exclude-source-directories entirely:

$ elm-doc . --output docs --fake-license 'SPDX license name' \
    --exclude-source-directories generated

You can also specify which files and directories to include in the list of modules:

$ elm-doc . --output docs \
    src/Whitelist src/Main.elm

Note that the --exclude flag takes no effect if you explicitly specify which files to include, unless you add the --force-exclusion flag:

$ elm-doc . --output docs --fake-license 'SPDX license name' \
    --exclude-modules '*.Private.*,Blacklist.*' \
    --force-exclusion \
    src/Whitelist src/Main.elm

For a full list of options, see:

$ elm-doc --help

Installation

In a Python (>=3.5) virtualenv or globally:

$ pip install --upgrade pip setuptools
$ pip install elm-doc

How it works

This is the rough build process:

  • Generate a temporary elm.json file in the build directory
    • Change the type to package and restructure / reformat to match the schema for a package project's elm.json
    • Populate --fake-* fields, including the license: these are required for a package project but not included in an application project's elm.json
    • Add dependencies that are listed as popular packages in the sidebar, making HTTP requests to look up the latest versions
    • This means the actual build / validation process will have its own elm-stuff directory
  • Copy source files into the build directory's src directory using rsync
    • An application project supports multiple source directories, while a package project supports only src
  • For each file that was copied, rewrite port delcarations to be normal functions
    • This is needed because ports are not allowed in package projects
  • Run elm make with the --doc flag on
  • If validating docs, exit here
  • Generate the top page of the package, individual module pages, and other files required for the package website to function
  • For each dependency, copy docs.json from the per-user package cache. This is generally in ~/.elm
  • For each dependency, also generate files required for the package website to function
  • Generate site-wide search index in a JSON format that the frontend expects
  • Generate help pages hosted by the package website
  • Extract frontend code that is prebuilt and distributed as part of the elm-doc Python package
    • It is a fork of the elm/package.elm-lang.org repo that takes a flag that specifies which URL path the frontend app is mounted at
  • These are all implemented as doit tasks

Development

Running tests:

$ nix-shell
$ poetry install
$ poetry run tox -e py35,...

Updating the prebuilt frontend code and test fixture:

$ poetry run doit

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elm-doc-1.0.0.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

elm_doc-1.0.0-py3-none-any.whl (600.7 kB view details)

Uploaded Python 3

File details

Details for the file elm-doc-1.0.0.tar.gz.

File metadata

  • Download URL: elm-doc-1.0.0.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.0a3 CPython/3.8.3 Linux/4.19.113-08528-g5803a1c7e9f9

File hashes

Hashes for elm-doc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 075d6961fb7fb6f9e302dcc920bc8ea1fea6b72e2218a49e6ca5899175117741
MD5 28d9f3faa22f7daf42ef9487982e0da9
BLAKE2b-256 5a9625a41046d3792c43c62146a8faa04fd3f69bb9a5aa1d28426889f1b96a67

See more details on using hashes here.

File details

Details for the file elm_doc-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: elm_doc-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 600.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.0a3 CPython/3.8.3 Linux/4.19.113-08528-g5803a1c7e9f9

File hashes

Hashes for elm_doc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bcfd6505532fd562f959eaff930c3a10e3a2ab12a6d0ad0802cd8db4389e02dc
MD5 7acdfe92d5702f4b5f960c356a1289fd
BLAKE2b-256 6693fcf19c290434cbbdb5877cd68eacc6d6d1447e366036f34d4fd675d30cc3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page