diff options
author | Kato Kazuyoshi <kato.kazuyoshi@gmail.com> | 2011-06-20 14:20:45 +0000 |
---|---|---|
committer | Kato Kazuyoshi <kato.kazuyoshi@gmail.com> | 2011-06-20 14:20:45 +0000 |
commit | 2627ab313f0d9f33e1b97e8aeda4447cf34bd27d (patch) | |
tree | b119264c47c6c990395ba3610209905aaf270b51 /src/compiler/scala/tools/nsc/doc/html/Page.scala | |
parent | d2fd3d61d1cceb79c731a4be46977384c7cb7c9b (diff) | |
download | scala-2627ab313f0d9f33e1b97e8aeda4447cf34bd27d.tar.gz scala-2627ab313f0d9f33e1b97e8aeda4447cf34bd27d.tar.bz2 scala-2627ab313f0d9f33e1b97e8aeda4447cf34bd27d.zip |
Separete index.js to parallelize downloads.
Diffstat (limited to 'src/compiler/scala/tools/nsc/doc/html/Page.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/html/Page.scala | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/html/Page.scala b/src/compiler/scala/tools/nsc/doc/html/Page.scala new file mode 100644 index 0000000000..f72b0a49eb --- /dev/null +++ b/src/compiler/scala/tools/nsc/doc/html/Page.scala @@ -0,0 +1,93 @@ +package scala.tools.nsc.doc.html +import scala.tools.nsc.doc.model._ +import java.io.{FileOutputStream, File} +import scala.reflect.NameTransformer + +abstract class Page { + thisPage => + + /** The path of this page, relative to the API site. `path.tail` is a list of folder names leading to this page (from + * closest package to one-above-root package), `path.head` is the file name of this page. Note that `path` has a + * length of at least one. */ + def path: List[String] + + def absoluteLinkTo(path: List[String]) = path.reverse.mkString("/") + + def createFileOutputStream(site: HtmlFactory) = { + val file = new File(site.siteRoot, absoluteLinkTo(thisPage.path)) + val folder = file.getParentFile + if (! folder.exists) { + folder.mkdirs + } + new FileOutputStream(file.getPath) + } + + /** Writes this page as a file. The file's location is relative to the generator's site root, and the encoding is + * also defined by the generator. + * @param generator The generator that is writing this page. */ + def writeFor(site: HtmlFactory): Unit + + def docEntityKindToString(ety: DocTemplateEntity) = + if (ety.isTrait) "trait" + else if (ety.isCaseClass) "case class" + else if (ety.isClass) "class" + else if (ety.isObject) "object" + else if (ety.isPackage) "package" + else "class" // FIXME: an entity *should* fall into one of the above categories, but AnyRef is somehow not + + def templateToPath(tpl: TemplateEntity): List[String] = { + def doName(tpl: TemplateEntity): String = + NameTransformer.encode(tpl.name) + (if (tpl.isObject) "$" else "") + def downPacks(pack: Package): List[String] = + if (pack.isRootPackage) Nil else (doName(pack) :: downPacks(pack.inTemplate)) + def downInner(nme: String, tpl: TemplateEntity): (String, Package) = { + tpl.inTemplate match { + case inPkg: Package => (nme + ".html", inPkg) + case inTpl => downInner(doName(inTpl) + "$" + nme, inTpl) + } + } + val (file, pack) = + tpl match { + case p: Package => ("package.html", p) + case _ => downInner(doName(tpl), tpl) + } + file :: downPacks(pack) + } + + /** A relative link from this page to some destination class entity. + * @param destEntity The class or object entity that the link will point to. */ + def relativeLinkTo(destClass: TemplateEntity): String = + relativeLinkTo(templateToPath(destClass)) + + /** A relative link from this page to some destination page in the Scaladoc site. + * @param destPage The page that the link will point to. */ + def relativeLinkTo(destPage: HtmlPage): String = { + relativeLinkTo(destPage.path) + } + + /** A relative link from this page to some destination path. + * @param destPath The path that the link will point to. */ + def relativeLinkTo(destPath: List[String]): String = { + def relativize(from: List[String], to: List[String]): List[String] = (from, to) match { + case (f :: fs, t :: ts) if (f == t) => // both paths are identical to that point + relativize(fs, ts) + case (fss, tss) => + List.fill(fss.length - 1)("..") ::: tss + } + relativize(thisPage.path.reverse, destPath.reverse).mkString("/") + } + + def isExcluded(dtpl: DocTemplateEntity) = { + val qname = dtpl.qualifiedName + ( ( qname.startsWith("scala.Tuple") || qname.startsWith("scala.Product") || + qname.startsWith("scala.Function") || qname.startsWith("scala.runtime.AbstractFunction") + ) && !( + qname == "scala.Tuple1" || qname == "scala.Tuple2" || + qname == "scala.Product" || qname == "scala.Product1" || qname == "scala.Product2" || + qname == "scala.Function" || qname == "scala.Function1" || qname == "scala.Function2" || + qname == "scala.runtime.AbstractFunction0" || qname == "scala.runtime.AbstractFunction1" || + qname == "scala.runtime.AbstractFunction2" + ) + ) + } +} |