Skip to content

Commit 2ad4bed

Browse files
committed
Add handling for scaladoc 2 flags: private, groups, author, canonical doc url, project footer.
1 parent 585f424 commit 2ad4bed

File tree

8 files changed

+85
-42
lines changed

8 files changed

+85
-42
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

-30
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,6 @@ trait CommonScalaSettings { self: Settings.SettingGroup =>
5252
val showPlugins: Setting[Boolean] = BooleanSetting ("-Xplugin-list", "Print a synopsis of loaded plugins.")
5353
val pluginsDir: Setting[String] = StringSetting ("-Xpluginsdir", "path", "Path to search for plugin archives.", Defaults.scalaPluginPath)
5454
val pluginOptions: Setting[List[String]] = MultiStringSetting ("-P", "plugin:opt", "Pass an option to a plugin, e.g. -P:<plugin>:<opt>")
55-
56-
/** Doctool specific settings */
57-
val siteRoot: Setting[String] = StringSetting(
58-
"-siteroot",
59-
"site root",
60-
"A directory containing static files from which to generate documentation.",
61-
"./docs"
62-
)
63-
64-
65-
val projectName: Setting[String] = StringSetting (
66-
"-project",
67-
"project title",
68-
"The name of the project.",
69-
""
70-
)
71-
72-
val projectVersion: Setting[String] = StringSetting (
73-
"-project-version",
74-
"project version",
75-
"The current version of your project.",
76-
""
77-
)
78-
79-
val projectLogo: Setting[String] = StringSetting(
80-
"-project-logo",
81-
"project logo filename",
82-
"The file that contains the project's logo (in /images).",
83-
""
84-
)
8555
}
8656

8757
class ScalaSettings extends Settings.SettingGroup with CommonScalaSettings {

project/Build.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ object Build {
291291
disableDocSetting
292292
)
293293

294+
private lazy val currentYear: String = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR).toString
295+
294296
lazy val scalacOptionsDocSettings = Seq(
295297
"-external-mappings:" +
296298
".*scala.*::scaladoc3::http://dotty.epfl.ch/api/," +
@@ -309,6 +311,9 @@ object Build {
309311
// Reflect doesn't expect to see it as a standalone definition
310312
// and therefore it's easier just not to document it
311313
"-skip-by-id:scala.runtime.MatchCase",
314+
"-project-footer", s"Copyright (c) 2002-$currentYear, LAMP/EPFL",
315+
"-author",
316+
"-groups"
312317
)
313318

314319
// Settings used when compiling dotty with a non-bootstrapped dotty
@@ -426,7 +431,7 @@ object Build {
426431
s"""version.number=${version.value}
427432
|maven.version.number=${version.value}
428433
|git.hash=${VersionUtil.gitHash}
429-
|copyright.string=Copyright 2002-${Calendar.getInstance().get(Calendar.YEAR)}, LAMP/EPFL
434+
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
430435
""".stripMargin
431436

432437
if (!(file.exists && IO.read(file) == contents)) {

scaladoc-testcases/src/example/Documentation2.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ class UserDocLinkingClass {
99

1010
object ReturnObjectWithType {
1111
type returnType = Int
12-
}
12+
}

scaladoc/src/dotty/tools/scaladoc/Scaladoc.scala

+12-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ object Scaladoc:
3535
docsRoot: Option[String] = None,
3636
projectVersion: Option[String] = None,
3737
projectLogo: Option[String] = None,
38+
projectFooter: Option[String] = None,
3839
defaultSyntax: CommentSyntax = CommentSyntax.Markdown,
3940
sourceLinks: List[String] = Nil,
4041
revision: Option[String] = None,
@@ -43,6 +44,10 @@ object Scaladoc:
4344
identifiersToSkip: List[String] = Nil,
4445
regexesToSkip: List[String] = Nil,
4546
rootDocPath: Option[String] = None,
47+
includeAuthors: Boolean = false,
48+
includeGroups: Boolean = false,
49+
includePrivateAPI: Boolean = false,
50+
docCanonicalBaseUrl: String = "",
4651
documentSyntheticTypes: Boolean = false,
4752
)
4853

@@ -94,7 +99,8 @@ object Scaladoc:
9499
)(s => newContext.setSetting(s.asInstanceOf[Setting[T]], newValue))
95100
}
96101

