• Stars
    star
    667
  • Rank 67,625 (Top 2 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created about 13 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Clojure documentation tool

Codox

A tool for generating API documentation from Clojure or ClojureScript source code.

Usage

Leiningen

Include the following plugin in your project.clj file or your global profile:

:plugins [[lein-codox "0.10.8"]]

Then run:

lein codox

This will generate API documentation in the "target/doc" subdirectory (or wherever your project :target-path is set to).

Boot

Add boot-codox to your build.boot dependencies and require the namespace:

(set-env! :dependencies '[[boot-codox "0.10.8" :scope "test"]])
(require '[codox.boot :refer [codox]])

You can see the options available on the command line:

$ boot codox -h

or in the REPL:

boot.user=> (doc codox)

Remember to output files to the target directory with boot's built-in target task:

$ boot codox target

deps.edn

Add an alias to your deps.edn:

:codox {:extra-deps {codox/codox {:mvn/version "0.10.8"}}
        :exec-fn codox.main/generate-docs
        :exec-args {:source-paths ["path/to/src"]}}

When using deps.edn, project options should be added to the :exec-args map in your Codox alias, as above. This behavior differs from the examples in "Project Options" section, which use the Leiningen configuration format.

Run Codox via -X like this:

clojure -X:codox

Note: Codox expects the code it analyzes to be on the classpath so you may need to specify additional aliases from your project to make that happen, e.g., clojure -X:dev:codox.

Breaking Changes in 0.9

In preparation for a 1.0 release, Codox 0.9 has a number of breaking changes:

  • The Leiningen plugin has been changed from codox to lein-codox
  • The Leiningen task has been changed from lein doc to lein codox
  • The default output path has been changed from doc to target/doc
  • The :sources option has been renamed to :source-paths
  • The :output-dir option has been renamed to :output-path
  • The :defaults option has been renamed to :metadata
  • The :include and :exclude options have been replaced with :namespaces
  • All the :src-* options have been replaced with :source-uri

See the "Source Files" section for information on the :namespaces option, and the "Source Links" section for information on the :source-uri option.

Examples

Some examples of API docs generated by Codox in real projects:

AOT Compilation

AOT-compiled namespaces will lose their metadata, which mean you'll lose documentation for namespaces. Avoid having global :aot directives in your project; instead, place them in a specialized profile, such as :uberjar.

Project Options

Codox can generate documentation from Clojure or ClojureScript. By default it looks for Clojure source files, but you can change this to ClojureScript by setting the :language key:

:codox {:language :clojurescript}

Source Files

By default Codox looks for source files in the :source-paths of your project, but you can change this just for Codox by placing the following in your project.clj file:

:codox {:source-paths ["path/to/source"]}

The :namespaces option can be used to restrict the documentation to a specific set of namespaces:

:codox {:namespaces [library.core library.io]}

Regular expressions can also be used for more general matching:

:codox {:namespaces [#"^library\."]}

For excluding only internal namespaces, it's sometimes useful to use negative lookahead:

:codox {:namespaces [#"^library\.(?!internal)"]}

To override the namespaces list and include all namespaces, use :all (the default):

:codox {:namespaces :all}

The :exclude-vars option can be used to exclude vars that match a regular expression. Set to nil to disable. By default vars generated by record constructor functions are excluded (such as ->Foo and map->Foo):

:codox {:exclude-vars #"^(map)?->\p{Upper}"}

Codox constructs documentation from metadata on vars and namespaces. You can specify a set of default metadata using the :metadata map:

:codox {:metadata {:doc "FIXME: write docs"}}

Documentation Files

As well as source files, Codox also tries to include documentation files as well. By default it looks for these in the doc directory, but you can change this with:

:codox {:doc-paths ["path/to/docs"]}

Documentation files will appear in the output sorted by their filename. If you want a particular order, one solution is to prefix your files with 01, 02, etc. Alternatively, you can also define the documentation files explicitly:

:codox {:doc-files ["doc/intro.md", "doc/tutorial.md"]}

If :doc-files is specified, then :doc-paths is ignored. Currently only markdown files (.md or .markdown) are supported. Any links between markdown files will be converted to their HTML equivalents automatically.

Output Files

To write output to a directory other than the default, use the :output-path key:

:codox {:output-path "codox"}

To use a different output writer, specify the fully qualified symbol of the writer function in the :writer key:

:codox {:writer codox.writer.html/write-docs}

By default the writer will include the project name, version and description in the output. You can override these by specifying a :project map in your Codox configuration:

:codox {:project {:name "Example", :version "1.0", :description "N/A"}}

Note: when using deps.edn, these entries should be added to the top level of the Codox configuration map (i.e. not under :project).

Source Links

If you have the source available at a URI and would like to have links to the function's source file in the documentation, you can set the :source-uri key:

:codox {:source-uri "https://github.com/foo/bar/blob/{version}/{filepath}#L{line}"}

The URI is a template that may contain the following keys:

  • {filepath} - the file path from the root of the repository
  • {basename} - the basename of the file
  • {classpath} - the relative path of the file within the source directory
  • {line} - the line number of the source file
  • {version} - the version of the project
  • {git-commit} - the Git commit id of the repository

You can also assign different URI templates to different paths of your source tree. This is particularly useful for created source links from generated source code, such as is the case with cljx.

For example, perhaps your Clojure source files are generated in target/classes. To link back to the original .cljx file, you could do:

:codox
{:source-uri
 {#"target/classes" "https://github.com/foo/bar/blob/master/src/{classpath}x#L{line}"
  #".*"             "https://github.com/foo/bar/blob/master/{filepath}#L{line}"}}

HTML Transformations

The HTML writer can be customized using Enlive-style transformations. You can use these to modify the HTML documents produced in arbitrary ways, but the most common use is to add in new stylesheets or scripts.

The transforms live in the :transforms key, in the :html map, and consist of a vector that matches selectors to transformations, in the same way that let matches symbols to values.

For example, the following code adds a new <script> element as the last child of the <head> element:

:html {:transforms [[:head] [:append [:script "console.log('foo');"]]]}

The selectors follow the Enlive selector syntax.

The transformations are a little different. There are five transforms, :append, :prepend, :after, :before and :substitute. These match to the corresponding Enlive transformations, but expect Hiccup-style arguments.

HTML Output Options

The HTML writer also has one other customization option.

By default the namespace list is nested, unless there is only one namespace in the library. To override this, set the :namespace-list option in the :html map to either :nested or :flat.

:html {:namespace-list :flat}

Themes

Themes are HTML transformations packaged with resources. Because they're data-driven and based on transformation of the generated documentation, multiple themes can be applied. The default theme is :default. Themes can be added by changing the :themes key:

:themes [:my-custom-theme]

To create a theme, you'll need to place the following resource in the classpath, either directly in your project, or via a dependency:

codox/theme/my-custom-theme/theme.edn

This edn file should contain a map of two keys: :transforms and :resources.

The :transforms key contains an ordered collection of HTML transformations. See the previous section for more information on the syntax.

The :resources key contains a list of sub-resources that will be copied to the target directory when the documentation is compiled. For example, if you define a sub-resource css/main.css, then Codox will copy the resource codox/theme/foo/css/main.css to the file css/main.css in the target directory.

Themes can also take parameters. You can put in a keyword as a placeholder, and then end users can specify the value that should replace the keyword. This is achieved by using a vector instead of a keyword to specify the theme:

:themes [[keyword {placeholder value}]]

For example:

:themes [[:my-custom-theme {:some-value "foobar"}]]

Codox will look for the keyword :some-value in the theme file, and replace it with the string "foobar".

If you want to take a look at a complete theme, try the default theme for Codox.

Metadata Options

To force Codox to skip a public var, add :no-doc true to the var's metadata. For example:

;; Documented
(defn square
  "Squares the supplied number."
  [x]
  (* x x))

;; Not documented
(defn ^:no-doc hidden-square
  "Squares the supplied number."
  [x]
  (* x x))

You can also skip namespaces by adding :no-doc true to the namespace's metadata. This currently only works for Clojure code, not ClojureScript. For example:

(ns ^:no-doc hidden-ns)

To denote the library version the var was added in, use the :added metadata key:

(defn square
  "Squares the supplied number."
  {:added "1.0"}
  [x]
  (* x x))

Similar, deprecated vars can be denoted with the :deprecated metadata key:

(defn square
  "Squares the supplied number."
  {:deprecated "2.0"}
  [x]
  (* x x))

Docstring Formats

By default, docstrings are rendered by Codox as fixed-width plain text, as they would be on a terminal. However, you can override this behavior by specifying an explicit format for your docstrings.

Currently there are only two formats for docstrings: plaintext and markdown. The markdown format includes extensions for code blocks, tables, and, like the plaintext format, URLs are automatically encoded as links.

You can specify docstring formats via a var's metadata, using the :doc/format option:

(defn foo
  "A **markdown** formatted docstring."
  {:doc/format :markdown}
  [x])

Or you can specify the docstring format globally by adding it to the :metadata map in your project.clj file:

:codox {:metadata {:doc/format :markdown}}

Markdown docstrings also support wikilink-style relative links, for referencing other vars. Vars in the current namespace will be matched first, and then Codox will try and find a best match out of all the vars its documenting.

(defn bar
  "See [[foo]] and [[user/square]] for other examples."
  {:doc/format :markdown}
  [x])

Live Documentation

You can make the code in your documentation live and interactive by using the Klipse theme written by Yehonathan Sharvit. This third-party theme integrates the generated docs with the Klipse code evaluator.

License

Copyright Β© 2018 James Reeves

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

More Repositories

1

compojure

A concise routing library for Ring/Clojure
Clojure
4,029
star
2

hiccup

Fast library for rendering HTML in Clojure
Clojure
2,571
star
3

integrant

Micro-framework for data-driven architecture
Clojure
1,232
star
4

cljfmt

A tool for formatting Clojure code
Clojure
1,112
star
5

environ

Library for managing environment variables in Clojure
Clojure
923
star
6

medley

A lightweight library of useful Clojure functions
Clojure
867
star
7

ragtime

Database-independent migration library
Clojure
608
star
8

lein-ring

Ring plugin for Leiningen
Clojure
501
star
9

hashp

A better "prn" for debugging
Clojure
442
star
10

eftest

Fast and pretty Clojure test runner
Clojure
424
star
11

reagi

An FRP library for Clojure and ClojureScript
Clojure
232
star
12

clout

HTTP route-matching library for Clojure
Clojure
230
star
13

ataraxy

A data-driven Ring routing and destructuring library
Clojure
209
star
14

crypto-password

Library for securely hashing passwords
Clojure
204
star
15

clj-aws-s3

S3 client library for Clojure
Clojure
198
star
16

clojure-toolbox.com

Source to clojure-toolbox.com
CSS
179
star
17

reloaded.repl

REPL functions to support the reloaded workflow
Clojure
178
star
18

clucy

Clojure interface to Lucene
Clojure
172
star
19

haslett

A lightweight WebSocket library for ClojureScript
Clojure
172
star
20

integrant-repl

Reloaded workflow functions for Integrant
Clojure
158
star
21

lein-beanstalk

Leiningen plugin for Amazon's Elastic Beanstalk service
Clojure
149
star
22

ring-oauth2

OAuth 2.0 client middleware for Ring
Clojure
144
star
23

brutha

Simple ClojureScript interface to React
Clojure
139
star
24

progrock

A functional Clojure progress bar for the command line
Clojure
134
star
25

lein-auto

A Leiningen plugin that executes tasks when files are modifed
Clojure
132
star
26

ns-tracker

Library to keep track of changes to Clojure source files
Clojure
114
star
27

meta-merge

A standalone implementation of Leiningen's meta-merge function
Clojure
105
star
28

ring-mock

Library to create mock ring requests for unit tests
Clojure
86
star
29

ring-anti-forgery

Ring middleware to prevent CSRF attacks
Clojure
76
star
30

crypto-random

Clojure library for generating cryptographically secure random bytes and strings
Clojure
72
star
31

crouton

HTML parsing library for Clojure
Clojure
68
star
32

comb

Clojure templating library
Clojure
67
star
33

ittyon

Library to manage distributed state for games
Clojure
58
star
34

compojure-example

An example Compojure project
Clojure
57
star
35

hiccup-bootstrap

Twitter's bootstrap in Hiccup
Clojure
57
star
36

lein-generate

Leiningen plugin for generating source file templates
Clojure
54
star
37

euclidean

Fast, immutable math for 3D geometries in Clojure
Clojure
52
star
38

impi

ClojureScript library for using Pixi.js through immutable data
Clojure
51
star
39

ring-server

Clojure
51
star
40

valip

Validations library for Clojure 1.2
Clojure
51
star
41

rotary

DynamoDB API for Clojure
Clojure
47
star
42

flupot

ClojureScript functions for creating React elements
Clojure
45
star
43

re-rand

Clojure library to generate random strings from regular expressions
Clojure
43
star
44

ring-webjars

Ring middleware to serve assets from WebJars
Clojure
36
star
45

ring-refresh

A Clojure middleware library for Ring that automatically triggers a browser refresh
Clojure
33
star
46

abrade

Clojure library for web scraping
Clojure
32
star
47

ring-jetty-component

A component for the standard Ring Jetty adapter
Clojure
32
star
48

tcp-server

Clojure TCP server library
Clojure
32
star
49

intentions

Multimethods that combine rather than override inherited behavior
Clojure
31
star
50

compojure-template

Compojure project template for Leiningen
Clojure
28
star
51

suspendable

A Clojure library to add suspend and resume methods to Component
Clojure
27
star
52

ring-serve

Ring development web server
Clojure
25
star
53

decorate

Clojure macros for decorating functions
Clojure
24
star
54

crypto-equality

A small Clojure library for securely comparing strings or byte arrays
Clojure
24
star
55

resauce

Clojure library for handling JVM resources
Clojure
24
star
56

fact

Unit testing library for Clojure (no longer in active dev)
Clojure
23
star
57

dotfiles

My configuration files
Emacs Lisp
21
star
58

inquest

A library for non-invasive monitoring in Clojure
Clojure
20
star
59

evaljs

Evaluate Javascript code and libraries in Clojure
Clojure
20
star
60

fish-git

Git completions and functions for the Fish Shell
18
star
61

snowball-stemmer

Snowball Stemmer for Clojure
Java
17
star
62

hop

An experimental declarative build tool for Clojure
Clojure
16
star
63

build

Clojure
15
star
64

coercer

Library to convert Clojure data into different types
Clojure
14
star
65

whorl

Generate unique fingerprints for Clojure data structures
Clojure
14
star
66

clojure-over-ajax

Ajax Clojure REPL based on why's Try Ruby
JavaScript
13
star
67

flupot-pixi

A ClojureScript wrapper around react-pixi
Clojure
13
star
68

websocket-example

Small example Ring/Aleph project for demonstrating websockets
Clojure
12
star
69

ring-json-response

Ring responses in JSON
Clojure
11
star
70

crumpets

Clojure library for dealing with color
Clojure
10
star
71

duct-hikaricp-component

Clojure component for managing a HikariCP connection pool
Clojure
10
star
72

clojure-dbm

Clojure interface to key-value databases
Clojure
9
star
73

hanami

A Clojure utility library for Heroku web applications
Clojure
9
star
74

strowger

A ClojureScript library for managing DOM events
Clojure
9
star
75

crypto-keystore

Clojure library for dealing with Java keystores
Clojure
8
star
76

substream

Stream subclassing in Clojure
Clojure
7
star
77

clj-daemon

Clojure daemon to avoid JVM startup time
Clojure
7
star
78

ring-reload-modified

Ring middleware that automatically reloads modifed source files
Clojure
7
star
79

duct-ragtime-component

Clojure component for managing migrations with Ragtime
Clojure
5
star
80

ring-honeybadger

Ring middleware for sending errors to HoneyBadger
Clojure
4
star
81

imprimatur

Data visualization library for ClojureScript and React
Clojure
4
star
82

hassium

Another Clojure MongoDB library
Clojure
4
star
83

contributing

Contributor's Guide
4
star
84

lein-template

Clojure
4
star
85

delegance

A Clojure library for remote evaluation
Clojure
3
star
86

po

A command-line tool for organizing project-specific scripts
Go
3
star
87

lein-version-script

A Leiningen plugin to set the project version from a shell script
Clojure
3
star
88

capra

An extensible package manager for Clojure
Clojure
3
star
89

eclair

Clojure
3
star
90

wrepl

Web-based Clojure REPL
Clojure
2
star
91

pocketses

Personal Wiki template that uses Gollum
CSS
2
star
92

clj-less

LESS interpreter for Clojure (http://lesscss.org)
Clojure
2
star
93

dewdrop

Web UI framework
2
star
94

ubitcoin

Bitcoin GUI for Ubuntu
Python
2
star
95

clojure-sandbox

Miscellaneous Clojure libraries that needed a home
Clojure
2
star
96

capra-server

RESTful package server
Clojure
1
star
97

delegance-aws

Library to integrate Delegance with Amazon Web Services
Clojure
1
star
98

weavejester.github.com

JavaScript
1
star
99

dojo-poetry

Code for Clojure Dojo 2012-08-28
Clojure
1
star
100

databstract

1
star