Skip to content

Commit aafbe91

Browse files
committed
Migrate dokka-site plugin configuration
Dokka-site works as before migration.
1 parent 163beaf commit aafbe91

12 files changed

+176
-322
lines changed

scala3doc/dotty-docs/docs/index.html

Lines changed: 17 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -49,158 +49,31 @@ <h1 id="dotty" class="above-byline">Dotty</h1>
4949
</div>
5050
</div>
5151
</section>
52-
53-
5452
<section class="page bg-blue bg-dark">
55-
<div class="container">
53+
<div class="container">
5654

57-
<h1 id="getting-started">Try Dotty</h1>
58-
<p>If you are a Mac user, you can install Dotty with <a href="https://brew.sh/">brew</a>:</p>
59-
<pre><code>brew install lampepfl/brew/dotty</code></pre>
55+
<h1 id="getting-started">Try Dotty</h1>
56+
<p>If you are a Mac user, you can install Dotty with <a href="https://brew.sh/">brew</a>:</p>
57+
<pre><code>brew install lampepfl/brew/dotty</code></pre>
6058

61-
<p>If you are a Linux or Windows user, download the <a href="https://github.com/lampepfl/dotty/releases">latest release</a>. Optionally add path of the folder <code>bin/</code> to the system environment variable <code>PATH</code>. </p>
59+
<p>If you are a Linux or Windows user, download the <a href="https://github.com/lampepfl/dotty/releases">latest release</a>. Optionally add path of the folder <code>bin/</code> to the system environment variable <code>PATH</code>. </p>
6260

63-
<p>Now you can compile Scala source code:</p>
64-
<pre><code>dotc hello.scala</code></pre>
61+
<p>Now you can compile Scala source code:</p>
62+
<pre><code>scalac hello.scala</code></pre>
6563

66-
<p>To start the REPL, run: <code>dotr</code>.</p>
64+
<p>To start the REPL, run: <code>scala</code>.</p>
6765

68-
<p>Or, you can try Dotty in your browser with <a href="https://scastie.scala-lang.org/?target=dotty">Scastie</a>.</p>
66+
<p>Or, you can try Dotty in your browser with <a href="https://scastie.scala-lang.org/?target=dotty">Scastie</a>.</p>
6967

70-
<h1 id="getting-started-with-a-project">Create a Dotty Project</h1>
71-
<p>The fastest way to create a new project in Dotty is using <a href="http://www.scala-sbt.org/">sbt (1.1.4+)</a>.</p>
68+
<h1 id="getting-started-with-a-project">Create a Dotty Project</h1>
69+
<p>The fastest way to create a new project in Dotty is using <a href="http://www.scala-sbt.org/">sbt (1.1.4+)</a>.</p>
7270

73-
<p>Create a Dotty project:</p>
74-
<pre><code>sbt new <a href="https://github.com/lampepfl/dotty.g8">lampepfl/dotty.g8</a></code></pre>
71+
<p>Create a Dotty project:</p>
72+
<pre><code>sbt new <a href="https://github.com/lampepfl/dotty.g8">lampepfl/dotty.g8</a></code></pre>
7573

76-
<p>Or a Dotty project that cross compiles with Scala 2:</p>
77-
<pre><code>sbt new <a href="https://github.com/lampepfl/dotty-cross.g8">lampepfl/dotty-cross.g8</a></code></pre>
74+
<p>Or a Dotty project that cross compiles with Scala 2:</p>
75+
<pre><code>sbt new <a href="https://github.com/lampepfl/dotty-cross.g8">lampepfl/dotty-cross.g8</a></code></pre>
7876

