Skip to content

Commit 8c63d66

Browse files
committed
Fix incorrect svg on objects with companion traits
1 parent 296e950 commit 8c63d66

File tree

5 files changed

+71
-35
lines changed

5 files changed

+71
-35
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class HtmlFactory(val universe: doc.Universe, val reporter: ScalaDocReporter) {
3333
"class_comp.svg",
3434
"object_comp.svg",
3535
"trait_comp.svg",
36+
"object_comp_trait.svg",
3637
"abstract_type.svg",
3738
"lato-v11-latin-100.eot",
3839
"lato-v11-latin-100.ttf",

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

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -216,41 +216,16 @@ abstract class HtmlPage extends Page { thisPage =>
216216
val Trait, Class, Type, Object, Package = Value
217217
}
218218

219-
/** Returns the _big image name and the alt attribute
220-
* corresponding to the DocTemplate Entity (upper left icon) */
221-
def docEntityKindToBigImage(ety: DocTemplateEntity) = {
222-
def entityToImage(e: DocTemplateEntity) =
223-
if (e.isTrait) Image.Trait
224-
else if (e.isClass) Image.Class
225-
else if (e.isAbstractType || e.isAliasType) Image.Type
226-
else if (e.isObject) Image.Object
227-
else if (e.isPackage) Image.Package
228-
else {
229-
// FIXME: an entity *should* fall into one of the above categories,
230-
// but AnyRef is somehow not
231-
Image.Class
232-
}
233-
234-
val image = entityToImage(ety)
235-
val companionImage = ety.companion filter {
236-
e => e.visibility.isPublic && ! e.inSource.isEmpty
237-
} map { entityToImage }
238-
239-
(image, companionImage) match {
240-
case (from, Some(to)) =>
241-
((from + "_to_" + to + "_big.png").toLowerCase, from + "/" + to)
242-
case (from, None) =>
243-
((from + "_big.png").toLowerCase, from.toString)
244-
}
245-
}
246-
247219
def permalink(template: Entity, isSelf: Boolean = true): Elem =
248220
<span class="permalink">
249221
<a href={ memberToUrl(template, isSelf) } title="Permalink">
250222
<i class="material-icons">&#xE157;</i>
251223
</a>
252224
</span>
253225

226+
def docEntityImageClass(tpl: DocTemplateEntity): String =
227+
tpl.kind + tpl.companion.fold("")("-companion-" + _.kind)
228+
254229
def docEntityKindToCompanionTitle(ety: DocTemplateEntity, baseString: String = "See companion") =
255230
ety.companion match{
256231
case Some(companion) =>

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,13 @@ trait EntityPage extends HtmlPage {
216216
<body class={ tpl.kind + (if (tpl.isType) " type" else " value") }>
217217
<div id="definition">
218218
{
219-
val (src, alt) = docEntityKindToBigImage(tpl)
220-
val identifier = alt.toString.substring(0,2).toLowerCase
219+
val imageClass = docEntityImageClass(tpl)
221220

222221
tpl.companion match {
223222
case Some(companion) if (companion.visibility.isPublic && companion.inSource != None) =>
224-
<a href={relativeLinkTo(companion)} title={docEntityKindToCompanionTitle(tpl)}><div class={s"big-circle companion $identifier"}>{ identifier.substring(0,1) }</div></a>
223+
<a href={relativeLinkTo(companion)} title={docEntityKindToCompanionTitle(tpl)}><div class={s"big-circle $imageClass"}>{ imageClass.substring(0,1) }</div></a>
225224
case _ =>
226-
<div class={ "big-circle " + alt.toString.toLowerCase }>{ identifier.substring(0,1) }</div>
225+
<div class={s"big-circle $imageClass"}>{ imageClass.substring(0,1) }</div>
227226
}
228227
}
229228
{ owner }
Lines changed: 57 additions & 0 deletions
Loading

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,22 @@ span.symbol > a {
216216
background: url("class.svg") no-repeat center;
217217
}
218218

219-
.big-circle.cl.companion {
219+
.big-circle.class-companion-object {
220220
background: url("class_comp.svg") no-repeat center;
221221
}
222222

223-
.big-circle.ob.companion {
223+
.big-circle.object-companion-class {
224224
background: url("object_comp.svg") no-repeat center;
225225
}
226226

227-
.big-circle.tr.companion {
227+
.big-circle.trait-companion-object {
228228
background: url("trait_comp.svg") no-repeat center;
229229
}
230230

231+
.big-circle.object-companion-trait {
232+
background: url("object_comp_trait.svg") no-repeat center;
233+
}
234+
231235
.big-circle.object {
232236
background: url("object.svg") no-repeat center;
233237
}

0 commit comments

Comments
 (0)