aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-08-11 17:18:14 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-08-19 15:37:34 +0200
commitbd7751924d9c145accf04b69e71621347d2b77f6 (patch)
tree961e90b8f9250589fb200648b05e3e4aa21d208a
parenta25207472c8b64beeb264f118ed1bb4f9a37418c (diff)
downloaddotty-bd7751924d9c145accf04b69e71621347d2b77f6.tar.gz
dotty-bd7751924d9c145accf04b69e71621347d2b77f6.tar.bz2
dotty-bd7751924d9c145accf04b69e71621347d2b77f6.zip
Implement working docs requiring manually specifying resources and template for html docs
-rw-r--r--bridge/src/main/scala/xsbt/ScaladocInterface.scala33
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala30
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java4
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala4
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/core/OutputJsonPhase.scala13
-rw-r--r--dottydoc/src/dotty/tools/dottydoc/core/PrintPhase.scala30
-rw-r--r--dottydoc/test/BaseTest.scala3
-rw-r--r--dottydoc/test/WhitelistedStdLibMain.scala30
-rw-r--r--src/dotty/tools/dotc/config/ScalaSettings.scala14
9 files changed, 63 insertions, 98 deletions
diff --git a/bridge/src/main/scala/xsbt/ScaladocInterface.scala b/bridge/src/main/scala/xsbt/ScaladocInterface.scala
index 39458bd1d..42f4296fe 100644
--- a/bridge/src/main/scala/xsbt/ScaladocInterface.scala
+++ b/bridge/src/main/scala/xsbt/ScaladocInterface.scala
@@ -20,12 +20,39 @@ class DottydocRunner(args: Array[String], log: Logger, delegate: xsbti.Reporter)
template.fold(writeJson(index, outputFolder)) { tpl =>
buildDocs(outputFolder, tpl, resources, index)
}
+ } getOrElse {
+ delegate.log(
+ NoPosition,
+ "No output folder set for API documentation (\"-d\" parameter should be passed to the documentation tool)",
+ xsbti.Severity.Error
+ )
}
+ private[this] val NoPosition = new xsbti.Position {
+ val line = xsbti.Maybe.nothing[Integer]
+ val lineContent = ""
+ val offset = xsbti.Maybe.nothing[Integer]
+ val sourcePath = xsbti.Maybe.nothing[String]
+ val sourceFile = xsbti.Maybe.nothing[java.io.File]
+ val pointer = xsbti.Maybe.nothing[Integer]
+ val pointerSpace = xsbti.Maybe.nothing[String]
+ }
+
+ private def getStringSetting(name: String): Option[String] =
+ args find (_.startsWith(name)) map (_.drop(name.length))
+
private def getOutputFolder(args: Array[String]): Option[String] =
- args sliding(2) find { case Array(x, _) => x == "-d" } map (_.tail.head)
+ args sliding(2) find { case Array(x, _) => x == "-d" } map (_.tail.head.trim)
+
+ private def getTemplate(args: Array[String]): Option[String] =
+ getStringSetting("-template:")
- private def getTemplate(args: Array[String]): Option[String] = None
+ private def getResources(args: Array[String]): List[String] =
+ getStringSetting("-resources:").map { path =>
+ val dir = new java.io.File(path)
+ if (dir.exists && dir.isDirectory)
+ dir.listFiles.filter(_.isFile).map(_.getAbsolutePath).toList
+ else Nil
+ }.getOrElse(Nil)
- private def getResources(args: Array[String]): List[String] = Nil
}
diff --git a/dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala b/dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala
index bef9141f2..e19805d21 100644
--- a/dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala
+++ b/dottydoc/src/dotty/tools/dottydoc/DottyDoc.scala
@@ -26,7 +26,7 @@ import _root_.java.util.{ Map => JMap }
* 2. Create an AST that is serializable
* 3. Serialize to JS object
*/
-class DottyDocCompiler extends Compiler {
+class DocCompiler extends Compiler {
override def phases: List[List[Phase]] = List(
List(new DocFrontEnd),
List(new DocImplicitsPhase),
@@ -36,11 +36,6 @@ class DottyDocCompiler extends Compiler {
new LinkImplicitlyAddedTypes,
new SortMembers))
)
-
- override def newRun(implicit ctx: Context): Run = {
- reset()
- new DocRun(this)(rootContext)
- }
}
class DocFrontEnd extends FrontEnd {
@@ -48,26 +43,7 @@ class DocFrontEnd extends FrontEnd {
unit.isJava
}
-class DocRun(comp: Compiler)(implicit ctx: Context) extends Run(comp)(ctx) {
- def fromDirectory(f: String): List[String] = {
- val file = new PlainFile(f)
-
- if (!file.isDirectory && f.endsWith(".scala")) List(f)
- else if (!file.isDirectory) Nil
- else file.iterator.flatMap {
- case x if x.isDirectory => fromDirectory(x.canonicalPath)
- case x => List(x.canonicalPath)
- }.toList
- }
-
- /** If DocRecursive is set, then try to find all scala files! */
- override def compile(fileNames: List[String]): Unit = super.compile(
- if (ctx.settings.DocRecursive.value) fileNames flatMap fromDirectory
- else fileNames
- )
-}
-
-abstract class DottyDocDriver extends Driver {
+abstract class DocDriver extends Driver {
import scala.collection.JavaConverters._
override def setup(args: Array[String], rootCtx: Context): (List[String], Context) = {
@@ -81,7 +57,7 @@ abstract class DottyDocDriver extends Driver {
(fileNames, ctx)
}
- override def newCompiler(implicit ctx: Context): Compiler = new DottyDocCompiler
+ override def newCompiler(implicit ctx: Context): Compiler = new DocCompiler
def compiledDocs(args: Array[String]): collection.Map[String, Package] = {
diff --git a/dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java b/dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java
index c50688c77..b461c3096 100644
--- a/dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java
+++ b/dottydoc/src/dotty/tools/dottydoc/api/java/Dottydoc.java
@@ -1,13 +1,13 @@
package dotty.tools.dottydoc.api.java;
-import dotty.tools.dottydoc.DottyDocDriver;
+import dotty.tools.dottydoc.DocDriver;
import dotty.tools.dottydoc.model.Package;
import dotty.tools.dottydoc.util.OutputWriter;
import java.util.Map;
import java.util.List;
/** FIXME: document me! */
-public class Dottydoc extends DottyDocDriver {
+public class Dottydoc extends DocDriver {
public Map<String, Package> createIndex(String[] args) {
return compiledDocsJava(args);
}
diff --git a/dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala b/dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala
index 373fae39a..dce994f5d 100644
--- a/dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala
+++ b/dottydoc/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala
@@ -1,13 +1,13 @@
package dotty.tools.dottydoc.api.scala
-import dotty.tools.dottydoc.DottyDocDriver
+import dotty.tools.dottydoc.DocDriver
import dotty.tools.dottydoc.model.Package
import dotty.tools.dottydoc.util.OutputWriter
import scala.collection.Map
/** FIXME: document this class plz */
-trait Dottydoc extends DottyDocDriver {
+trait Dottydoc extends DocDriver {
def createIndex(args: Array[String]): Map[String, Package] =
compiledDocs(args)
diff --git a/dottydoc/src/dotty/tools/dottydoc/core/OutputJsonPhase.scala b/dottydoc/src/dotty/tools/dottydoc/core/OutputJsonPhase.scala
deleted file mode 100644
index 9f8dfdca6..000000000
--- a/dottydoc/src/dotty/tools/dottydoc/core/OutputJsonPhase.scala
+++ /dev/null
@@ -1,13 +0,0 @@
-package dotty.tools
-package dottydoc
-package core
-
-import dotc.CompilationUnit
-import dotc.core.Contexts.Context
-import dotc.core.Phases.Phase
-import model.{Package, Entity}
-
-abstract class JsonOutputPhase extends Phase {
- def phaseName = "jsonOutputPhase"
- println("wabalubadubdub")
-}
diff --git a/dottydoc/src/dotty/tools/dottydoc/core/PrintPhase.scala b/dottydoc/src/dotty/tools/dottydoc/core/PrintPhase.scala
deleted file mode 100644
index 080687877..000000000
--- a/dottydoc/src/dotty/tools/dottydoc/core/PrintPhase.scala
+++ /dev/null
@@ -1,30 +0,0 @@
-package dotty.tools
-package dottydoc
-package core
-
-import dotc.CompilationUnit
-import dotc.core.Contexts.Context
-import dotc.core.Phases.Phase
-import model.{Package, Entity}
-
-/** TODO: re-write to `DocMiniPhase` */
-//class PrintPhase extends Phase {
-// def phaseName = "docPrintPhase"
-//
-// var currentRun = 0
-// override def run(implicit ctx: Context): Unit = ()
-//
-// override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
-// val compUnits = super.runOn(units)
-// val packages = ctx.docbase.packages[Package].toMap
-//
-// val outputDir = {
-// val out = ctx.settings.DocOutput.value
-// if (out.last == '/') out.dropRight(1)
-// else out
-// }
-// if (!ctx.settings.YDocNoWrite.value) (new util.OutputWriter).write(packages, outputDir)
-//
-// compUnits
-// }
-//}
diff --git a/dottydoc/test/BaseTest.scala b/dottydoc/test/BaseTest.scala
index 0c6fad1c8..7f077d27b 100644
--- a/dottydoc/test/BaseTest.scala
+++ b/dottydoc/test/BaseTest.scala
@@ -17,12 +17,11 @@ trait DottyTest {
val ctx = base.initialCtx.fresh
ctx.setSetting(ctx.settings.language, List("Scala2"))
ctx.setSetting(ctx.settings.YkeepComments, true)
- ctx.setSetting(ctx.settings.YDocNoWrite, true)
base.initialize()(ctx)
ctx
}
- private def compilerWithChecker(assertion: DocASTPhase => Unit) = new DottyDocCompiler {
+ private def compilerWithChecker(assertion: DocASTPhase => Unit) = new DocCompiler {
private[this] val docPhase = new DocASTPhase
override def phases =
diff --git a/dottydoc/test/WhitelistedStdLibMain.scala b/dottydoc/test/WhitelistedStdLibMain.scala
index d1168bf15..95d4afbae 100644
--- a/dottydoc/test/WhitelistedStdLibMain.scala
+++ b/dottydoc/test/WhitelistedStdLibMain.scala
@@ -7,7 +7,7 @@ object WhitelistedStandardLib extends dottydoc.api.java.Dottydoc {
import scala.collection.JavaConverters._
val files: List[String] = {
- val whitelist = "../test/dotc/scala-collections.whitelist"
+ val whitelist = "./test/dotc/scala-collections.whitelist"
Source.fromFile(whitelist, "UTF8")
.getLines()
@@ -21,20 +21,20 @@ object WhitelistedStandardLib extends dottydoc.api.java.Dottydoc {
}
private val resources = List(
- "../../dottydoc-client/resources/MaterialIcons-Regular.eot",
- "../../dottydoc-client/resources/MaterialIcons-Regular.ijmap",
- "../../dottydoc-client/resources/MaterialIcons-Regular.svg",
- "../../dottydoc-client/resources/MaterialIcons-Regular.ttf",
- "../../dottydoc-client/resources/MaterialIcons-Regular.woff",
- "../../dottydoc-client/resources/MaterialIcons-Regular.woff2",
- "../../dottydoc-client/resources/codepoints",
- "../../dottydoc-client/resources/github.css",
- "../../dottydoc-client/resources/highlight.pack.js",
- "../../dottydoc-client/resources/index.css",
- "../../dottydoc-client/resources/material-icons.css",
- "../../dottydoc-client/resources/material.min.css",
- "../../dottydoc-client/resources/material.min.js",
- "../../dottydoc-client/target/scala-2.11/dottydoc-client-fastopt.js"
+ "../dottydoc-client/resources/MaterialIcons-Regular.eot",
+ "../dottydoc-client/resources/MaterialIcons-Regular.ijmap",
+ "../dottydoc-client/resources/MaterialIcons-Regular.svg",
+ "../dottydoc-client/resources/MaterialIcons-Regular.ttf",
+ "../dottydoc-client/resources/MaterialIcons-Regular.woff",
+ "../dottydoc-client/resources/MaterialIcons-Regular.woff2",
+ "../dottydoc-client/resources/codepoints",
+ "../dottydoc-client/resources/github.css",
+ "../dottydoc-client/resources/highlight.pack.js",
+ "../dottydoc-client/resources/index.css",
+ "../dottydoc-client/resources/material-icons.css",
+ "../dottydoc-client/resources/material.min.css",
+ "../dottydoc-client/resources/material.min.js",
+ "../dottydoc-client/target/scala-2.11/dottydoc-client-fastopt.js"
)
override def main(args: Array[String]) = {
diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala
index fa4059a96..5d5903584 100644
--- a/src/dotty/tools/dotc/config/ScalaSettings.scala
+++ b/src/dotty/tools/dotc/config/ScalaSettings.scala
@@ -197,8 +197,16 @@ class ScalaSettings extends Settings.SettingGroup {
val YpresentationReplay = StringSetting("-Ypresentation-replay", "file", "Replay presentation compiler events from file", "")
val YpresentationDelay = IntSetting("-Ypresentation-delay", "Wait number of ms after typing before starting typechecking", 0, 0 to 999)
- /** Dottydoc specific settings */
- val YDocNoWrite = BooleanSetting("-Ydoc-nowrite", "Doesn't write HTML files if set", false)
+ /** Doc specific settings */
+ val template = OptionSetting[String](
+ "-template",
+ "A mustache template for rendering each top-level entity in the API"
+ )
+
+ val resources = OptionSetting[String](
+ "-resources",
+ "A directory containing static resources needed for the API documentation"
+ )
val DocTitle = StringSetting (
"-Ydoc-title",
@@ -235,8 +243,6 @@ class ScalaSettings extends Settings.SettingGroup {
""
)
- val DocRecursive = BooleanSetting("-Ydoc-recursive", "Get all files from supplied directory")
-
//def DocUncompilableFiles(implicit ctx: Context) = DocUncompilable.value match {
// case "" => Nil
// case path => io.Directory(path).deepFiles.filter(_ hasExtension "scala").toList