summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
diff options
context:
space:
mode:
authorGilles Dubochet <gilles.dubochet@epfl.ch>2009-12-02 17:31:28 +0000
committerGilles Dubochet <gilles.dubochet@epfl.ch>2009-12-02 17:31:28 +0000
commit6995333a275d0d403869a1cd9d7e92b530bd0e86 (patch)
tree810df836cfe5866a21a96cd1c5fdce02e8b6ad11 /src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
parent5697e1115b8895e06cb91a4a6e70d0f73e5aa9ab (diff)
downloadscala-6995333a275d0d403869a1cd9d7e92b530bd0e86.tar.gz
scala-6995333a275d0d403869a1cd9d7e92b530bd0e86.tar.bz2
scala-6995333a275d0d403869a1cd9d7e92b530bd0e86.zip
[scaladoc] Types are links.
Diffstat (limited to 'src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala')
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala b/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
index 48073f8e59..3760099a26 100644
--- a/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
@@ -38,7 +38,7 @@ abstract class HtmlPage { thisPage =>
/** 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: SiteFactory): Unit = {
+ def writeFor(site: HtmlFactory): Unit = {
val pageFile = new File(site.siteRoot, absoluteLinkTo(thisPage.path))
val pageFolder = pageFile.getParentFile
if (!pageFolder.exists) pageFolder.mkdirs()
@@ -145,12 +145,34 @@ abstract class HtmlPage { thisPage =>
case Text(text) => Unparsed(text)
}
- def typeToHtml(tpe: model.TypeEntity): NodeSeq = {
-
- // TODO: Generate links using tpe's refEntity map
-
- xml.Text(tpe.name)
-
+ def typeToHtml(tpe: model.TypeEntity, hasLinks: Boolean): NodeSeq = {
+ val string = tpe.name
+ def toLinksOut(inPos: Int, starts: List[Int]): NodeSeq = {
+ if (starts.isEmpty && (inPos == string.length))
+ NodeSeq.Empty
+ else if (starts.isEmpty)
+ xml.Text(string.slice(inPos, string.length))
+ else if (inPos == starts.head)
+ toLinksIn(inPos, starts)
+ else {
+ xml.Text(string.slice(inPos, starts.head)) ++ toLinksIn(starts.head, starts)
+ }
+ }
+ def toLinksIn(inPos: Int, starts: List[Int]): NodeSeq = {
+ val (tpl, width) = tpe.refEntity(inPos)
+ (tpl match {
+ case dtpl:DocTemplateEntity if hasLinks =>
+ <a href={ relativeLinkTo(tpl) } class="extype" name={ dtpl.qualifiedName }>{
+ string.slice(inPos, inPos + width)
+ }</a>
+ case tpl =>
+ <span class="extype" name={ tpl.qualifiedName }>{ string.slice(inPos, inPos + width) }</span>
+ }) ++ toLinksOut(inPos + width, starts.tail)
+ }
+ if (hasLinks)
+ toLinksOut(0, tpe.refEntity.keySet.toList)
+ else
+ xml.Text(string)
}
}