diff options
author | Paul Phillips <paulp@improving.org> | 2013-03-06 07:39:19 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-03-09 11:59:07 -0800 |
commit | c6ca941ccc017a8869f4def717cfeb640f965077 (patch) | |
tree | e21038cc55d3a4231544d148913504a754eafdf8 /src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala | |
parent | 9094822181c398b945b7f30ac1e2b05da9796f53 (diff) | |
download | scala-c6ca941ccc017a8869f4def717cfeb640f965077.tar.gz scala-c6ca941ccc017a8869f4def717cfeb640f965077.tar.bz2 scala-c6ca941ccc017a8869f4def717cfeb640f965077.zip |
Moved scaladoc sources into separate directory.
This change is not externally visible. It moves the scaladoc
sources into src/scaladoc and adds an ant target for building
them. The compilation products are still packaged into
scala-compiler.jar as before, but with a small change to
build.xml a separate jar can be created instead.
Diffstat (limited to 'src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala')
-rw-r--r-- | src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala b/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala new file mode 100644 index 0000000000..d721a96ad7 --- /dev/null +++ b/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala @@ -0,0 +1,152 @@ +/* NSC -- new Scala compiler + * Copyright 2007-2013 LAMP/EPFL + * @author David Bernard, Manohar Jonnalagedda + */ + +package scala.tools.nsc +package doc +package html + +import model._ +import java.io.{ File => JFile } +import io.{ Streamable, Directory } +import scala.collection._ +import page.diagram._ + +import html.page.diagram.DiagramGenerator + +/** A class that can generate Scaladoc sites to some fixed root folder. + * @author David Bernard + * @author Gilles Dubochet */ +class HtmlFactory(val universe: doc.Universe, index: doc.Index) { + + /** The character encoding to be used for generated Scaladoc sites. + * This value is currently always UTF-8. */ + def encoding: String = "UTF-8" + + def siteRoot: JFile = new JFile(universe.settings.outdir.value) + + def libResources = List( + "index.js", + "jquery-ui.js", + "jquery.js", + "jquery.layout.js", + "scheduler.js", + "diagrams.js", + "template.js", + "tools.tooltip.js", + "modernizr.custom.js", + + "index.css", + "ref-index.css", + "template.css", + "diagrams.css", + + "class.png", + "class_big.png", + "class_diagram.png", + "object.png", + "object_big.png", + "object_diagram.png", + "package.png", + "package_big.png", + "trait.png", + "trait_big.png", + "trait_diagram.png", + "type.png", + "type_big.png", + "type_diagram.png", + + "class_to_object_big.png", + "object_to_class_big.png", + "trait_to_object_big.png", + "object_to_trait_big.png", + "type_to_object_big.png", + "object_to_type_big.png", + + "arrow-down.png", + "arrow-right.png", + "filter_box_left.png", + "filter_box_left2.gif", + "filter_box_right.png", + "filterbg.gif", + "filterboxbarbg.gif", + "filterboxbg.gif", + + "constructorsbg.gif", + "defbg-blue.gif", + "defbg-green.gif", + "filterboxbarbg.png", + "fullcommenttopbg.gif", + "ownderbg2.gif", + "ownerbg.gif", + "ownerbg2.gif", + "packagesbg.gif", + "signaturebg.gif", + "signaturebg2.gif", + "typebg.gif", + "conversionbg.gif", + "valuemembersbg.gif", + + "navigation-li-a.png", + "navigation-li.png", + "remove.png", + "selected-right.png", + "selected.png", + "selected2-right.png", + "selected2.png", + "selected-right-implicits.png", + "selected-implicits.png", + "unselected.png" + ) + + /** Generates the Scaladoc site for a model into the site root. + * A scaladoc site is a set of HTML and related files + * that document a model extracted from a compiler run. + */ + def generate() { + + def copyResource(subPath: String) { + val bytes = new Streamable.Bytes { + val p = "/scala/tools/nsc/doc/html/resource/" + subPath + val inputStream = getClass.getResourceAsStream(p) + assert(inputStream != null, p) + }.toByteArray() + val dest = Directory(siteRoot) / subPath + dest.parent.createDirectory() + val out = dest.toFile.bufferedOutput() + try out.write(bytes, 0, bytes.length) + finally out.close() + } + + DiagramGenerator.initialize(universe.settings) + + libResources foreach (s => copyResource("lib/" + s)) + + new page.Index(universe, index) writeFor this + new page.IndexScript(universe, index) writeFor this + + writeTemplates(_ writeFor this) + + for (letter <- index.firstLetterIndex) { + new html.page.ReferenceIndex(letter._1, index, universe) writeFor this + } + + DiagramGenerator.cleanup() + } + + def writeTemplates(writeForThis: HtmlPage => Unit) { + val written = mutable.HashSet.empty[DocTemplateEntity] + val diagramGenerator: DiagramGenerator = new DotDiagramGenerator(universe.settings) + + def writeTemplate(tpl: DocTemplateEntity) { + if (!(written contains tpl)) { + writeForThis(new page.Template(universe, diagramGenerator, tpl)) + written += tpl + tpl.templates collect { case d: DocTemplateEntity => d } map writeTemplate + } + } + + writeTemplate(universe.rootPackage) + } +} |