97-
allSettings.filterNot(scaladocSpecificSettings.contains).foreach(setInGlobal)
102+
val commonScalaSettings = (new SettingGroup with CommonScalaSettings).allSettings
103+
allSettings.filter(commonScalaSettings.contains).foreach(setInGlobal)
98104

99105
def parseTastyRoots(roots: String) =
100106
roots.split(File.pathSeparatorChar).toList.map(new File(_))
@@ -162,6 +168,7 @@ object Scaladoc:
162168
siteRoot.nonDefault,
163169
projectVersion.nonDefault,
164170
projectLogo.nonDefault,
171+
projectFooter.nonDefault,
165172
parseSyntax,
166173
sourceLinks.get,
167174
revision.nonDefault,
@@ -170,6 +177,10 @@ object Scaladoc:
170177
skipById.get ++ deprecatedSkipPackages.get,
171178
skipByRegex.get,
172179
docRootContent.nonDefault,
180+
author.get,
181+
groups.get,
182+
visibilityPrivate.get,
183+
docCanonicalBaseUrl.get,
173184
YdocumentSyntheticTypes.get
174185
)
175186
(Some(docArgs), newContext)

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

+35-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ class ScaladocSettings extends SettingGroup with CommonScalaSettings:
2626
sourcepath, sourceroot
2727
)
2828

29+
val projectName: Setting[String] =
30+
StringSetting("-project", "project title", "The name of the project.", "", aliases = List("-doc-title"))
31+
32+
val projectVersion: Setting[String] =
33+
StringSetting("-project-version", "project version", "The current version of your project.", "", aliases = List("-doc-version"))
34+
35+
val projectLogo: Setting[String] =
36+
StringSetting("-project-logo", "project logo filename", "The file that contains the project's logo (in /images).", "", aliases = List("-doc-logo"))
37+
38+
val projectFooter: Setting[String] = StringSetting("-project-footer", "project footer", "A footer on every Scaladoc page.", "", aliases = List("-doc-footer"))
39+
2940
val sourceLinks: Setting[List[String]] =
3041
MultiStringSetting("-source-links", "sources", SourceLinks.usage)
3142

@@ -57,8 +68,29 @@ class ScaladocSettings extends SettingGroup with CommonScalaSettings:
5768
val docRootContent: Setting[String] =
5869
StringSetting("-doc-root-content", "path", "The file from which the root package documentation should be imported.", "")
5970

71+
val author: Setting[Boolean] =
72+
BooleanSetting("-author", "Include authors.", false)
73+
74+
val groups: Setting[Boolean] =
75+
BooleanSetting("-groups", "Group similar functions together (based on the @group annotation)", false)
76+
77+
val visibilityPrivate: Setting[Boolean] =
78+
BooleanSetting("-private", "Show all types and members. Unless specified, show only public and protected types and members.", false)
79+
80+
val docCanonicalBaseUrl: Setting[String] =
81+
StringSetting(
82+
"-doc-canonical-base-url",
83+
"url",
84+
s"A base URL to use as prefix and add `canonical` URLs to all pages. The canonical URL may be used by search engines to choose the URL that you want people to see in search results. If unset no canonical URLs are generated.",
85+
""
86+
)
87+
88+
val siteRoot: Setting[String] = StringSetting(
89+
"-siteroot",
90+
"site root",
91+
"A directory containing static files from which to generate documentation.",
92+
"./docs"
93+
)
94+
6095
val YdocumentSyntheticTypes: Setting[Boolean] =
6196
BooleanSetting("-Ydocument-synthetic-types", "Documents intrinsic types e. g. Any, Nothing. Setting is useful only for stdlib", false)
62-
63-
def scaladocSpecificSettings: Set[Setting[_]] =
64-
Set(sourceLinks, syntax, revision, externalDocumentationMappings, socialLinks, skipById, skipByRegex, deprecatedSkipPackages, docRootContent)

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
131131
meta(charset := "utf-8"),
132132
meta(util.HTML.name := "viewport", content := "width=device-width, initial-scale=1"),
133133
title(page.link.name),
134+
canonicalUrl(absolutePath(page.link.dri)),
134135
link(
135136
rel := "shortcut icon",
136137
`type` := "image/x-icon",
@@ -170,6 +171,14 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
170171
)
171172
renderNested(navigablePage, toplevel = true)._2
172173

