scala.tools.nsc.doc.html.page.Index.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala-compiler Show documentation
Show all versions of scala-compiler Show documentation
Compiler for the Scala Programming Language
/* NSC -- new Scala compiler
* Copyright 2007-2013 LAMP/EPFL
* @author David Bernard, Manohar Jonnalagedda
*/
package scala.tools.nsc
package doc
package html
package page
import model._
import scala.collection._
import scala.xml._
import scala.util.parsing.json.{JSONObject, JSONArray}
class Index(universe: doc.Universe, val index: doc.Index) extends HtmlPage {
def path = List("index.html")
def title = {
val s = universe.settings
( if (!s.doctitle.isDefault) s.doctitle.value else "" ) +
( if (!s.docversion.isDefault) (" " + s.docversion.value) else "" )
}
val headers =
val body =
{ browser }
def browser =
{
def packageElem(pack: model.Package): NodeSeq = {
{ if (!pack.isRootPackage)
{ pack.qualifiedName }
else NodeSeq.Empty
}
{
val tpls: Map[String, Seq[DocTemplateEntity]] =
(pack.templates collect {
case t: DocTemplateEntity if !t.isPackage && !universe.settings.hardcoded.isExcluded(t.qualifiedName) => t
}) groupBy (_.name)
val placeholderSeq: NodeSeq =
def createLink(entity: DocTemplateEntity, includePlaceholder: Boolean, includeText: Boolean) = {
val entityType = kindToString(entity)
val linkContent = (
{ if (includePlaceholder) placeholderSeq else NodeSeq.Empty }
++
{ if (includeText) { Text(packageQualifiedName(entity)) } else NodeSeq.Empty }
)
({ Text(entityType) }){ linkContent }
}
for (tn <- tpls.keySet.toSeq sortBy (_.toLowerCase)) yield {
val entities = tpls(tn)
val row = (entities find (e => e.isPackage || e.isObject), entities find (e => e.isTrait || e.isClass))
val itemContents = row match {
case (Some(obj), None) => createLink(obj, includePlaceholder = true, includeText = true)
case (maybeObj, Some(template)) =>
val firstLink = maybeObj match {
case Some(obj) => createLink(obj, includePlaceholder = false, includeText = false)
case None => placeholderSeq
}
firstLink ++ createLink(template, includePlaceholder = false, includeText = true)
case _ => // FIXME: this default case should not be necessary. For some reason AnyRef is not a package, object, trait, or class
val entry = entities.head
placeholderSeq ++ createLink(entry, includePlaceholder = false, includeText = true)
}
- { itemContents }
}
}
{
for (sp <- pack.packages sortBy (_.name.toLowerCase)) yield
- { packageElem(sp) }
}
}
packageElem(universe.rootPackage)
}
def packageQualifiedName(ety: DocTemplateEntity): String =
if (ety.inTemplate.isPackage) ety.name
else (packageQualifiedName(ety.inTemplate) + "." + ety.name)
}