79-
<p>For documentation see the <a href="https://github.com/lampepfl/dotty-example-project">Dotty Example Project</a>.</p>
80-
</div>
77+
<p>For documentation see the <a href="https://github.com/lampepfl/dotty-example-project">Dotty Example Project</a>.</p>
78+
</div>
8179
</section>
82-
83-
<section class="page bg-teal bg-dark">
84-
<div class="container">
85-
<h1 id="so-features">So, features?</h1>
86-
<div class="centered-table">
87-
<table>
88-
<colgroup>
89-
<col width="82%" />
90-
<col width="17%" />
91-
</colgroup>
92-
<tbody>
93-
<tr>
94-
<td><a href="https://dotty.epfl.ch/docs/reference/new-types/intersection-types.html">Intersection Types</a></td>
95-
<td>Implemented</td>
96-
</tr>
97-
<tr>
98-
<td><a href="https://dotty.epfl.ch/docs/reference/new-types/union-types.html">Union Types</a></td>
99-
<td>Implemented</td>
100-
</tr>
101-
<tr>
102-
<td><a href="https://dotty.epfl.ch/docs/reference/new-types/type-lambdas.html">Type lambdas</a></td>
103-
<td>Implemented</td>
104-
</tr>
105-
<tr>
106-
<td><a href="https://dotty.epfl.ch/docs/reference/contextual/implicit-function-types.html">Context query</a></td>
107-
<td>Implemented</td>
108-
</tr>
109-
<tr>
110-
<td><a href="https://dotty.epfl.ch/docs/reference/other-new-features/trait-parameters.html">Trait parameters</a></td>
111-
<td>Implemented</td>
112-
</tr>
113-
<tr>
114-
<td><a href="https://dotty.epfl.ch/docs/reference/contextual/delegates.html">Implied Instances</a></td>
115-
<td>Implemented</td>
116-
</tr>
117-
<tr>
118-
<td><a href="https://dotty.epfl.ch/docs/reference/contextual/given-clauses.html">Inferable parameters</a></td>
119-
<td>Implemented</td>
120-
</tr>
121-
<tr>
122-
<td><a href="https://dotty.epfl.ch/docs/reference/contextual/extension-methods.html">Extension Methods</a></td>
123-
<td>Implemented</td>
124-
</tr>
125-
<tr>
126-
<td><a href="https://dotty.epfl.ch/docs/reference/other-new-features/opaques.html">Opaque Type Aliases</a></td>
127-
<td>Implemented</td>
128-
</tr>
129-
<tr>
130-
<td><a href="https://dotty.epfl.ch/docs/reference/dropped-features/package-objects.html">Toplevel definitions</a></td>
131-
<td>Implemented</td>
132-
</tr>
133-
<tr>
134-
<td><a href="https://dotty.epfl.ch/docs/reference/other-new-features/export.html">Export clauses</a></td>
135-
<td>Implemented</td>
136-
</tr>
137-
<tr>
138-
<td><a href="https://dotty.epfl.ch/docs/reference/changed-features/vararg-patterns.html">Vararg patterns</a></td>
139-
<td>Implemented</td>
140-
</tr>
141-
<tr>
142-
<td><a href="https://dotty.epfl.ch/docs/reference/other-new-features/creator-applications.html">Creator applications</a></td>
143-
<td>Implemented</td>
144-
</tr>
145-
<tr>
146-
<td><a href="https://github.com/scala/scala.github.com/pull/491">@static methods and fields</a></td>
147-
<td>Implemented</td>
148-
</tr>
149-
<tr>
150-
<td><a href="https://dotty.epfl.ch/#getting-started">SBT incremental build</a></td>
151-
<td>Implemented</td>
152-
</tr>
153-
<tr>
154-
<td><a href="https://dotty.epfl.ch/docs/reference/changed-features/pattern-matching.html">Option-less pattern matching</a></td>
155-
<td>Implemented</td>
156-
</tr>
157-
<tr>
158-
<td><a href="https://dotty.epfl.ch/docs/reference/contextual/multiversal-equality.html">Multiversal equality</a></td>
159-
<td>Implemented</td>
160-
</tr>
161-
<tr>
162-
<td><a href="https://dotty.epfl.ch/docs/reference/metaprogramming/erased-terms.html">Erased Terms</a></td>
163-
<td>Implemented</td>
164-
</tr>
165-
<tr>
166-
<td><a href="https://github.com/dotty-linker/dotty">Auto-Specialization</a></td>
167-
<td>In progress</td>
168-
</tr>
169-
<tr>
170-
<td><a href="https://github.com/lampepfl/dotty/pull/1840">Whole program optimizer</a></td>
171-
<td>In progress</td>
172-
</tr>
173-
<tr>
174-
<td><a href="https://github.com/lampepfl/dotty/pull/2199">HList &amp; HMaps/Record types</a></td>
175-
<td>In progress</td>
176-
</tr>
177-
<tr>
178-
<td></td>
179-
<td></td>
180-
</tr>
181-
<tr>
182-
<td>Effects</td>
183-
<td>Considered</td>
184-
</tr>
185-
<tr>
186-
<td>…and many more, check the <a href="https://dotty.epfl.ch/docs/reference/overview.html">overview page</a> for a comprehensive list</td>
187-
<td></td>
188-
</tr>
189-
</tbody>
190-
</table>
191-
</div>
192-
<h1 id="talks-on-dotty">Talks on Dotty?</h1>
193-
<ul>
194-
<li><a href="https://www.youtube.com/watch?v=GHzWqJKFCk4">Scala's Road Ahead</a> by Martin Odersky (<a href="http://www.slideshare.net/Odersky/scala-days-nyc-2016">slides</a>)</li>
195-
<li><a href="https://www.youtube.com/watch?v=WxyyJyB_Ssc">Compilers are Databases</a> by Martin Odersky (<a href="http://www.slideshare.net/Odersky/compilers-are-databases">slides</a>)</li>
196-
<li><a href="https://www.youtube.com/watch?v=aftdOFuVU1o">Exploring the future of Scala</a> by Dmitry Petrashko (<a href="https://d-d.me/scalaworld2015/#/">slides</a>)</li>
197-
<li><a href="https://dotty.epfl.ch/docs/resources/talks.html">Deep Dive with Dotty</a></li>
198-
</ul>
199-
<h1 id="i-have-more-questions">I have more questions!</h1>
200-
<div class="text-center">
201-
<p>That’s great! We have more details on the <a href="{{ site.baseurl }}/docs">docs</a> and please join our <a href="https://gitter.im/lampepfl/dotty">Gitter channel</a>!</p>
202-
</div>
203-
<br/>
204-
</div>
205-
</section>
206-

