aboutsummaryrefslogtreecommitdiff
path: root/dottydoc/jvm/src
diff options
context:
space:
mode:
Diffstat (limited to 'dottydoc/jvm/src')
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala3
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/html/EntityPage.scala4
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/util/IndexWriters.scala47
-rw-r--r--dottydoc/jvm/src/dotty/tools/dottydoc/util/OutputWriter.scala90
4 files changed, 93 insertions, 51 deletions
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala
index e569a706a..81dc21bbc 100644
--- a/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/core/Phases.scala
@@ -147,8 +147,7 @@ object Phases {
if (out.last == '/') out.dropRight(1)
else out
}
- assert(outputDir == "../js/out")
- if (!ctx.settings.YDocNoWrite.value) util.IndexWriters.writeJs(packages, outputDir)
+ if (!ctx.settings.YDocNoWrite.value) (new util.OutputWriter).write(packages, outputDir)
// (5) Clear caches
commentParser.clear()
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/html/EntityPage.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/html/EntityPage.scala
index cfac8333d..84630f214 100644
--- a/dottydoc/jvm/src/dotty/tools/dottydoc/html/EntityPage.scala
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/html/EntityPage.scala
@@ -12,7 +12,7 @@ case class EntityPage(entity: Entity, packages: Map[String, Package]) {
import util.internal.setters._
private def relPath(to: String, from: Entity) = {
- val len = from.path.length + (from match {
+ val len = (from.path.length - 1) + (from match {
case _: Package => 1
case _ => 0
})
@@ -30,7 +30,7 @@ case class EntityPage(entity: Entity, packages: Map[String, Package]) {
script(`type` := "text/javascript", src := relPath("static/material.min.js", entity)),
script(`type` := "text/javascript", src := relPath("static/highlight.pack.js", entity)),
script(`type` := "text/javascript", src := relPath("index.js", entity)),
- script(`type` := "text/javascript", src := relPath("target/scala-2.11/dottydoc-fastopt.js", entity)),
+ script(`type` := "text/javascript", src := relPath("static/dottydoc-fastopt.js", entity)),
link(rel := "stylesheet", href := relPath("static/material-icons.css", entity)),
link(rel := "stylesheet", href := relPath("static/material.min.css", entity)),
link(rel := "stylesheet", href := relPath("static/github.css", entity)),
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/util/IndexWriters.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/util/IndexWriters.scala
deleted file mode 100644
index 65ed70773..000000000
--- a/dottydoc/jvm/src/dotty/tools/dottydoc/util/IndexWriters.scala
+++ /dev/null
@@ -1,47 +0,0 @@
-package dotty.tools.dottydoc
-package util
-
-object IndexWriters {
- import html.EntityPage
- import model.Package
- import model.pickling._
- import prickle._
-
- def writeJs(packs: Map[String, Package], outPath: String): Unit = {
- for (pack <- packs.values) {
- println(s"""Writing '${pack.path.mkString(".")}'""")
- writeFile(
- EntityPage(pack, packs).render,
- outPath + pack.path.mkString("/", "/", "/"),
- "index.html")
-
- for {
- child <- pack.children
- if child.kind != "package"
- } {
- println(s"""Writing '${child.path.mkString(".")}'""")
- writeFile(
- EntityPage(child, packs).render,
- outPath + child.path.dropRight(1).mkString("/", "/", "/"),
- child.path.last + ".html")
- }
- }
-
- val pickled = Pickle.intoString(packs)
- val js = "UnparsedIndex = {}; UnparsedIndex.packages = " + pickled + ";"
- println("Writing index.js...")
- writeFile(js, outPath + "/../", "index.js")
- println("Done writing static material, building js-app")
-
- }
-
- def writeFile(str: String, path: String, file: String): Unit = {
- def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) {
- val p = new java.io.PrintWriter(f)
- try { op(p) } finally { p.close() }
- }
-
- new java.io.File(path).mkdirs()
- printToFile(new java.io.File(path + file))(_.println(str))
- }
-}
diff --git a/dottydoc/jvm/src/dotty/tools/dottydoc/util/OutputWriter.scala b/dottydoc/jvm/src/dotty/tools/dottydoc/util/OutputWriter.scala
new file mode 100644
index 000000000..f2a6c7e95
--- /dev/null
+++ b/dottydoc/jvm/src/dotty/tools/dottydoc/util/OutputWriter.scala
@@ -0,0 +1,90 @@
+package dotty.tools.dottydoc
+package util
+
+
+class OutputWriter {
+ import java.io.{File => JFile, BufferedInputStream, FileInputStream, FileOutputStream, BufferedOutputStream}
+ import html.EntityPage
+ import model.Package
+ import model.pickling._
+ import prickle._
+
+ def write(packs: Map[String, Package], outPath: String): Unit = {
+ // Write all packages to `outPath`
+ for (pack <- packs.values) {
+ println(s"""Writing '${pack.path.mkString(".")}'""")
+ writeFile(
+ EntityPage(pack, packs).render,
+ outPath + pack.path.mkString("/", "/", "/"),
+ "index.html")
+
+ // Write all package children to outPath
+ for {
+ child <- pack.children
+ if child.kind != "package"
+ } {
+ println(s"""Writing '${child.path.mkString(".")}'""")
+ writeFile(
+ EntityPage(child, packs).render,
+ outPath + child.path.dropRight(1).mkString("/", "/", "/"),
+ child.path.last + ".html")
+ }
+ }
+
+ // Write full index to outPath
+ val pickled = Pickle.intoString(packs)
+ val js = "UnparsedIndex = {}; UnparsedIndex.packages = " + pickled + ";"
+ println("Writing index.js...")
+ writeFile(js, outPath + "/", "index.js")
+
+ // Write resources to outPath
+ println("Copying CSS/JS resources to destination...")
+ assert(resources.nonEmpty)
+ resources.map(copy(_, outPath))
+
+ println("Done writing static material, building js-app")
+ }
+
+ def writeFile(str: String, path: String, file: String): Unit =
+ writeFile(str.map(_.toByte).toArray, path, file)
+
+ def writeFile(bytes: Array[Byte], path: String, file: String): Unit = {
+ def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) = {
+ val bos = new BufferedOutputStream(new FileOutputStream(f))
+ try {
+ Stream.continually(bos.write(bytes))
+ } finally bos.close()
+ }
+
+ new java.io.File(path).mkdirs()
+ printToFile(new java.io.File(path + file))(printer => bytes.foreach(printer.print))
+ }
+
+ def copy(src: JFile, path: String): Unit = {
+ val reader = new BufferedInputStream(new FileInputStream(src))
+ try {
+ val bytes = Stream.continually(reader.read).takeWhile(-1 != _).map(_.toByte)
+ writeFile(bytes.toArray, path + "/static/", src.getName)
+ } finally reader.close()
+ }
+
+ /** All static resources */
+ private val resources: Iterable[JFile] = List(
+ "/MaterialIcons-Regular.eot",
+ "/MaterialIcons-Regular.ijmap",
+ "/MaterialIcons-Regular.svg",
+ "/MaterialIcons-Regular.ttf",
+ "/MaterialIcons-Regular.woff",
+ "/MaterialIcons-Regular.woff2",
+ "/codepoints",
+ "/github.css",
+ "/highlight.pack.js",
+ "/index.css",
+ "/material-icons.css",
+ "/material.min.css",
+ "/material.min.js",
+ "/dottydoc-fastopt.js"
+ ).map { f =>
+ new JFile(this.getClass.getResource(f).toURI)
+ }
+}