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/page/IndexScript.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/page/IndexScript.scala')
-rw-r--r-- | src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala b/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala new file mode 100644 index 0000000000..e3c94505ab --- /dev/null +++ b/src/scaladoc/scala/tools/nsc/doc/html/page/IndexScript.scala @@ -0,0 +1,69 @@ +/* NSC -- new Scala compiler + * Copyright 2007-2013 LAMP/EPFL + * @author David Bernard, Manohar Jonnalagedda + */ + +package scala.tools.nsc.doc.html.page + +import scala.tools.nsc.doc +import scala.tools.nsc.doc.model.{Package, DocTemplateEntity} +import scala.tools.nsc.doc.html.{Page, HtmlFactory} +import scala.util.parsing.json.{JSONObject, JSONArray} + +class IndexScript(universe: doc.Universe, index: doc.Index) extends Page { + def path = List("index.js") + + override def writeFor(site: HtmlFactory) { + writeFile(site) { + _.write("Index.PACKAGES = " + packages.toString() + ";") + } + } + + val packages = { + val pairs = allPackagesWithTemplates.toIterable.map(_ match { + case (pack, templates) => { + val merged = mergeByQualifiedName(templates) + + val ary = merged.keys.toList.sortBy(_.toLowerCase).map(key => { + val pairs = merged(key).map( + t => kindToString(t) -> relativeLinkTo(t) + ) :+ ("name" -> key) + + JSONObject(scala.collection.immutable.Map(pairs : _*)) + }) + + pack.qualifiedName -> JSONArray(ary) + } + }).toSeq + + JSONObject(scala.collection.immutable.Map(pairs : _*)) + } + + def mergeByQualifiedName(source: List[DocTemplateEntity]) = { + var result = Map[String, List[DocTemplateEntity]]() + + for (t <- source) { + val k = t.qualifiedName + result += k -> (result.getOrElse(k, List()) :+ t) + } + + result + } + + def allPackages = { + def f(parent: Package): List[Package] = { + parent.packages.flatMap( + p => f(p) :+ p + ) + } + f(universe.rootPackage).sortBy(_.toString) + } + + def allPackagesWithTemplates = { + Map(allPackages.map((key) => { + key -> key.templates.collect { + case t: DocTemplateEntity if !t.isPackage && !universe.settings.hardcoded.isExcluded(t.qualifiedName) => t + } + }) : _*) + } +} |