scala3doc/src/dotty/dokka/DottyDokkaConfig.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.jetbrains.dokka._
44
import org.jetbrains.dokka.DokkaSourceSetImpl
55
import java.io.File
66
import collection.JavaConverters._
7+
import dotty.dokka.site.StaticSiteContext
78

89
case class DottyDokkaConfig(docConfiguration: DocConfiguration) extends DokkaConfiguration:
910
override def getOutputDir: File = docConfiguration.args.output
@@ -16,15 +17,11 @@ case class DottyDokkaConfig(docConfiguration: DocConfiguration) extends DokkaCon
1617
override def getModuleName(): String = "ModuleName"
1718
override def getModuleVersion(): String = ""
1819

19-
private object OurConfig extends DokkaConfiguration.PluginConfiguration:
20-
override def getFqPluginName = "ExternalDocsTooKey"
21-
override def getSerializationFormat: DokkaConfiguration$SerializationFormat =
22-
DokkaConfiguration$SerializationFormat.JSON.asInstanceOf[DokkaConfiguration$SerializationFormat]
23-
override def getValues: String = docConfiguration.args.docsRoot.getOrElse("")
20+
lazy val staticSiteContext = docConfiguration.args.docsRoot.map(path => StaticSiteContext(File(path).getAbsoluteFile(), Set(mkSourceSet.asInstanceOf[SourceSetWrapper])))
2421

25-
override def getPluginsConfiguration: JList[DokkaConfiguration.PluginConfiguration] = JList(OurConfig)
22+
override def getPluginsConfiguration: JList[DokkaConfiguration.PluginConfiguration] = JList()
2623

