Skip to content

Commit 21a5401

Browse files
authored
Merge pull request #14669 from dotty-staging/scaladoc/tweak-reference-documentation
Tweak Language Reference documentation
2 parents 3d06d94 + 4fc4951 commit 21a5401

File tree

27 files changed

+76
-39
lines changed

27 files changed

+76
-39
lines changed

docs/_blog/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<h1>{{ page.title }}</h1>
77

88
<ul class="post-list">
9-
{% for post in site.posts %}
9+
{% for post in site.subpages %}
1010
<li>
1111
<h2>
1212
<a href="{{ post.url }}">{{ post.title }}</a>

docs/_docs/contributing/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: index
3+
title: Contributing
4+
---

docs/_docs/index.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
layout: doc-page
3-
redirectFrom: docs/index.html
2+
layout: index
3+
redirectFrom: /docs/index.html
44
---
55

66
Dotty is the project name for technologies that are considered for inclusion in Scala 3. Scala has
@@ -16,7 +16,3 @@ be a big step towards realizing the full potential of these ideas. Its main obje
1616
In this documentation you will find information on how to use the Dotty compiler on your machine,
1717
navigate through the code, setup Dotty with your favorite IDE and more!
1818

19-
Table of Contents
20-
=================
21-
{% assign titles = sidebar.titles %}
22-
{% include "table-of-contents" %}

docs/_docs/internals/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
layout: index
3+
title: Internals
4+
---
5+

docs/_docs/reference/changed-features/changed-features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: doc-page
2+
layout: index
33
title: "Other Changed Features"
44
movedTo: https://docs.scala-lang.org/scala3/reference/changed-features.html
55
---

docs/_docs/reference/contextual/contextual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: doc-page
2+
layout: index
33
title: "Contextual Abstractions"
44
movedTo: https://docs.scala-lang.org/scala3/reference/contextual.html
55
---

docs/_docs/reference/dropped-features/dropped-features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: doc-page
2+
layout: index
33
title: "Dropped Features"
44
movedTo: https://docs.scala-lang.org/scala3/reference/dropped-features.html
55
---

docs/_docs/reference/enums/enums-index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: doc-page
2+
layout: index
33
title: "Enums"
44
movedTo: https://docs.scala-lang.org/scala3/reference/enums.html
55
---

docs/_docs/reference/experimental/named-typeargs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: doc-page
33
title: "Named Type Arguments"
4-
redirectFrom: reference/other-new-features/named-typeargs.html
4+
redirectFrom: /docs/reference/other-new-features/named-typeargs.html
55
movedTo: https://docs.scala-lang.org/scala3/reference/experimental/named-typeargs.html
66
---
77

docs/_docs/reference/experimental/overview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
layout: doc-page
3-
title: "Overview"
3+
title: "Experimental"
44
movedTo: https://docs.scala-lang.org/scala3/reference/experimental/overview.html
5+
redirectFrom: overview.html
56
---
67

78
### Experimental language features

docs/_docs/reference/language-versions/language-versions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: doc-page
2+
layout: index
33
title: "Language Versions"
44
---
55

docs/_docs/reference/metaprogramming/metaprogramming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: doc-page
2+
layout: index
33
title: "Metaprogramming"
44
movedTo: https://docs.scala-lang.org/scala3/reference/metaprogramming.html
55
---

docs/_docs/reference/new-types/new-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: doc-page
2+
layout: index
33
title: "New Types"
44
movedTo: https://docs.scala-lang.org/scala3/reference/new-types.html
55
---

docs/_docs/reference/other-new-features/other-new-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: doc-page
2+
layout: index
33
title: "Other New Features"
44
movedTo: https://docs.scala-lang.org/scala3/reference/other-new-features.html
55
---

docs/_docs/reference/overview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
layout: doc-page
3-
title: "Overview"
3+
title: "Reference"
44
movedTo: https://docs.scala-lang.org/scala3/reference/overview.html
5+
redirectFrom: overview.html
56
---
67

78
Scala 3 implements many language changes and improvements over Scala 2.

docs/_docs/usage/dottydoc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ An example of this would be:
107107
To be rendered as templates, each blog post should have front-matter and a
108108
`layout` declaration.
109109

110-
The posts are also available in the variable `site.posts` throughout the site.
110+
The posts are also available in the variable `site.subpages` throughout the site.
111111
The fields of these objects are the same as in
112112
`[BlogPost](dotty.tools.dottydoc.staticsite.BlogPost)`.
113113

