Skip to content

Commit 07290ba

Browse files
committed
Update scaladoc front-matters
1 parent 0b03762 commit 07290ba

File tree

9 files changed

+281
-240
lines changed

9 files changed

+281
-240
lines changed

docs/docs/usage/scaladoc/blog.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
---
2+
layout: multipage-overview
23
title: Built-in blog
4+
partof: scala3-scaladoc
5+
num: 5
6+
previous-page: static-site
7+
next-page: site-versioning
38
---
49

5-
# {{page.title}}
6-
710
Scaladoc allows you to include a simple blog in your documentation. For now, it
811
provides only basic features. In the future, we plan to include more advanced
912
features like tagging or author pages.
@@ -22,7 +25,7 @@ All your blogposts must be put under `blog/_posts` directory.
2225
│ └── index.html
2326
```
2427

25-
If you are using yaml [sidebar](./staticSite.html#sidebar) don't forget to place
28+
If you are using yaml [sidebar](./static-site.html#sidebar) don't forget to place
2629

2730
```
2831
sidebar:

docs/docs/usage/scaladoc/scaladocDocstrings.md renamed to docs/docs/usage/scaladoc/docstrings.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
---
2-
title: Scaladoc docstrings - specific Tags and Features
2+
layout: multipage-overview
3+
title: Docstrings - specific Tags and Features
4+
partof: scala3-scaladoc
5+
num: 2
6+
previous-page: index
7+
next-page: linking
38
---
49

