Skip to content

Commit cbbfbff

Browse files
committed
Merge pull request scala#4165 from dickwall/ticket/9006
SI-9006 Scaladoc: explicit companion and package links
2 parents 1e223a5 + 89c000f commit cbbfbff

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/scaladoc/scala/tools/nsc/doc/html/HtmlPage.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,26 @@ abstract class HtmlPage extends Page { thisPage =>
228228
</a>
229229
</span>
230230

231+
def companionAndPackage(tpl: DocTemplateEntity): Elem =
232+
<span class="morelinks">{
233+
tpl.companion match {
234+
case Some(companionTpl) =>
235+
val objClassTrait =
236+
if (companionTpl.isObject) s"object ${tpl.name}"
237+
else if (companionTpl.isTrait) s"trait ${companionTpl.name}"
238+
else s"class ${companionTpl.name}"
239+
<div>
240+
Related Docs:
241+
<a href={relativeLinkTo(tpl.companion.get)} title="See companion">{objClassTrait}</a>
242+
| {templateToHtml(tpl.inTemplate, s"package ${tpl.inTemplate.name}")}
243+
</div>
244+
case None =>
245+
<div>Related Doc:
246+
{templateToHtml(tpl.inTemplate, s"package ${tpl.inTemplate.name}")}
247+
</div>
248+
}
249+
}</span>
250+
231251
def memberToUrl(template: Entity, isSelf: Boolean = true): String = {
232252
val (signature: Option[String], containingTemplate: TemplateEntity) = template match {
233253
case dte: DocTemplateEntity if (!isSelf) => (Some(dte.signature), dte.inTemplate)

src/scaladoc/scala/tools/nsc/doc/html/page/Template.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp
110110
<img src={ relativeLinkTo(List(docEntityKindToBigImage(tpl), "lib")) }/>
111111
}}
112112
{ owner }
113-
<h1>{ displayName }</h1> { permalink(tpl) }
113+
<h1>{ displayName }</h1>{
114+
if (tpl.isPackage) NodeSeq.Empty else <h3>{companionAndPackage(tpl)}</h3>
115+
}{ permalink(tpl) }
114116
</div>
115117

116118
{ signature(tpl, isSelf = true) }

src/scaladoc/scala/tools/nsc/doc/html/resource/lib/template.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,18 @@ div.members > ol > li:last-child {
397397
margin-bottom: 5px;
398398
}
399399

400+
#definition .morelinks {
401+
text-align: right;
402+
position: absolute;
403+
top: 40px;
404+
right: 10px;
405+
width: 450px;
406+
}
407+
408+
#definition .morelinks a {
409+
color: #EBEBEB;
410+
}
411+
400412
#template .members li .permalink {
401413
position: absolute;
402414
top: 5px;

0 commit comments

Comments
 (0)