aboutsummaryrefslogtreecommitdiff
path: root/doc-tool/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala
blob: 37f97040b65f2b362caf60b8a902033082476123 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package dotty.tools.dottydoc.api.scala

import dotty.tools.dottydoc.DocDriver
import dotty.tools.dottydoc.model.Package
import dotty.tools.dottydoc.util.OutputWriter

import scala.collection.Map
import java.net.URL

/** The Dottydoc API is fairly simple. The tool creates an index by calling:
  * `createIndex` with the same argument list as you would the compiler - e.g:
  *
  * ```scala
  * val array: Array[String] = Array(
  *   "-language:Scala2"
  * )
  *
  * val index: Map[String, Package] = createIndex(array)
  * ```
  *
  * Once the index has been generated, the tool can also build a documentation
  * API given a Mustache template and a flat resources structure (i.e. absolute
  * paths to each resource, which will be put in the same directory).
  *
  * ```scala
  * buildDocs("path/to/output/dir", templateURL, resources, index)
  * ```
  *
  * The tool can also generate JSON from the created index using `indexToJson`
  * or directly using `createJsonIndex`
  */
trait Dottydoc extends DocDriver {
  /** Creates index from compiler arguments */
  def createIndex(args: Array[String]): Map[String, Package] =
    compiledDocs(args)

  /** Creates JSON from compiler arguments */
  def createJsonIndex(args: Array[String]): String =
    indexToJson(compiledDocs(args))

  /** Creates a documentation from the given parameters */
  def buildDocs(outDir: String, template: URL, resources: List[URL], index: Map[String, Package]) =
    new OutputWriter().write(index, outDir, template, resources)

  /** Writes JSON to an output directory as "index.json" */
  def writeJson(index: Map[String, Package], outputDir: String) =
    new OutputWriter().writeJson(index, outputDir)
}