27-
def mkSourceSet: DokkaSourceSet =
24+
lazy val mkSourceSet: DokkaSourceSet =
2825
val sourceLinks:Set[SourceLinkDefinitionImpl] = docConfiguration.args.sourceLinks.map(SourceLinkDefinitionImpl.Companion.parseSourceLinkDefinition(_)).toSet
2926
new DokkaSourceSetImpl(
3027
/*displayName=*/ docConfiguration.args.name,

scala3doc/src/dotty/dokka/DottyDokkaPlugin.scala

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import dotty.dokka.model.api._
2323
import org.jetbrains.dokka.CoreExtensions
2424
import org.jetbrains.dokka.base.DokkaBase
2525

26+
import dotty.dokka.site.SitePagesCreator
27+
import dotty.dokka.site.StaticSiteContext
28+
import dotty.dokka.site.RootIndexPageCreator
29+
import dotty.dokka.site.SiteResourceManager
30+
import dotty.dokka.site.StaticSiteLocationProviderFactory
31+
2632
/** Main Dokka plugin for the doctool.
2733
*
2834
* Wires together classes responsible for consuming Tasty and generating
@@ -120,7 +126,7 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
120126
)
121127

122128
val implicitMembersExtensionTransformer = extend(
123-
_.extensionPoint(CoreExtensions.INSTANCE.getDocumentableTransformer )
129+
_.extensionPoint(CoreExtensions.INSTANCE.getDocumentableTransformer)
124130
.fromRecipe(ImplicitMembersExtensionTransformer(_))
125131
.name("implicitMembersExtensionTransformer")
126132
)
@@ -134,6 +140,54 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
134140
.name("muteDefaultSourceLinksTransformer")
135141
)
136142

143+
val customDocumentationProvider = extend(
144+
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
145+
.fromRecipe(c => SitePagesCreator(c.siteContext))
146+
.name("customDocumentationProvider")
147+
.ordered(
148+
before = Seq(
149+
dokkaBase.getNavigationPageInstaller,
150+
dokkaBase.getScriptsInstaller,
151+
dokkaBase.getStylesInstaller,
152+
dokkaBase.getPackageListCreator,
153+
),
154+
after = Seq(dokkaBase.getRootCreator)
155+
)
156+
)
157+
158+
val customIndexRootProvider = extend(
159+
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
160+
.fromRecipe(c => RootIndexPageCreator(c.siteContext))
161+
.name("customIndexRootProvider")
162+
.ordered(
163+
before = Seq(
164+
dokkaBase.getScriptsInstaller,
165+
dokkaBase.getStylesInstaller,
166+
),
167+
after = Seq(dokkaBase.getNavigationPageInstaller)
168+
)
169+
)
170+
171+
val customDocumentationResources = extend(
172+
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
173+
.fromRecipe(c => SiteResourceManager(c.siteContext))
174+
.name("customDocumentationResources")
175+
.after(
176+
scalaEmbeddedResourceAppender.getValue
177+
)
178+
)
179+
180+
val locationProvider = extend(
181+
_.extensionPoint(dokkaBase.getLocationProviderFactory)
182+
.fromRecipe(StaticSiteLocationProviderFactory(_))
183+
.overrideExtension(dokkaBase.getLocationProvider)
184+
)
185+
186+
extension (ctx: DokkaContext):
187+
def siteContext: Option[StaticSiteContext] = ctx.getConfiguration match
188+
case d: DottyDokkaConfig => d.staticSiteContext
189+
case _ => None
190+
137191
// TODO (https://github.com/lampepfl/scala3doc/issues/232): remove once problem is fixed in Dokka
138192
extension [T] (builder: ExtensionBuilder[T]):
139193
def ordered(before: Seq[Extension[_, _, _]], after: Seq[Extension[_, _, _]]): ExtensionBuilder[T] =

scala3doc/src/dotty/dokka/compat.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.jetbrains.dokka.model.properties.ExtraProperty
1212
import java.util.stream.Stream // comment out - wrong error!
1313
import java.util.stream.Collectors
1414

15-
def mkDRI(classNames: String = null, extra: String = null) = new DRI(null, classNames, null, PointingToDeclaration.INSTANCE, extra)
15+
def mkDRI(packageName: String = null, extra: String = null) = new DRI(packageName, null, null, PointingToDeclaration.INSTANCE, extra)
1616

1717
val U: kotlin.Unit = kotlin.Unit.INSTANCE
1818

@@ -56,4 +56,4 @@ extension [V] (map: JMap[SourceSetWrapper, V]):
5656

5757
extension [V](jlist: JList[V]):
5858
def ++ (other: JList[V]): JList[V] =
59-
Stream.of(jlist, other).flatMap(_.stream).collect(Collectors.toList())
59+
Stream.of(jlist, other).flatMap(_.stream).collect(Collectors.toList())

scala3doc/src/dotty/dokka/site/contentNodes.scala renamed to scala3doc/src/dotty/dokka/site/PartiallyRenderedContent.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ import org.jetbrains.dokka.model.properties.PropertyContainer
66
import org.jetbrains.dokka.pages.{ContentNode, DCI, Style}
77

88
case class PartiallyRenderedContent(
9-
page: PreResolvedPage,
9+
template: TemplateFile,
10+
context: StaticSiteContext,
1011
override val getChildren: JList[ContentNode],
1112
override val getDci: DCI,
1213
override val getSourceSets: JSet[DisplaySourceSet],
1314
override val getStyle: JSet[Style] = JSet(),
1415
override val getExtra: PropertyContainer[ContentNode] = new PropertyContainer(JMap())
1516
) extends ContentNode:
16-
override def hasAnyContent(): Boolean = getChildren.stream().filter(_.hasAnyContent()).count() > 0
17+
override def hasAnyContent(): Boolean = true
1718

1819
override def withNewExtras(newExtras: PropertyContainer[ContentNode]): ContentNode =
1920
copy(getExtra = newExtras)
2021

2122
override def withSourceSets(sourceSets: JSet[DisplaySourceSet]): ContentNode =
2223
copy(getSourceSets = sourceSets)
2324

24-
val allResources: List[String] = page.render("").resources
25+
lazy val resolved = template.resolveToHtml(context)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dotty.dokka
2+
package site
3+
4+
import java.io.File
5+
import java.nio.file.Files
6+
7+
import org.jetbrains.dokka.base.renderers.html.{NavigationNode, NavigationPage}
8+
import org.jetbrains.dokka.links.DRI
9+
import org.jetbrains.dokka.model.Documentable
10+
import org.jetbrains.dokka.pages._
11+
import org.jetbrains.dokka.transformers.pages.PageTransformer
12+
13+
case class LoadedTemplate(templateFile: TemplateFile, children: List[LoadedTemplate], file: File) {
14+
def relativePath(root: File): String =
15+
root.toPath().relativize(file.toPath()).toString().replace(File.separatorChar, '.')
16+
}
17+
18+
case class StaticPageNode(
19+
template: TemplateFile,
20+
override val getName: String,
21+
override val getContent: ContentNode,
22+
override val getDri: JSet[DRI],
23+
override val getEmbeddedResources: JList[String],
24+
override val getChildren: JList[PageNode],
25+
) extends ContentPage:
26+
override def getDocumentable: Documentable = null
27+
28+
def title(): String = template.title()
29+
def hasFrame(): Boolean = template.hasFrame()
30+
31+
override def modified(name: String, content: ContentNode, dri: JSet[DRI], embeddedResources: JList[String], children: JList[_ <: PageNode]): ContentPage =
32+
copy(template, name, content, dri, embeddedResources, children.asInstanceOf[JList[PageNode]])
33+
34+
override def modified(name: String, children: JList[_ <: PageNode]): PageNode =
35+
copy(getName = name, getChildren = children.asInstanceOf[JList[PageNode]])
36+
37+
def resources(): List[String] = getContent match
38+
case p: PartiallyRenderedContent => p.resolved.resources
39+
case _ => Nil

0 commit comments

Comments
 (0)