From eeeada2083dead6ef15c2c45e4158fa677b8ec02 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Fri, 13 Jan 2017 13:38:44 +0100 Subject: Fix dotty docs gen, scroll --- doc-tool/resources/css/dottydoc.css | 1 + .../dotty/tools/dottydoc/api/java/Dottydoc.java | 16 --- .../dotty/tools/dottydoc/api/scala/Dottydoc.scala | 9 -- .../dotty/tools/dottydoc/util/OutputWriter.scala | 125 --------------------- doc-tool/test/GenDocs.scala | 33 ++---- docs/docs/contributing/getting-started.md | 8 +- sbt-bridge/src/xsbt/ScaladocInterface.scala | 7 +- 7 files changed, 17 insertions(+), 182 deletions(-) delete mode 100644 doc-tool/src/dotty/tools/dottydoc/util/OutputWriter.scala diff --git a/doc-tool/resources/css/dottydoc.css b/doc-tool/resources/css/dottydoc.css index 71f3d88c7..ee66c810c 100644 --- a/doc-tool/resources/css/dottydoc.css +++ b/doc-tool/resources/css/dottydoc.css @@ -22,6 +22,7 @@ div.index-wrapper { top: 0; left: 0; height: 100%; + overflow-y: auto; } div#content-body { diff --git a/doc-tool/src/dotty/tools/dottydoc/api/java/Dottydoc.java b/doc-tool/src/dotty/tools/dottydoc/api/java/Dottydoc.java index d10e145a8..a44413c75 100644 --- a/doc-tool/src/dotty/tools/dottydoc/api/java/Dottydoc.java +++ b/doc-tool/src/dotty/tools/dottydoc/api/java/Dottydoc.java @@ -2,7 +2,6 @@ package dotty.tools.dottydoc.api.java; 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; import java.net.URL; @@ -46,19 +45,4 @@ public class Dottydoc { public String toJson(Map index) { return driver.indexToJsonJava(index); } - - /** Creates a documentation from the given parameters */ - public void buildDocs( - String outputDir, - URL template, - List resources, - Map index - ) { - new OutputWriter().writeJava(index, outputDir, template, resources); - } - - /** Writes JSON to an output directory as "index.json" */ - public void writeJson(Map index, String outputDir) { - new OutputWriter().writeJsonJava(index, outputDir); - } } diff --git a/doc-tool/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala b/doc-tool/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala index 37f97040b..1d0891bc2 100644 --- a/doc-tool/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala +++ b/doc-tool/src/dotty/tools/dottydoc/api/scala/Dottydoc.scala @@ -2,7 +2,6 @@ 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 @@ -37,12 +36,4 @@ trait Dottydoc extends DocDriver { /** 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) } diff --git a/doc-tool/src/dotty/tools/dottydoc/util/OutputWriter.scala b/doc-tool/src/dotty/tools/dottydoc/util/OutputWriter.scala deleted file mode 100644 index 2084e0a97..000000000 --- a/doc-tool/src/dotty/tools/dottydoc/util/OutputWriter.scala +++ /dev/null @@ -1,125 +0,0 @@ -package dotty.tools.dottydoc -package util - -import dotty.tools.dotc.config.Printers.dottydoc - -import _root_.java.io.{ - File => JFile, - PrintWriter => JPrintWriter, - FileReader => JFileReader, - BufferedInputStream, - InputStream, - InputStreamReader, - FileOutputStream, - BufferedOutputStream, - FileNotFoundException -} -import _root_.java.net.URL -import _root_.java.util.{ Map => JMap, List => JList } -import model.{ Entity, Package } -import model.json._ -import com.github.mustachejava.DefaultMustacheFactory -import scala.collection.JavaConverters._ - -class OutputWriter { - - def writeJava(packs: JMap[String, Package], outPath: String, template: URL, resources: JList[URL]): Unit = { - write(packs.asScala, outPath, template, resources.asScala) - } - - def write(packs: collection.Map[String, Package], outPath: String, template: URL, resources: Traversable[URL]): Unit = { - // Write all packages to `outPath` - for (pack <- packs.values) { - println(s"""Writing '${pack.path.mkString(".")}'""") - writeFile( - expandTemplate(template, pack, outPath), - 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( - expandTemplate(template, child, outPath), - outPath + child.path.dropRight(1).mkString("/", "/", "/"), - child.path.last + ".html") - } - } - - // Write full index to outPath - val js = "Index = {}; Index.packages = " + packs.json + ";" - println("Writing index.js...") - writeFile(js, outPath + "/docassets/", "index.js") - - // Write resources to outPath - println("Copying CSS/JS resources to destination...") - assert(resources.nonEmpty) - - // TODO: splitting the URL by '/' and taking the last means that we don't - // allow folders among the resources - resources.foreach(url => copy(url.openStream, outPath, url.getFile.split("/").last)) - - println("Done writing static material, building js-app") - } - - def writeJsonJava(index: JMap[String, Package], outputDir: String): Unit = - writeJson(index.asScala, outputDir) - - def writeJson(index: collection.Map[String, Package], outputDir: String): Unit = - writeFile(index.json, outputDir + "/", "index.json") - - def expandTemplate(template: URL, entity: Entity, outPath: String): String = try { - import model.json._ - import model.java._ - - val inputStream = template.openStream - val writer = new _root_.java.io.StringWriter() - val mf = new DefaultMustacheFactory() - - def toRoot = "../" * (entity.path.length - { if (entity.isInstanceOf[Package]) 0 else 1 }) - - val entityWithExtras = entity.asJava(Map( - "assets" -> s"${toRoot}docassets", - "index" -> s"${toRoot}docassets/index.js", - "currentEntity" -> entity.json - )) - - mf.compile(new InputStreamReader(inputStream), "template") - .execute(writer, entityWithExtras) - - inputStream.close() - writer.flush() - writer.toString - } catch { - case fnf: FileNotFoundException => - dottydoc.println(s"""Couldn't find the template: "${template.getFile}"...exiting""") - System.exit(1); "" - } - - 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: JFile)(op: JPrintWriter => Unit) = { - val bos = new BufferedOutputStream(new FileOutputStream(f)) - try { - Stream.continually(bos.write(bytes)) - } finally bos.close() - } - - new JFile(path).mkdirs() - printToFile(new JFile(path + file))(printer => bytes.foreach(printer.print)) - } - - def copy(src: InputStream, path: String, name: String): Unit = { - val reader = new BufferedInputStream(src) - try { - val bytes = Stream.continually(reader.read).takeWhile(-1 != _).map(_.toByte) - writeFile(bytes.toArray, path + "/docassets/", name) - src.close() - } finally reader.close() - } -} diff --git a/doc-tool/test/GenDocs.scala b/doc-tool/test/GenDocs.scala index 358e52fdf..c60e8f1e0 100644 --- a/doc-tool/test/GenDocs.scala +++ b/doc-tool/test/GenDocs.scala @@ -12,24 +12,15 @@ object Files { trait LocalResources extends api.scala.Dottydoc { import Files._ - val template = new JFile( - sys.env.get("DOC_TEMPLATE").getOrElse("../../dottydoc-client/resources/template.html") - ) - val resources = new JFile( - sys.env.get("DOC_RESOURCES").getOrElse("../../dottydoc-client/resources/") - ).listFiles - def getFiles(file: JFile): Array[JFile] = if (file.isDirectory) file.listFiles.flatMap(getFiles) else if (file.getAbsolutePath.endsWith(".scala")) Array(file) else Array() - assert(template.exists, "please specify a template.html file using DOC_TEMPLATE env var") - assert(resources.forall(_.exists), "please specify a resource dir using DOC_RESOURCES env var") - - def index(files: Array[String]) = createIndex( - "-language:Scala2" +: "-classpath" +: "../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar:../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar" +: files - ) + def withClasspath(files: Array[String]) = + "-language:Scala2" +: + "-classpath" +: "../library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar:../interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar" +: + files } object GenCollections extends LocalResources { @@ -37,12 +28,8 @@ object GenCollections extends LocalResources { val collections = TestWhitelistedCollections.files - override def main(args: Array[String]): Unit = buildDocs( - "../local/docs", - template.getUrl, - resources.map(_.getUrl).toList, - index(collections.toArray) - ) + override def main(args: Array[String]): Unit = + super.main(Array("-siteroot", "../docs") ++ withClasspath(collections.toArray)) } object GenDottyDocs extends LocalResources { @@ -50,10 +37,6 @@ object GenDottyDocs extends LocalResources { val dottyFiles = new JFile("../compiler/src/dotty").listFiles.flatMap(getFiles).map(_.getAbsolutePath) - override def main(args: Array[String]): Unit = buildDocs( - "../local/docs", - template.getUrl, - resources.map(_.getUrl).toList, - index(dottyFiles) - ) + override def main(args: Array[String]): Unit = + super.main(Array("-siteroot", "../docs") ++ withClasspath(dottyFiles)) } diff --git a/docs/docs/contributing/getting-started.md b/docs/docs/contributing/getting-started.md index e38c3a8fc..26862e790 100644 --- a/docs/docs/contributing/getting-started.md +++ b/docs/docs/contributing/getting-started.md @@ -23,7 +23,7 @@ Compiling and Running --------------------- Start by cloning the repository: -```none +```bash $ git clone https://github.com/lampepfl/dotty.git $ cd dotty ``` @@ -31,7 +31,7 @@ $ cd dotty Dotty provides a standard sbt build: compiling, running and starting a repl can all be done from within sbt using -```none +```bash $ sbt > dotc tests/pos/HelloWorld.scala > dotr HelloWorld @@ -50,7 +50,7 @@ there is also a bash script that can be used in the same way: Starting a REPL --------------- -```none +```bash $ sbt > repl Welcome to Scala.next (pre-alpha) (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101). @@ -61,6 +61,6 @@ scala> or via bash: -```none +```bash $ ./bin/dotr ``` diff --git a/sbt-bridge/src/xsbt/ScaladocInterface.scala b/sbt-bridge/src/xsbt/ScaladocInterface.scala index 3ad9c7941..15a9a84f4 100644 --- a/sbt-bridge/src/xsbt/ScaladocInterface.scala +++ b/sbt-bridge/src/xsbt/ScaladocInterface.scala @@ -18,9 +18,10 @@ class DottydocRunner(args: Array[String], log: Logger, delegate: xsbti.Reporter) val resources = getResources(args) val template = getTemplate(resources) - template.fold(writeJson(index, outputFolder)) { tpl => - buildDocs(outputFolder, tpl, resources, index) - } + // FIXME: temporarily disabled until new implementation in place + //template.fold(writeJson(index, outputFolder)) { tpl => + // buildDocs(outputFolder, tpl, resources, index) + //} } getOrElse { delegate.log( NoPosition, -- cgit v1.2.3