Skip to content

Commit 757b32b

Browse files
committed
Merge pull request scala#420 from felixmulder/topic/blog-getting-into-scaladoc
Add "Getting into Scaladoc Development" blog post
2 parents e6d28b3 + 72df5d6 commit 757b32b

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
layout: blog
3+
post-type: blog
4+
by: Felix Mulder
5+
title: Getting into Scaladoc Development
6+
disqus: true
7+
---
8+
9+
Over the past months I've been working on the new Scaladoc - and it's coming
10+
along nicely. Together with
11+
[@heathercmiller](http://twitter.com/heathercmiller) and
12+
[@vladureche](http://twitter.com/vladureche) we've overhauled the overall look
13+
of Scaladoc as well as having added a bunch of useful features - like complete
14+
member search!
15+
16+
With the new Scala Center recently announced, one of the things discussed has
17+
been how to lower the entry barrier on important open source projects. This blog
18+
post aims to do exactly that for Scaladoc. There are a lot of things we want
19+
to do with the docs - and we'd love help! If that piques your interest - read on.
20+
21+
## Scaladoc for 2.12.x ##
22+
The new major version of Scala is scheduled for later this year, and currently
23+
its doc tool generates sites like this one:
24+
25+
![Scala Collections](http://i.imgur.com/TOkD4JF.png)
26+
27+
The new search functionality allows you to not only look for so called
28+
"top-level entities" (`class`, `trait`, `object` and `package`) but members like
29+
methods and even `val` and `var`s. The new search is not at all taxing, on a
30+
big library like the collections - the results are shown almost
31+
instantaneously. Nevertheless, we've got a progress bar showing you something's
32+
actually happening:
33+
34+
![Scala Collections](http://imgur.com/jLxcRpx.png)
35+
36+
## How does Scaladoc work? ##
37+
The Scaladoc tool is quite easy to understand - there are basically three things
38+
that happen once you've specified what you want documented:
39+
40+
1. Scaladoc compiles the sources using the first step of the compiler (the
41+
frontend). This will fill a tree structure known as `Universe` with all the
42+
information about the sources (classes, members, doc string etc).
43+
44+
**See:** [DocFactory.scala](https://github.com/scala/scala/blob/2.12.x/src/scaladoc/scala/tools/nsc/doc/DocFactory.scala)
45+
46+
2. Copy all needed assets to out location (i.e. scripts and CSS-files)
47+
48+
**See:** [HtmlFactory.scala](https://github.com/scala/scala/blob/2.12.x/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala).
49+
50+
3. Traverse the `Universe` tree and for each top-level entity create an
51+
HTML-page using the `Entity` class.
52+
53+
**See:** [Entity.scala](https://github.com/scala/scala/blob/2.12.x/src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala)
54+
55+
The bulk of these steps are carried out inside the `HtmlFactory` class in
56+
[HtmlFactory.scala](https://github.com/scala/scala/blob/2.12.x/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala).
57+
Have a look there for a more complete overview.
58+
59+
## How do I generate the docs? ##
60+
61+
Simple:
62+
63+
```bash
64+
$ git clone [email protected]:scala/scala.git && cd scala
65+
$ ant docs # "ant docs.lib" if you just want the standard library
66+
```
67+
68+
## Where to begin ##
69+
70+
The markup of the entity page is defined in
71+
[Entity.scala](https://github.com/scala/scala/blob/2.12.x/src/scaladoc/scala/tools/nsc/doc/html/page/Entity.scala).
72+
If you're looking to change the HTML that's where you will want to look first.
73+
74+
If you want to add some static asset, remember that `HtmlFactory` needs to copy
75+
it to the destination. So be sure to add your new resource to `libResources` in
76+
[HtmlFactory.scala](https://github.com/scala/scala/blob/2.12.x/src/scaladoc/scala/tools/nsc/doc/html/HtmlFactory.scala).
77+
78+
All the current static assets are located in the
79+
[lib](https://github.com/scala/scala/tree/2.12.x/src/scaladoc/scala/tools/nsc/doc/html/resource/lib) directory.
80+
That's where you'd want to put new things (it is also where `index.js` etc live!)
81+
82+
**How can I see my changes?** You have two options, if you changed the markup -
83+
you'll need to regenerate the docs:
84+
85+
```bash
86+
$ ant docs.clean && ant docs
87+
```
88+
89+
When the changes are to scripts or style sheets I use a small `Makefile` in the
90+
root of the project. This makefile will simply copy the resources to the same location
91+
as the generated docs:
92+
93+
```make
94+
all:
95+
cp src/scaladoc/scala/tools/nsc/doc/html/resource/lib/{index.css,index.js,template.css,template.js,diagrams.css,diagrams.js} build/scaladoc/library/lib/
96+
```
97+
98+
Regenerating the docs all the time is a pain - if you just want to generate
99+
them for a single file, do this:
100+
101+
```bash
102+
$ ant quick.bin
103+
$ build/quick/bin/scaladoc path/to/source/File.scala
104+
```
105+
106+
Lastly, before you open your pull request - test your changes!
107+
108+
```bash
109+
$ ant test.scaladoc
110+
```
111+
112+
## Where to really begin ##
113+
114+
There's still a lot of things to do before this can be considered release ready.
115+
Here's a laundry list of things we need to do:
116+
117+
* General
118+
- Async all the things! We should be able to parallelize the generation of
119+
the doc pages
120+
- CSS cleanup! There are a lot of things not necessary anymore, these could
121+
simply be deleted
122+
* Mobile, the docs look decent on mobile - but there's still a ton to do!
123+
- Landscape kills some of our layout
124+
- There is no good package overview (list on the right) - ideas welcome!
125+
* Desktop
126+
- Keyboard navigation on entity pages (i.e. between members)
127+
- Better keyboard navigation on search results
128+
- Minor layout issues
129+
- Showing existence of companion `class`/`trait`/`object` (maybe *"You
130+
won't believe who* `Companion object Boolean` *is going home with
131+
tonight!"*)
132+
133+
The full list of ideas and things to do can be found on
134+
[scala-dev](https://github.com/scala/scala-dev/issues/84). Comment on the issue
135+
or reach out to one of us (@felixmulder, @heathermiller, @vladureche) on the
136+
[scala/contributors gitter](https://gitter.im/scala/contributors) if you're
137+
interested in knowing more!

0 commit comments

Comments
 (0)