174+
private def canonicalUrl(l: String): AppliedTag | String =
175+
val canon = args.docCanonicalBaseUrl
176+
if !canon.isEmpty then
177+
val canonicalUrl = if canon.endsWith("/") then canon else canon + "/"
178+
link(rel := "canonical", href := canonicalUrl + l)
179+
else
180+
"" // return empty tag
181+
173182
private def hasSocialLinks = !args.socialLinks.isEmpty
174183

175184
private def socialLinks(whiteIcon: Boolean = true) =
@@ -194,6 +203,13 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
194203
)).dropRight(1)
195204
div(cls := "breadcrumbs")(innerTags:_*)
196205

206+
def textFooter: String | AppliedTag =
207+
args.projectFooter.fold("") { f =>
208+
div(id := "footer-text")(
209+
raw(f)
210+
)
211+
}
212+
197213
div(id := "container")(
198214
div(id := "leftColumn")(
199215
div(id := "logo")(
@@ -244,7 +260,8 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
244260
cls := "scaladoc_logo"
245261
)
246262
)
263+
),
264+
textFooter
247265
)
248266
)
249267
)
250-
)

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
4646
def opt(name: String, on: Option[DocPart]): Seq[AppliedTag] =
4747
if on.isEmpty then Nil else tableRow(name, renderDocPart(on.get))
4848

49+
def authors(authors: List[DocPart]) = if summon[DocContext].args.includeAuthors then list("Authors", authors) else Nil
50+
4951
m.docs.fold(Nil)(d =>
5052
nested("Type Params", d.typeParams) ++
5153
nested("Value Params", d.valueParams) ++
5254
opt("Returns", d.result) ++
5355
nested("Throws", d.throws) ++
5456
opt("Constructor", d.constructor) ++
55-
list("Authors", d.authors) ++
57+
authors(d.authors) ++
5658
list("See also", d.see) ++
5759
opt("Version", d.version) ++
5860
opt("Since", d.since) ++
@@ -263,7 +265,13 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
263265
Tab("Grouped members", "custom_groups", content, "selected")
264266

265267
def buildMembers(s: Member): AppliedTag =
266-
val (membersInGroups, rest) = s.members.partition(_.docs.exists(_.group.nonEmpty))
268+
def partitionIntoGroups(members: Seq[Member]) =
269+
if summon[DocContext].args.includeGroups then
270+
members.partition(_.docs.exists(_.group.nonEmpty))
271+
else
272+
(Nil, members)
273+
274+
val (membersInGroups, rest) = partitionIntoGroups(s.members)
267275

268276
val extensions =
269277
rest.groupBy{ _.kind match

scaladoc/src/dotty/tools/scaladoc/tasty/SymOps.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ class SymOps[Q <: Quotes](val q: Q) extends JavadocAnchorCreator with Scaladoc2A
8383
Flags.Case -> Modifier.Case,
8484
).collect { case (flag, mod) if sym.flags.is(flag) => mod }
8585

86-
def isHiddenByVisibility: Boolean =
86+
def isHiddenByVisibility(using dctx: DocContext): Boolean =
8787
import VisibilityScope._
8888

89-
getVisibility() match
89+
!summon[DocContext].args.includePrivateAPI && getVisibility().match
9090
case Visibility.Private(_) => true
9191
case Visibility.Protected(ThisScope | ImplicitModuleScope | _: ExplicitModuleScope) => true
9292
case _ => false
9393

94-
def shouldDocumentClasslike: Boolean = !isHiddenByVisibility
94+
def shouldDocumentClasslike(using dctx: DocContext): Boolean = !isHiddenByVisibility
9595
&& !sym.flags.is(Flags.Synthetic)
9696
&& (!sym.flags.is(Flags.Case) || !sym.flags.is(Flags.Enum))
9797
&& !(sym.companionModule.flags.is(Flags.Given))

0 commit comments

Comments
 (0)