Skip to content

Commit c14aa53

Browse files
committed
Add version to docs toolbar
1 parent 4e9f00f commit c14aa53

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,12 @@ class ScalaSettings extends Settings.SettingGroup {
123123
sys.props("user.dir").split(File.separatorChar).last
124124
)
125125

126+
val projectVersion = StringSetting (
127+
"-project-version",
128+
"project version",
129+
"The current version of your project",
130+
""
131+
)
132+
126133
val wikiSyntax = BooleanSetting("-Xwiki-syntax", "Retains the Scala2 behavior of using Wiki Syntax in Scaladoc")
127134
}

doc-tool/resources/_includes/toolbar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
</a>
55
<div id="project-details">
66
<h1 id="project-name">{{ site.project }} Documentation</h1>
7-
<h2 id="project-version">0.1-SNAPSHOT</h2>
7+
<h2 id="project-version">{{ site.version }}</h2>
88
</div>
99
</div>

doc-tool/src/dotty/tools/dottydoc/DocDriver.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ class DocDriver extends Driver {
4545
val reporter = doCompile(newCompiler(ctx), filesToDocument)(ctx)
4646
val siteRoot = new java.io.File(ctx.settings.siteRoot.value)
4747
val projectName = ctx.settings.projectName.value
48+
val projectVersion = ctx.settings.projectVersion.value
4849

4950
if (!siteRoot.exists || !siteRoot.isDirectory)
5051
ctx.error(s"Site root does not exist: $siteRoot")
5152
else {
52-
Site(siteRoot, projectName, ctx.docbase.packages)
53+
Site(siteRoot, projectName, projectVersion, ctx.docbase.packages)
5354
.generateApiDocs()
5455
.copyStaticFiles()
5556
.generateHtmlFiles()

doc-tool/src/dotty/tools/dottydoc/staticsite/DefaultParams.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ case class DefaultParams(
3232
"site" -> Map(
3333
"baseurl" -> site.baseurl,
3434
"posts" -> site.posts.map(_.toMap),
35-
"project" -> site.projectTitle
35+
"project" -> site.projectTitle,
36+
"version" -> site.projectVersion
3637
).asJava,
3738

3839
"sidebar" -> sidebar.titles.asJava
@@ -47,7 +48,7 @@ case class DefaultParams(
4748
}
4849

4950
def withPosts(posts: Array[BlogPost]): DefaultParams =
50-
copy(site = SiteInfo(site.baseurl, site.projectTitle, posts))
51+
copy(site = SiteInfo(site.baseurl, site.projectTitle, site.projectVersion, posts))
5152

5253
def withUrl(url: String): DefaultParams =
5354
copy(page = PageInfo(url))
@@ -61,7 +62,12 @@ case class PageInfo(url: String, date: String = "") {
6162
val path: Array[String] = url.split('/').reverse.drop(1)
6263
}
6364

64-
case class SiteInfo(baseurl: String, projectTitle: String, posts: Array[BlogPost])
65+
case class SiteInfo(
66+
baseurl: String,
67+
projectTitle: String,
68+
projectVersion: String,
69+
posts: Array[BlogPost]
70+
)
6571

6672
case class Sidebar(titles: List[Title])
6773

doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import io.{ AbstractFile, VirtualFile, File }
2828
import scala.collection.mutable.ArrayBuffer
2929
import util.syntax._
3030

31-
case class Site(val root: JFile, val projectTitle: String, val documentation: Map[String, Package]) extends ResourceFinder {
31+
case class Site(val root: JFile, val projectTitle: String, val projectVersion: String, val documentation: Map[String, Package]) extends ResourceFinder {
3232
/** Documentation serialized to java maps */
3333
private val docs: JList[_] = {
3434
import model.JavaConverters._
@@ -157,7 +157,7 @@ case class Site(val root: JFile, val projectTitle: String, val documentation: Ma
157157
"../" * (assetLen - rootLen - 1 + additionalDepth) + "."
158158
}
159159

160-
DefaultParams(docs, documentation, PageInfo(pathFromRoot), SiteInfo(baseUrl, projectTitle, Array()), sidebar)
160+
DefaultParams(docs, documentation, PageInfo(pathFromRoot), SiteInfo(baseUrl, projectTitle, projectVersion, Array()), sidebar)
161161
}
162162

163163
/* Creates output directories if allowed */

project/Build.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ object Build {
282282
val args: Seq[String] = Seq(
283283
"-siteroot", "docs",
284284
"-project", "Dotty",
285+
"-project-version", dottyVersion,
285286
"-classpath", s"$dottyLib:$dottyInterfaces:$otherDeps"
286287
)
287288
(runMain in Compile).toTask(

0 commit comments

Comments
 (0)