-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enhancements to ScalaDoc: New Features Implemented #21436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 19 commits
8fc1f15
feac040
89d11f9
b2eab74
5351239
5fa510a
44e670e
907584b
f25ab16
c5b5450
76247e9
44548bb
b8b94ab
8ddd55f
942b643
ecf9265
7ce1ed2
2d1818f
9b15ebd
1fd197d
798b9ac
6222ab2
bb9b8c0
f9c1c1f
0cab089
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version = "3.7.15" | ||
runner.dialect = scala213 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be moved to a page within the "internals" section https://dotty.epfl.ch/docs/internals/index.html |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
--- | ||
layout: doc-page | ||
title: Scaladoc | ||
partof: scaladoc | ||
overview-name: Scaladoc | ||
num: 1 | ||
|
||
--- | ||
|
||
|
||
# Custom Template Tags Documentation | ||
|
||
|
||
## 1. Language Picker Tag | ||
|
||
The language_picker tag is a custom tag used to render a language selection dropdown on a page. This tag allows users to switch between different language versions of the content. The available languages are determined based on the configuration and the frontmatter of the page. | ||
|
||
### Prequisites: | ||
- #### Configuration in config.yaml: | ||
The available languages must be defined in the `config.yaml` file under the languages section. Each language should have a corresponding code and name. | ||
Example: | ||
```yaml | ||
languages: | ||
- code: en | ||
name: English | ||
- code: ja | ||
name: Japanese | ||
``` | ||
- #### Language Folders in `_docs`: | ||
For each language code specified in config.yaml, there should be a corresponding folder in the _docs directory. These folders contain the translated content for each language. | ||
Example: | ||
``` | ||
_docs/ | ||
├── en/ | ||
├── ja/ | ||
|
||
``` | ||
- #### Frontmatter in the page: | ||
Each page should have a `languages` key in its frontmatter that lists the available languages for that page. This ensures that the language picker dropdown is rendered with the correct options. | ||
|
||
Example: | ||
```yaml | ||
--- | ||
title: Getting Started | ||
languages: ['en', 'ja'] | ||
--- | ||
``` | ||
|
||
### Usage: | ||
|
||
```html | ||
<div class="language-picker-container"> | ||
{ % if page.languages % } | ||
{ % language_picker languages=page.languages % } | ||
{ % endif %} | ||
</div> | ||
``` | ||
|
||
### Considerations | ||
|
||
- Empty Language List: If the languages list in the frontmatter is empty, the language_picker tag will not render anything. | ||
- Default Language: If the selected language is en, the language code will be removed from the URL, treating it as the default language. | ||
- Folder Structure: Ensure that the corresponding language folders exist in the _docs directory; otherwise, the language switch will lead to broken links. | ||
|
||
|
||
|
||
## 1. Include Tag | ||
|
||
### Purpose: | ||
The `{ % include % }` tag is used to include content from other files or templates within your page. This helps in reusing common elements across multiple pages, such as headers, footers, or any other repeated content. | ||
|
||
### Usage: | ||
```html | ||
{ % include 'filename' variable1='value1' variable2='value2' % } | ||
``` | ||
|
||
|
||
### Example: | ||
```html | ||
{ % include 'header.html' title='Welcome to My Website' % } | ||
``` | ||
|
||
### How it Works: | ||
- File Inclusion: The tag includes the specified file from a predefined folder. | ||
- Passing Variables: You can pass variables when including a file, which can be accessed within the included file using the syntax {{ include.variable1 }}. | ||
- Accessing Variables: Inside the included file, the passed variables can be accessed like regular variables, allowing dynamic content based on the context of inclusion. | ||
|
||
|
||
|
||
## 2. Tabs Block | ||
|
||
### Purpose: | ||
The { % tabs % } block is used to group content into tabs, allowing users to switch between different content sections without reloading the page. This is useful for organizing content that has multiple views, like installation instructions for different platforms. | ||
|
||
### Usage: | ||
```html | ||
{ % tabs unique-tabs-id class='additional-class' % } | ||
{ % tab 'Tab 1' for='unique-tabs-id' % } | ||
<!-- Content for Tab 1 --> | ||
{ % endtab % } | ||
|
||
{ % tab 'Tab 2' for='unique-tabs-id' % } | ||
<!-- Content for Tab 2 --> | ||
{ % endtab % } | ||
|
||
{ % endtabs % } | ||
``` | ||
|
||
### Example: | ||
|
||
```html | ||
{ % tabs install-instructions % } | ||
{ % tab 'Windows' for='install-instructions' % } | ||
|
||
{ % endtab % } | ||
|
||
{ % tab 'macOS' for='install-instructions' % } | ||
|
||
{ % endtab % } | ||
|
||
{ % endtabs % } | ||
``` | ||
|
||
How it Works: | ||
- Tabs Block: The { % tabs % } tag creates a container for multiple tabs. | ||
- Tab Content: Each { % tab % } tag defines the content of a single tab. The for attribute must match the id specified in the { % tabs % } block to correctly link the tab content. | ||
- Default Tab: You can specify a default tab by using the defaultTab keyword in the { % tab % } tag. | ||
- Styling: You can apply additional CSS classes to the tabs by specifying the class attribute | ||
|
||
|
||
## 2. AltDetails Block | ||
|
||
### Purpose: | ||
The { % altDetails % } tag is used to create switchable sections, often referred to as tabs. This is useful for including optional or advanced information that doesn’t need to be visible by default. | ||
|
||
### Usage: | ||
|
||
```html | ||
{ % altDetails 'unique-id' 'Title of the Section' % } | ||
<!-- Content inside the dropdown --> | ||
{ % endaltDetails %} | ||
|
||
``` | ||
|
||
### How it Works: | ||
|
||
- Collapsible Section: The { % altDetails % } tag creates a section that can be expanded or collapsed by the user. | ||
- Title and ID: The first argument is a unique identifier for the section, and the second argument is the title displayed when the section is collapsed. | ||
- Content: Any content placed within the { % altDetails % } and { % endaltDetails % } tags is hidden by default and can be revealed by clicking on the title. | ||
|
||
|
||
# `_data` Folder | ||
|
||
The _data folder in your project is used to store YAML, JSON, or CSV files that contain structured data. These files can then be accessed throughout your site using the site.data variable. This is particularly useful for storing site-wide information, such as navigation menus, reusable content blocks, or any other structured data that needs to be referenced across multiple pages. | ||
|
||
### Structure and Access | ||
- Folder Location: The _data folder should be located in the root directory of your project. | ||
|
||
- File Formats: The _data folder supports .yml, .yaml, .json, and .csv file formats. Each file represents a collection of data that can be accessed using the site.data variable. | ||
|
||
- Accessing Data: | ||
- The data within a YAML file can be accessed using `site.data.<file_name>.<key>.` | ||
- Replace `<file_name>` with the name of the file (without the extension), and `<key>` with the specific key within the file. | ||
|
||
### Example | ||
|
||
Suppose you have a YAML file `_data/navigation.yml` with the following content: | ||
|
||
```yaml | ||
main_menu: | ||
- name: Home | ||
url: / | ||
- name: About | ||
url: /about/ | ||
- name: Contact | ||
url: /contact/ | ||
``` | ||
|
||
You can access the data in this file using the following syntax: | ||
|
||
```html | ||
<ul> | ||
{ % for item in site.data.navigation.main_menu % } | ||
<li><a href="{ { item.url } }">{ { item.name } }</a></li> | ||
{ % endfor % } | ||
</ul> | ||
``` | ||
|
||
### Considerations | ||
- File Naming: Make sure the file names are unique to avoid conflicts when accessing data. | ||
- Data Structure: Keep the data structure consistent across different files to avoid confusion when accessing data in your templates. | ||
|
||
<aside class="info"> | ||
<div class='icon'></div> | ||
<div class='content'> | ||
It is preferred to avoid using hyphens in naming conventions. When using LIQP tags, hyphens can be misinterpreted as minus signs, leading to unexpected errors. | ||
<br/> | ||
{ { site.data.example['key-with-hyphen'] } } | ||
|
||
</div> | ||
</aside> | ||
|
||
|
||
|
||
|
||
|
||
# Configuration File | ||
|
||
The `_config.yaml` file is a central configuration file located in the root directory of your project. It is used to define site-wide settings and variables that can be accessed throughout your site using the `site` variable. | ||
|
||
### Structure and Access | ||
|
||
- File Location: The _config.yaml file should be placed in the root directory of your project. | ||
|
||
- YAML Structure: The file uses YAML syntax to define configuration options. You can define any key-value pairs in this file, and they will be accessible via the site.config.`<key>` variable in your templates. | ||
|
||
- Accessing Configuration: | ||
- Any configuration setting defined in _config.yaml can be accessed using site.`<key>`. | ||
- For example, if you define a key title: My Website, you can access it using site.title. | ||
|
||
### Example | ||
If your _config.yaml includes: | ||
```yaml | ||
site_name: My Awesome Site | ||
description: A description of my awesome site. | ||
``` | ||
You can access these values in your templates: | ||
```html | ||
{ { site.config.site_name } } <!-- Outputs: My Awesome Site --> | ||
``` | ||
|
||
|
||
|
||
<aside class="info"> | ||
<div class='icon'></div> | ||
<div class='content'> | ||
It is preferred to avoid using hyphens in naming conventions. When using LIQP tags, hyphens can be misinterpreted as minus signs, leading to unexpected errors. | ||
<br/> | ||
{ { site.data.example['key-with-hyphen'] } } | ||
</div> | ||
</aside> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
|
||
|
||
bishabosha marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
package dotty.tools.scaladoc | ||
package site | ||
|
||
import java.io.File | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
|
||
import org.jsoup.Jsoup | ||
import scala.jdk.CollectionConverters._ | ||
|
||
case class LazyEntry(getKey: String, value: () => String) extends JMapEntry[String, Object]: | ||
lazy val getValue: Object = value() | ||
def setValue(x$0: Object): Object = ??? | ||
|
||
case class LoadedTemplate( | ||
templateFile: TemplateFile, | ||
children: List[LoadedTemplate], | ||
file: File, | ||
hidden: Boolean = false): | ||
|
||
private def brief(ctx: StaticSiteContext): String = | ||
try | ||
val code = Jsoup.parse(resolveToHtml(ctx).code) | ||
Option(code.select("p").first()).fold("...")(_.outerHtml()) | ||
catch | ||
case e: Throwable => | ||
val msg = s"[ERROR] Unable to process brief for ${templateFile.file}" | ||
report.error(msg, templateFile.file, e)(using ctx.outerCtx) | ||
"..." | ||
|
||
def lazyTemplateProperties(ctx: StaticSiteContext): JMap[String, Object] = new java.util.AbstractMap[String, Object](): | ||
lazy val entrySet: JSet[JMapEntry[String, Object]] = | ||
val site = templateFile.settings.getOrElse("page", Map.empty).asInstanceOf[Map[String, Object]] | ||
site.asJava.entrySet() ++ JSet( | ||
LazyEntry("url", () => "/" ++ ctx.pathFromRoot(LoadedTemplate.this).toString), | ||
LazyEntry("title", () => templateFile.title.name), | ||
LazyEntry("excerpt", () => brief(ctx)) | ||
) | ||
|
||
def resolveToHtml(ctx: StaticSiteContext): ResolvedPage = | ||
val subpages = children.filterNot(_.hidden).map(_.lazyTemplateProperties(ctx)) | ||
|
||
def getMap(key: String): Map[String, Object] = | ||
templateFile.settings.getOrElse(key, Map.empty).asInstanceOf[Map[String, Object]] | ||
|
||
// Handle nested structures and lists in frontmatter | ||
def mergeMaps(map1: Map[String, Object], map2: Map[String, Object]): Map[String, Object] = | ||
(map1.keySet ++ map2.keySet).map { key => | ||
key -> ((map1.get(key), map2.get(key)) match { | ||
case (Some(v1: Map[_, _]), Some(v2: Map[_, _])) => | ||
mergeMaps(v1.asInstanceOf[Map[String, Object]], v2.asInstanceOf[Map[String, Object]]) | ||
case (Some(v1: List[_]), Some(v2: List[_])) => | ||
(v1 ++ v2).asInstanceOf[Object] | ||
case (_, Some(v2)) => v2 | ||
case (Some(v1), _) => v1 | ||
case _ => throw new IllegalStateException("Unreachable code") | ||
}) | ||
}.toMap | ||
|
||
val sourceLinks = if !templateFile.file.exists() then Nil else | ||
val actualPath = templateFile.file.toPath | ||
ctx.sourceLinks.pathTo(actualPath).map("viewSource" -> _ ) ++ | ||
ctx.sourceLinks.pathTo(actualPath, operation = "edit").map("editSource" -> _) | ||
|
||
val pageFrontmatter = getMap("page") + ("title" -> templateFile.title.name) | ||
val mergedPageSettings = mergeMaps(pageFrontmatter, templateFile.settings.asInstanceOf[Map[String, Object]]) | ||
|
||
val siteSettings = getMap("site") + ("subpages" -> subpages) | ||
val projectWidePropsMap = ctx.projectWideProperties.toMap.asInstanceOf[Map[String, Object]] // Convert to map | ||
|
||
val updatedSettings = mergeMaps(mergedPageSettings, projectWidePropsMap) + | ||
("site" -> siteSettings) + ("urls" -> sourceLinks.toMap.asInstanceOf[Map[String, Object]]) | ||
|
||
templateFile.resolveInner(RenderingContext(updatedSettings, ctx.layouts))(using ctx) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1776,7 +1776,7 @@ object Build { | |
bundleCSS.taskValue | ||
), | ||
libraryDependencies ++= Dependencies.flexmarkDeps ++ Seq( | ||
"nl.big-o" % "liqp" % "0.8.2", | ||
"nl.big-o" % "liqp" % "0.9", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for context, this was necessary to support the custom syntax |
||
"org.jsoup" % "jsoup" % "1.17.2", // Needed to process .html files for static site | ||
Dependencies.`jackson-dataformat-yaml`, | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.