docs/_docs/usage/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: index
3+
title: Usage
4+
---

docs/_docs/usage/scaladoc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: doc-page
2+
layout: index
33
title: "Scaladoc"
44
---
55

docs/_layouts/index.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
---
2-
layout: main
2+
layout: static-site-main
33
---
4-
<h1>{{ content }}</h1>
4+
<h1>{{ page.title }}</h1>
5+
6+
{{ content }}
7+
8+
<h2>Table of Contents</h2>
9+
<ul class="table-of-contents">
10+
{% for subpage in site.subpages %}
11+
<li>
12+
<a href="{{ subpage.url }}">{{ subpage.title }}</a>
13+
</li>
14+
{% endfor %}
15+
</ul>

docs/sidebar.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ index: index.md
22
subsection:
33
- title: Usage
44
directory: docs/usage
5+
index: usage/index.md
56
subsection:
67
- page: usage/sbt-projects.md
78
- page: usage/ide-support.md
@@ -17,8 +18,8 @@ subsection:
1718
- page: usage/scaladoc/static-site.md
1819
- title: Reference
1920
directory: docs/reference
21+
index: reference/overview.md
2022
subsection:
21-
- page: reference/overview.md
2223
- title: New Types
2324
index: reference/new-types/new-types.md
2425
subsection:
@@ -137,8 +138,8 @@ subsection:
137138
- page: reference/dropped-features/wildcard-init.md
138139
- title: Experimental Features
139140
directory: experimental
141+
index: reference/experimental/overview.md
140142
subsection:
141-
- page: reference/experimental/overview.md
142143
- page: reference/experimental/canthrow.md
143144
- page: reference/experimental/erased-defs.md
144145
- page: reference/experimental/erased-defs-spec.md
@@ -157,6 +158,7 @@ subsection:
157158
- page: reference/features-classification.md
158159
- title: Contributing
159160
directory: docs/contributing
161+
index: contributing/index.md
160162
subsection:
161163
- page: contributing/contribute-knowledge.md
162164
- page: contributing/getting-started.md
@@ -175,6 +177,7 @@ subsection:
175177
- page: contributing/procedures/vulpix.md
176178
- title: Internals
177179
directory: docs/internals
180+
index: internals/index.md
178181
subsection:
179182
- page: internals/backend.md
180183
- page: internals/classpaths.md