5-
# {{page.title}}
6-
710
This chapter describes how to correctly write docstrings and how to use all the available features of scaladoc.
811
Since many things are the same as in the old scaladoc, some parts are reused from this [article](https://docs.scala-lang.org/overviews/scaladoc/for-library-authors.html)
912

@@ -192,4 +195,4 @@ Further information on the formatting and style recommendations can be found in
192195
193196
Scaladoc allows linking to API documentation with Wiki-style links. Linking to
194197
`scala.collection.immutable.List` is as simple as
195-
`[[scala.collection.immutable.List]]`. For more information on the exact syntax, see [doc comment documentation](./linkingDocumentation.html#definition-links).
198+
`[[scala.collection.immutable.List]]`. For more information on the exact syntax, see [doc comment documentation]({% link _overviews/scala3-scaladoc/linking.md %}#definition-links).

docs/docs/usage/scaladoc/index.md

+7-22
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
---
2-
title: scaladoc
2+
layout: multipage-overview
3+
title: Scaladoc
4+
partof: scala3-scaladoc
5+
num: 1
6+
next-page: docstrings
37
---
48

5-
![scaladoc logo](/images/scaladoc-logo.png)
9+
![scaladoc logo]({{ site.baseurl }}/resources/images/scala3/scaladoc/logo.svg)
610

7-
scaladoc is a tool to generate documentation for your Scala 3 projects. It provides similar features to `javadoc` as well as `jekyll` or `docusaurus`.
8-
9-
As you probably have guessed, this whole site was created using scaladoc.
10-
11-
12-
{% for post in site.posts %}
13-
## [{{ post.title }}](/{{ post.url }})
14-
15-
{{ post.excerpt }}
16-
17-
[ (read more) ](/{{ post.url }})
18-
19-
{% endfor %}
20-
21-
## Other extensions
22-
23-
We would love to have your feedback on what you think would be good in order to
24-
render the documentation you want! Perhaps you would like to render method
25-
definitions or members? Do you want to have runnable code snippets? Let us know
26-
by filing [issues](https://github.com/lampepfl/dotty/issues/new)!
11+
scaladoc is a tool to generate the API documentation of your Scala 3 projects. It provides similar features to `javadoc` as well as `jekyll` or `docusaurus`.

docs/docs/usage/scaladoc/linkingDocumentation.md renamed to docs/docs/usage/scaladoc/linking.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
---
2+
layout: multipage-overview
23
title: Linking documentation
4+
partof: scala3-scaladoc
5+
num: 3
6+
previous-page: docstrings
7+
next-page: static-site
38
---
49

5-
# {{ page.title }}
6-
710
Scaladoc's main feature is creating API documentation from code comments.
811

912
By default, the code comments are understood as Markdown, though we also support
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
layout: multipage-overview
3+
title: Type-based search
4+
partof: scala3-scaladoc
5+
num: 7
6+
previous-page: site-versioning
7+
next-page: settings
8+
---
9+
10+
Searching for functions by their symbolic names can be time-consuming.
11+
That is why the new scaladoc allows searching for methods and fields by their types.
12+
13+
14+
Consider the following extension method definition:
15+
```
16+
extension [T](arr: IArray[T]) def span(p: T => Boolean): (IArray[T], IArray[T]) = ...
17+
```
18+
Instead of searching for `span` we can also search for `IArray[A] => (A => Boolean) => (IArray[A], IArray[A])`.
19+
20+
To use this feature, type the signature of the member you are looking for in the scaladoc searchbar. This is how it works:
21+
22+
![]({{ site.baseurl }}/resources/images/scala3/scaladoc/inkuire-1.0.0-M2_js_flatMap.gif)
23+
24+
This feature is provided by the [Inkuire](https://github.com/VirtusLab/Inkuire) search engine, which works for Scala 3 and Kotlin. To be up-to-date with the development of this feature, follow the [Inkuire repository](https://github.com/VirtusLab/Inkuire).
25+
26+
## Examples of queries
27+
28+
Some examples of queries with intended results:
29+
- `List[Int] => (Int => Long) => List[Long]` -> `map`
30+
- `Seq[A] => (A => B) => Seq[B]` -> `map`
31+
- `(A, B) => A` -> `_1`
32+
- `Set[Long] => Long => Boolean` -> `contains`
33+
- `Int => Long => Int` -> `const`
34+
- `String => Int => Char` -> `apply`
35+
- `(Int & Float) => (String | Double)` -> `toDouble`, `toString`
36+
- `F[A] => Int` -> `length`
37+
38+
## Query syntax
39+
40+
In order for a scaladoc searchbar query to be searched using Inkuire instead of the default search engine, the query has to contain the `=>` character sequence.
41+
42+
Accepted input is similar to a curried function signature in Scala 3. With some differences:
43+
- AndTypes, OrTypes and Functions have to be enclosed in parentheses e.g. `(Int & Any) => String`
44+
- fields and parameterless methods can be found by preceding their type with `=>`, e.g., `=> Int`
45+
- A wildcard `_` can be used to indicate that we want to match any type in a given place e.g. `Long => Double => _`
46+
- Types in the form of single letter e.g. `A` or a letter with a digit `X1` are automatically assumed to be type variables
47+
- Other type variables can be declared just like in polymorphic functions e.g. `[AVariable, AlsoAVariable] => AVariable => AlsoAVariable => AVariable`
48+
49+
### Working with type aliases and method receivers
50+
51+
When it comes to how the code is mapped to InkuireDb entries, there are some transformations to make the engine more opinionated (though open to suggestions and changes). Firstly, the receiver (non-module owner) of a function can be treated as a first argument. Automatic currying is also applied, so that the results don't depend on argument lists. When finding matches, `val`s and `def`s are not distinguished.
52+
53+
So the following declarations should be found by query `Num => Int => Int => Int`:
54+
```
55+
class Num():
56+
def a(i: Int, j: Int): Int
57+
def b(i: Int)(j: Int): Int
58+
def c(i: Int): (Int => Int)
59+
val d: Int => Int => Int
60+
val e: Int => Int => Int
61+
val f: (Int, Int) => Int
62+
end Num
63+
64+
def g(i: Num, j: Int, k: Int): Int
65+
extension (i: Num) def h(j: Int, k: Int): Int
66+
def i(i: Num, j: Int)(k: Int): Int
67+
extension (i: Num) def j(j: Int)(k: Int): Int
68+
...
69+
```
70+
71+
When it comes to type aliases, they are desugared on both the declaration and the query signature. This means that for declarations:
72+
```
73+
type Name = String
74+
75+
def fromName(name: Name): String
76+
def fromString(str: String): Name
77+
```
78+
both methods, `fromName` and `fromString`, should be found for queries `Name => Name`, `String => String`, `Name => String` and `String => Name`.
79+
80+
## How it works
81+
82+
Inkuire works as a JavaScript worker in the browser thanks to the power of [ScalaJS](https://www.scala-js.org/).
83+
84+
To enable Inkuire when running scaladoc, add the flag `-Ygenerate-inkuire`. By adding this flag two files are generated:
85+
- `inkuire-db.json` - this is the file containing all the searchable declarations from the currently documented project in a format readable to the Inkuire search engine.
86+
- `inkuire-config.json` - this file contains the locations of the database files that should be searchable from the documentation of the current project. By default, it will be generated with the location of the local db file as well as the default implied locations of database files in [External mappings](/scala3/guides/scaladoc/settings.html#-external-mappings).

docs/docs/usage/scaladoc/settings.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
2-
title: Scaladoc settings
2+
layout: multipage-overview
3+
title: Settings
4+
partof: scala3-scaladoc
5+
num: 8
6+
previous-page: search-engine
37
---
48

5-
# {{page.title}}
6-
79
This chapter lists the configuration options that can be used when calling scaladoc. Some of the information shown here can be found by calling scaladoc with the `-help` flag.
810

911
## Parity with scaladoc for Scala 2
@@ -77,7 +79,7 @@ In such case paths used in templates will be relativized against `<sub-path>`
7779
Mapping between regexes matching classpath entries and external documentation.
7880

7981
Example external mapping is:
80-
`-external-mappings:.*scala.*::scaladoc3::http://dotty.epfl.ch/api/,.*java.*::javadoc::https://docs.oracle.com/javase/8/docs/api/`
82+
`-external-mappings:.*scala.*::scaladoc3::https://scala-lang.org/api/3.x/,.*java.*::javadoc::https://docs.oracle.com/javase/8/docs/api/`
8183

8284
A mapping is of the form '\<regex>::\[scaladoc3|scaladoc|javadoc]::\<path>'. You can supply several mappings, separated by commas, as shown in the example.
8385

docs/docs/usage/scaladoc/site-versioning.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
---
2+
layout: multipage-overview
23
title: Site versioning
4+
partof: scala3-scaladoc
5+
num: 6
6+
previous-page: blog
7+
next-page: search-engine
38
---
49

5-
# {{ page.title }}
6-
710
Scaladoc provides a convenient way to switch between different versions of the documentation. The feature is useful if we want to expose older docs for users that didn't migrate to the new version of our library.
811

912
### How to setup it
@@ -33,4 +36,4 @@ doc / scalacOptions ++= Seq("-versions-dictionary-url", "https://dotty.epfl.ch/v
3336

3437
Providing a JSON file via `-versions-dictionary-url` enables scaladoc to link between versions. It is also convenient to be able to change the revision label in the drop-down menu. Everything will change automatically.
3538

36-
![](images/scaladoc/nightly.gif)
39+
![]({{ site.baseurl }}/resources/images/scala3/scaladoc/nightly.gif)
+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
---
2+
layout: multipage-overview
3+
title: Static documentation
4+
partof: scala3-scaladoc
5+
num: 4
6+
previous-page: linking
7+
next-page: blog
8+
---
9+
10+
Scaladoc is able to generate static sites, known from [Jekyll](http://jekyllrb.com/) or [Docusaurus](https://docusaurus.io/).
11+
Having a combined tool allows to provide interaction between static documentation and API, thus allowing the two to blend naturally.
12+
13+
Creating a site is just as simple as in Jekyll. The site root contains the
14+
layout of the site and all files placed there will be either considered static,
15+
or processed for template expansion.
16+
17+
The files that are considered for template expansion must end in `*.{html,md}`
18+
and will from here on be referred to as "template files" or "templates".
19+
20+
A simple "hello world" site could look something like this:
21+
22+
```
23+
├── docs
24+
│ └── getting-started.md
25+
└── index.html
26+
```
27+
28+
This will give you a site with the following files in generated documentation:
29+
30+
```
31+
index.html
32+
docs/getting-started.html
33+
```
34+
35+
Scaladoc can transform both files and directories (to organize your documentation into tree-like structure). By default directories has title based on file name and has empty content. There is an option to include `index.html` or `index.md` (not both) to provide both content and properties like title (see [Properties](#properties)).
36+
37+
## Properties
38+
39+
Scaladoc uses the [Liquid](https://shopify.github.io/liquid/) templating engine
40+
and provides a number of custom filters and tags specific to Scala
41+
documentation.
42+
43+
In Scaladoc, all templates can contain YAML front-matter. The front-matter
44+
is parsed and put into the `page` variable available in templates via Liquid.
45+
46+
Scaladoc uses some predefined properties to controls some aspect of page.
47+
48+
Predefined properties:
49+
50+
- **title** provide page title that will be used in navigation and html metadata.
51+
- **extraCss** additional `.css` files that will be included in this page. Paths should be relative to documentation root. **This setting is not exported to template engine.**
52+
- **extraJs** additional `.js` files that will be included in this page. Paths should be relative to documentation root. **This setting is not exported to template engine.**
53+
- **hasFrame** when set to `false` page will not include default layout (navigation, breadcrumbs etc.) but only token html wrapper to provide metadata and resources (js and css files). **This setting is not exported to template engine.**
54+
- **layout** - predefined layout to use, see below. **This setting is not exported to template engine.**
55+
56+
57+
## Using existing Templates and Layouts
58+
59+
To perform template expansion, Dottydoc looks at the `layout` field in the front-matter.
60+
Here's a simple example of the templating system in action, `index.html`:
61+
62+
```html
63+
---
64+
layout: main
65+
---
66+
67+
<h1>Hello world!</h1>
68+
```
69+
70+
With a simple main template like this:
71+
72+
{% raw %}
73+
```html
74+
<html>
75+
<head>
76+
<title>Hello, world!</title>
77+
</head>
78+
<body>
79+
{{ content }}
80+
</body>
81+
</html>
82+
```
83+
84+
Would result in `{{ content }}` being replaced by `<h1>Hello world!</h1>` from
85+
the `index.html` file.
86+
{% endraw %}
87+
88+
Layouts must be placed in a `_layouts` directory in the site root:
89+
90+
```
91+
├── _layouts
92+
│ └── main.html
93+
├── docs
94+
│ └── getting-started.md
95+
└── index.html
96+
```
97+
98+
## Sidebar
99+
100+
Scaladoc by default uses layout of files in `docs` directory to create table of content. There is also ability to override it by providing a `sidebar.yml` file in the site root:
101+
102+
```yaml
103+
sidebar:
104+
- title: Blog
105+
- title: Docs
106+
url: docs/index.html
107+
- title: Usage
108+
subsection:
109+
- title: Dottydoc
110+
url: docs/usage/dottydoc.html
111+
- title: sbt-projects
112+
url: docs/usage/sbt-projects.html
113+
```
114+
115+
The `sidebar` key is mandatory, as well as `title` for each element. The
116+
default table of contents allows you to have subsections - albeit the current
117+
depth limit is 2 however it accepts both files and directories and latter can be used to provide deeper structures.
118+
119+
The items must provide either `subsection` or `url` but not both at once!
120+
The only exception is `Blog` which is only a `title` and behaves differently.
121+
You can read more about blog [here]({% link _overviews/scala3-scaladoc/blog.md %}).
122+
123+
```
124+
├── blog
125+
│ ├── _posts
126+
│ │ └── 2016-12-05-implicit-function-types.md
127+
│ └── index.html
128+
├── index.html
129+
└── sidebar.yml
130+
```
131+
132+
## Static resources
133+
134+
You can attach static resources (pdf, images) to your documentation by using two dedicated directories:
135+
`resources` and `images`. When you upload your assests under any of these directories you can reference them in markdown
136+
as if they were relatively at the same level.
137+
138+
For example, consider the following situation:
139+
140+
```
141+
├── blog
142+
│ ├── _posts
143+
│ │ └── 2016-12-05-implicit-function-types.md
144+
│ └── index.html
145+
├── index.html
146+
├── resources
147+
│ └── my_file.pdf
148+
├── images
149+
│ └── my_image.png
150+
└── sidebar.yml
151+
152+
```
153+
154+
You can refer to the assets from within any of the files using markdown links:
155+
156+
```
157+
This is my blogpost. Here is the image ![](my_image.png) and here is my [pdf](my_file.pdf)
158+
```

0 commit comments

Comments
 (0)