Skip to content

Commit 9366528

Browse files
authored
Merge pull request #2608 from dotty-staging/topic/add-toc
Add include for rendering sidebar in docs
2 parents 465b320 + 939e9aa commit 9366528

File tree

6 files changed

+61
-22
lines changed

6 files changed

+61
-22
lines changed

doc-tool/resources/_includes/sidebar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="index-wrapper" style="top: {{ sidebarTop }};">
22
<ul class="toc">
33
{% assign parent = page.path | first %}
4-
{% for title in sidebar %}
4+
{% for title in sidebar.titles %}
55
<li>{% renderTitle title, parent %}</li>
66
{% endfor %}
77
</ul>

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

+21-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ case class DefaultParams(
4343
"root" -> site.root
4444
).asJava,
4545

46-
"sidebar" -> sidebar.titles.asJava
46+
"sidebar" -> sidebar.toMap
4747
)
4848
val entityMap = entity match {
4949
case NonEntity => Map.empty
@@ -79,7 +79,11 @@ case class SiteInfo(
7979
root: String
8080
)
8181

82-
case class Sidebar(titles: List[Title])
82+
case class Sidebar(titles: List[Title]) {
83+
import model.JavaConverters._
84+
def toMap: JMap[String, _] =
85+
Map("titles" -> titles.map(_.toMap).asJava).asJava
86+
}
8387

8488
object Sidebar {
8589
def apply(map: HashMap[String, AnyRef]): Option[Sidebar] = Option(map.get("sidebar")).map {
@@ -91,7 +95,15 @@ object Sidebar {
9195
def empty: Sidebar = Sidebar(Nil)
9296
}
9397

94-
case class Title(title: String, url: Option[String], subsection: List[Title])
98+
case class Title(title: String, url: Option[String], subsection: List[Title], description: Option[String]) {
99+
import model.JavaConverters._
100+
def toMap: JMap[String, _] = Map(
101+
"title" -> title,
102+
"url" -> url.getOrElse(null), // ugh, Java
103+
"subsection" -> subsection.map(_.toMap).asJava,
104+
"description" -> description.getOrElse(null)
105+
).asJava
106+
}
95107

96108
object Title {
97109
def apply(map: JMap[String, AnyRef]): Option[Title] = {
@@ -101,13 +113,18 @@ object Title {
101113
val url = Option(map.get("url")).collect {
102114
case s: String => s
103115
}
116+
117+
val description = Option(map.get("description")).collect {
118+
case s: String => s
119+
}
120+
104121
val subsection = Option(map.get("subsection")).collect {
105122
case xs: JList[JMap[String, AnyRef]] @unchecked =>
106123
xs.asScala.map(Title.apply).toList.flatMap(x => x)
107124
}.getOrElse(Nil)
108125

109126
title.map {
110-
case title: String => Title(title, url, subsection)
127+
case title: String => Title(title, url, subsection, description)
111128
}
112129
}
113130
}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ object tags {
184184

185185
override def render(ctx: TemplateContext, nodes: LNode*): AnyRef =
186186
(nodes(0).render(ctx), nodes(1).render(ctx)) match {
187-
case (t: Title, parent: String) => renderTitle(t, parent)
188-
case (t: Title, _) => renderTitle(t, "./") // file is in top dir
187+
case (map: JMap[String, AnyRef] @unchecked, parent: String) =>
188+
Title(map).map(renderTitle(_, parent)).getOrElse(null)
189+
case (map: JMap[String, AnyRef] @unchecked, _) =>
190+
Title(map).map(renderTitle(_, "./")).getOrElse(null) // file is in top dir
189191
case _ => null
190192
}
191193
}

docs/_includes/table-of-contents.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<ul>
2+
{% for item in titles %}
3+
<li>
4+
{% if item.url %}
5+
<a href="{{ site.baseurl }}/{{ item.url }}">{{ item.title }}</a>
6+
{% else %}
7+
{{ item.title }}
8+
{% endif %}
9+
{% if item.subsection %}
10+
{% assign titles = item.subsection %}
11+
{% include "table-of-contents" %}
12+
{% endif %}
13+
</li>
14+
{% endfor %}
15+
</ul>

docs/docs/index.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ layout: doc-page
33
title: "Dotty Documentation"
44
---
55

6-
Dotty is a platform to try out new language concepts and compiler technologies for Scala.
7-
The focus is mainly on simplification. We remove extraneous syntax (e.g. no XML literals),
8-
and try to boil down Scala’s types into a smaller set of more fundamental constructors.
6+
Dotty is a platform to try out new language concepts and compiler technologies for Scala.
7+
The focus is mainly on simplification. We remove extraneous syntax (e.g. no XML literals),
8+
and try to boil down Scala’s types into a smaller set of more fundamental constructors.
99
The theory behind these constructors is researched in DOT, a calculus for dependent object types.
1010

1111
In this documentation you will find information on how to use the Dotty compiler on your machine, navigate through
1212
the code, setup Dotty with your favorite IDE and more!
13+
14+
Table of Contents
15+
=================
16+
{% assign titles = sidebar.titles %}
17+
{% include "table-of-contents" %}

docs/sidebar.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
sidebar:
22
- title: Blog
33
url: blog/index.html
4+
- title: Usage
5+
subsection:
6+
- title: sbt-projects
7+
url: docs/usage/sbt-projects.html
8+
- title: IDE support for Dotty
9+
url: docs/usage/ide-support.html
10+
- title: cbt-projects
11+
url: docs/usage/cbt-projects.html
12+
- title: Dottydoc
13+
url: docs/usage/dottydoc.html
14+
- title: Migrating
15+
url: docs/usage/migrating.html
416
- title: Reference
517
subsection:
618
- title: New Types
@@ -71,18 +83,6 @@ sidebar:
7183
url: docs/reference/dropped/limit22.html
7284
- title: XML literals
7385
url: docs/reference/dropped/xml.html
74-
- title: Usage
75-
subsection:
76-
- title: sbt-projects
77-
url: docs/usage/sbt-projects.html
78-
- title: IDE support for Dotty
79-
url: docs/usage/ide-support.html
80-
- title: cbt-projects
81-
url: docs/usage/cbt-projects.html
82-
- title: Dottydoc
83-
url: docs/usage/dottydoc.html
84-
- title: Migrating
85-
url: docs/usage/migrating.html
8686
- title: Contributing
8787
subsection:
8888
- title: Getting Started

0 commit comments

Comments
 (0)