diff options
author | Marcin Kubala <marcin@mkubala.pl> | 2014-03-10 23:55:16 +0100 |
---|---|---|
committer | Marcin Kubala <marcin@mkubala.pl> | 2014-03-14 22:58:07 +0100 |
commit | 466340cf9e3fbc6fbd3c65e13b43d7fe57471d86 (patch) | |
tree | deb1d87f2a9711f3dea1d15494be52a5fc5e1693 /src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala | |
parent | 8d7f73316570a4325111da3b4c0529793ced8b97 (diff) | |
download | scala-466340cf9e3fbc6fbd3c65e13b43d7fe57471d86.tar.gz scala-466340cf9e3fbc6fbd3c65e13b43d7fe57471d86.tar.bz2 scala-466340cf9e3fbc6fbd3c65e13b43d7fe57471d86.zip |
SI-8144 permalinks in scaladoc
Diffstat (limited to 'src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala')
-rw-r--r-- | src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala b/src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala index f6373e9e97..295bae5bef 100644 --- a/src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala +++ b/src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala @@ -14,6 +14,7 @@ import base.comment._ import model._ import scala.xml.NodeSeq +import scala.xml.Elem import scala.xml.dtd.{DocType, PublicID} import scala.collection._ import java.io.Writer @@ -219,4 +220,28 @@ abstract class HtmlPage extends Page { thisPage => else if (ety.isObject) "object_big.png" else if (ety.isPackage) "package_big.png" else "class_big.png" // FIXME: an entity *should* fall into one of the above categories, but AnyRef is somehow not + + def permalink(template: Entity, isSelf: Boolean = true): Elem = + <span class="permalink"> + <a href={ memberToUrl(template, isSelf) } title="Permalink" target="_top"> + <img src={ relativeLinkTo(List("permalink.png", "lib")) } /> + </a> + </span> + + def memberToUrl(template: Entity, isSelf: Boolean = true): String = { + val (signature: Option[String], containingTemplate: TemplateEntity) = template match { + case dte: DocTemplateEntity if (!isSelf) => (Some(dte.signature), dte.inTemplate) + case dte: DocTemplateEntity => (None, dte) + case me: MemberEntity => (Some(me.signature), me.inTemplate) + case tpl => (None, tpl) + } + + def hashFromPath(templatePath: List[String]): String = + ((templatePath.head.replace(".html", "") :: templatePath.tail).reverse).mkString(".") + + val containingTemplatePath = templateToPath(containingTemplate) + val url = "../" * (containingTemplatePath.size - 1) + "index.html" + val hash = hashFromPath(containingTemplatePath) + s"$url#$hash" + signature.map("@" + _).getOrElse("") + } } |