project/Build.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,7 @@ object Build {
13921392
.add(OutputDir("scaladoc/output/reference"))
13931393
.add(SiteRoot(s"${temp.getAbsolutePath}/docs"))
13941394
.add(ProjectName("Scala 3 Reference"))
1395+
.remove[VersionsDictionaryUrl]
13951396
.add(SourceLinks(List(
13961397
dottySrcLink(referenceVersion, temp.getAbsolutePath + "=")
13971398
)))

project/resources/referenceReplacements/sidebar.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
index: reference/overview.md
22
subsection:
3-
- page: reference/overview.md
43
- title: New Types
54
index: reference/new-types/new-types.md
65
subsection:
@@ -119,8 +118,8 @@ subsection:
119118
- page: reference/dropped-features/wildcard-init.md
120119
- title: Experimental Features
121120
directory: experimental
121+
index: reference/experimental/overview.md
122122
subsection:
123-
- page: reference/experimental/overview.md
124123
- page: reference/experimental/canthrow.md
125124
- page: reference/experimental/erased-defs.md
126125
- page: reference/experimental/erased-defs-spec.md
@@ -136,4 +135,4 @@ subsection:
136135
- page: reference/language-versions/source-compatibility.md
137136
- page: reference/language-versions/binary-compatibility.md
138137
- page: reference/soft-modifier.md
139-
- page: reference/features-classification.md
138+
- page: reference/features-classification.md

scaladoc-js/common/src/code-snippets/CodeSnippets.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class CodeSnippets:
179179
val buttonsSection = getButtonsSection(snippet)
180180
buttonsSection.foreach(s =>
181181
s.appendChild(copyButton)
182-
if !snippet.hasAttribute("hasContext") then {
182+
if snippet.hasAttribute("runnable") then {
183183
s.appendChild(toScastieButton)
184184
s.appendChild(runButton)
185185
s.appendChild(exitButton)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: static-site-main
33
redirectFrom:
4-
- docs/fr.html
5-
- docs/my-custom-link
4+
- /docs/fr.html
5+
- /docs/my-custom-link
66
---
77
F1

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ case class LoadedTemplate(
3939
)
4040

4141
def resolveToHtml(ctx: StaticSiteContext): ResolvedPage =
42-
val posts = children.map(_.lazyTemplateProperties(ctx))
42+
val subpages = children.filterNot(_.hidden).map(_.lazyTemplateProperties(ctx))
4343
def getMap(key: String) = templateFile.settings.getOrElse(key, Map.empty).asInstanceOf[Map[String, Object]]
4444

4545
val sourceLinks = if !file.exists() then Nil else
@@ -50,7 +50,7 @@ case class LoadedTemplate(
5050
ctx.sourceLinks.pathTo(actualPath, operation = "edit", optionalRevision = Some("master")).map("editSource" -> _)
5151

5252
val updatedSettings = templateFile.settings ++ ctx.projectWideProperties +
53-
("site" -> (getMap("site") + ("posts" -> posts))) + ("urls" -> sourceLinks.toMap) +
53+
("site" -> (getMap("site") + ("subpages" -> subpages))) + ("urls" -> sourceLinks.toMap) +
5454
("page" -> (getMap("page") + ("title" -> templateFile.title.name)))
5555

5656
templateFile.resolveInner(RenderingContext(updatedSettings, ctx.layouts))(using ctx)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ class StaticSiteContext(
4646
allTemplates.flatMap { loadedTemplate =>
4747
val redirectFrom = loadedTemplate.templateFile.settings.getOrElse("page", Map.empty).asInstanceOf[Map[String, Object]].get("redirectFrom")
4848
def redirectToTemplate(redirectFrom: String) =
49-
val fakeFile = new File(docsPath.toFile, redirectFrom)
50-
val driFrom = driFor(fakeFile.toPath)
49+
val path = if redirectFrom.startsWith("/")
50+
then relativizeFrom.resolve(redirectFrom.drop(1))
51+
else loadedTemplate.file.toPath.resolveSibling(redirectFrom)
52+
val driFrom = driFor(path)
5153
val driTo = driFor(loadedTemplate.file.toPath)
52-
(LoadedTemplate(layouts("redirect"), List.empty, fakeFile), driFrom, driTo)
54+
(LoadedTemplate(layouts("redirect"), List.empty, path.toFile), driFrom, driTo)
5355
redirectFrom.map {
5456
case redirectFrom: String => Seq(redirectToTemplate(redirectFrom))
5557
case redirects: List[?] => redirects.asInstanceOf[List[String]].map(redirectToTemplate)

scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.vladsch.flexmark.html._
55
import util.HTML._
66

77
import dotty.tools.scaladoc.snippets._
8-
import dotty.tools.scaladoc.util.HTML._
98

109
case class SnippetLine(content: String, lineNo: Int, classes: Set[String] = Set.empty, messages: Seq[String] = Seq.empty, attributes: Map[String, String] = Map.empty):
1110
def withClass(cls: String) = this.copy(classes = classes + cls)
@@ -134,15 +133,26 @@ object SnippetRenderer:
134133
div(cls := "snippet-label")(name)
135134
).toString
136135

137-
def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean): String =
136+
def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean, success: Boolean): String =
138137
val transformedLines = wrapCodeLines.andThen(addCompileMessages(messages)).apply(codeLines).map(_.toHTML)
139138
val codeHTML = s"""<code class="language-scala">${transformedLines.mkString("")}</code>"""
140-
s"""<div class="snippet" scala-snippet ${if hasContext then "hasContext" else ""}><div class="buttons"></div><pre>$codeHTML</pre>${snippetName.fold("")(snippetLabel(_))}</div>"""
139+
val isRunnable = !hasContext && success
140+
val attrs = Seq(
141+
Option.when(isRunnable)(Attr("runnable") := "")
142+
).flatten
143+
div(cls := "snippet", Attr("scala-snippet") := "", attrs)(
144+
div(cls := "buttons")(),
145+
pre(
146+
raw(codeHTML)
147+
),
148+
raw(snippetName.fold("")(snippetLabel(_)))
149+
).toString
141150

142151
def renderSnippetWithMessages(node: ExtendedFencedCodeBlock): String =
143152
renderSnippetWithMessages(
144153
node.name,
145154
node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq,
146155
node.compilationResult.toSeq.flatMap(_.messages),
147-
node.hasContext
156+
node.hasContext,
157+
node.compilationResult.fold(false)(_.isSuccessful)
148158
)

0 commit comments

Comments
 (0)