Skip to content

Commit 5d96a3b

Browse files
committed
Apply requested changes to scaladoc
1 parent 2ebba6f commit 5d96a3b

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

docs/_layouts/main.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
layout: base
33
---
44
<div id="content-wrapper">
5+
{% if page.movedTo %}
6+
<aside class="warning">
7+
The content of this page is outdated. Click <a href="{{ page.movedTo }}">here</a> to find the up to date version of this page.
8+
</aside>
9+
{% endif %}
510
{{ content }}
611
</div>
712
<script>

project/Build.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,7 @@ object Build {
12951295
name,
12961296
scalaSrcLink(stdLibVersion, srcManaged(dottyNonBootstrappedVersion, "scala") + "="),
12971297
dottySrcLink(referenceVersion, srcManaged(dottyNonBootstrappedVersion, "dotty") + "=", "#library/src"),
1298+
dottySrcLink(referenceVersion, "docs-for-dotty-page=", "#docs"),
12981299
dottySrcLink(referenceVersion),
12991300
"-Ygenerate-inkuire",
13001301
) ++ scalacOptionsDocSettings(includeExternalMappings) ++ revision ++ params ++ targets

scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings:
139139
StringSetting(
140140
"-default-template",
141141
"default template used by static site",
142-
"The static site is generating empty files for indexes that haven't been provided explicitly. User can specify what template should be used for such generic indexes (note it can still interpolate some general settings)",
142+
"The static site is generating empty files for indexes that haven't been provided explicitly in a sidebar/missing index.html in directory. " +
143+
"User can specify what default template should be used for such indexes. It can be useful for providing generic templates that interpolate some common settings, like title, or can have some custom html embedded.",
143144
""
144145
)
145146

scaladoc/src/dotty/tools/scaladoc/renderers/Renderer.scala

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package renderers
33

44
import util.HTML._
55
import collection.JavaConverters._
6+
import collection.mutable.ListBuffer
67
import java.net.URI
78
import java.net.URL
89
import dotty.tools.scaladoc.site._
@@ -55,7 +56,7 @@ abstract class Renderer(rootPackage: Member, val members: Map[DRI, Member], prot
5556
val allTemplates: Seq[Option[LoadedTemplate]] = None +: templates.flatMap(flattenedTemplates).map(Some(_)) :+ None
5657

5758
// Let's gather the list of maps for each template with its in-order neighbours
58-
val newSettings: Seq[Map[String, Object]] = allTemplates.sliding(size = 3, step = 1).map {
59+
val newSettings: List[Map[String, Object]] = allTemplates.sliding(size = 3, step = 1).map {
5960
case None :: None :: Nil =>
6061
Map.empty
6162
case prev :: mid :: next :: Nil =>
@@ -67,30 +68,22 @@ abstract class Renderer(rootPackage: Member, val members: Map[DRI, Member], prot
6768
realMidPath.relativize(realSiblingPath).toString.stripPrefix("../")
6869
}
6970
List(link(prev).map("previous" -> _), link(next).map("next" -> _)).flatten.toMap
70-
}.toSeq
71-
72-
// We update the immutable tree of templates by walking in-order
73-
def updateSettings(template: LoadedTemplate, additionalSettings: Seq[Map[String, Object]]): (LoadedTemplate, Seq[Map[String, Object]]) =
74-
val head :: tail = additionalSettings
75-
val (newChildren, newAdditionalSettings): (List[LoadedTemplate], List[Seq[Map[String, Object]]]) = template.children.scanLeft((null: LoadedTemplate, tail: Seq[Map[String, Object]])) { case ((_, aS), template) =>
76-
updateSettings(template, aS)
77-
}.unzip
78-
val newLoadedTemplate = template.copy(
79-
templateFile = template.templateFile.copy(settings = template.templateFile.settings.updated("page", head ++ template.templateFile.settings.getOrElse("page", Map.empty).asInstanceOf[Map[String, Object]])),
80-
children = newChildren.drop(1) // We drop trailing null from the first `scanLeft` output collection
81-
)
82-
83-
(newLoadedTemplate, newAdditionalSettings.last)
84-
end updateSettings
85-
86-
// We run the above function for the templates. We could do some temporary parent template so it would be just `updatedSettings(...)` but we would eventually post-process it so it has no difference
87-
val (newTemplates, _): (List[LoadedTemplate], List[Seq[Map[String, Object]]]) = templates.scanLeft((null: LoadedTemplate, newSettings)) {
88-
case ((_, aS), template) =>
89-
updateSettings(template, aS)
90-
}.unzip
91-
92-
// We finally obtain updated template pages. Once again we drop first null from `scanLeft` and map it using `templateToPage`
93-
val templatePages = newTemplates.drop(1).map(templateToPage(_, siteContext))
71+
}.toList
72+
73+
def updateSettings(templates: Seq[LoadedTemplate], additionalSettings: ListBuffer[Map[String, Object]]): List[LoadedTemplate] =
74+
val updatedTemplates = List.newBuilder[LoadedTemplate]
75+
for template <- templates do
76+
val head: Map[String, Object] = additionalSettings.remove(0)
77+
val current: Map[String, Object] = template.templateFile.settings.getOrElse("page", Map.empty).asInstanceOf[Map[String, Object]]
78+
val updatedTemplateFile = template.templateFile.copy(settings = template.templateFile.settings.updated("page", head ++ current))
79+
updatedTemplates += template.copy(
80+
templateFile = updatedTemplateFile,
81+
children = updateSettings(template.children, additionalSettings)
82+
)
83+
updatedTemplates.result()
84+
85+
val newTemplates = updateSettings(templates, newSettings.to(ListBuffer))
86+
val templatePages = newTemplates.map(templateToPage(_, siteContext))
9487

9588
indexes.headOption match
9689
case None if templatePages.isEmpty=>

scaladoc/src/dotty/tools/scaladoc/site/LoadedTemplate.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ case class LoadedTemplate(
4646
// toRealPath is used to turn symlinks into proper paths
4747
val actualPath = Paths.get("").toAbsolutePath.relativize(file.toPath.toRealPath())
4848
ctx.sourceLinks.pathTo(actualPath).map("viewSource" -> _ ) ++
49-
ctx.sourceLinks.pathTo(actualPath, operation = "edit", optionalRevision = Some("master")).map("editSource" -> _.replace("docs-for-dotty-page/", "docs/"))
49+
ctx.sourceLinks.pathTo(actualPath, operation = "edit", optionalRevision = Some("master")).map("editSource" -> _)
5050

5151
val updatedSettings = templateFile.settings ++ ctx.projectWideProperties +
5252
("site" -> (getMap("site") + ("posts" -> posts))) + ("urls" -> sourceLinks.toMap) +

0 commit comments

Comments
 (0)