Skip to content

Add support from member groupping and render html more directly #10795

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

Merged
merged 9 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,13 @@ object Build {
def generateDocumentation(targets: String, name: String, outDir: String, ref: String, params: String = "") = Def.taskDyn {
val projectVersion = version.value
IO.createDirectory(file(outDir))
val sourcesAndRevision = s"-source-links github://lampepfl/dotty -revision $ref -project-version $projectVersion"
val managedSources =
(`stdlib-bootstrapped`/Compile/sourceManaged).value / "scala-library-src"
val projectRoot = (ThisBuild/baseDirectory).value.toPath
val stdLibRoot = projectRoot.relativize(managedSources.toPath.normalize())
val scalaSourceLink =
s"$stdLibRoot=github://scala/scala/v${stdlibVersion(Bootstrapped)}#src/library"
val sourcesAndRevision = s"-source-links $scalaSourceLink,github://lampepfl/dotty -revision $ref -project-version $projectVersion"
val cmd = s""" -d $outDir -project "$name" $sourcesAndRevision $params $targets"""
run.in(Compile).toTask(cmd)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class DocumentableList extends Component {
super(props);

this.refs = {
tabs: findRefs(".section-tab[data-togglable]", findRef(".tabbedcontent")),
sections: findRefs("div[data-togglable]", findRef(".tabbedcontent")),
tabs: findRefs(".names .tab[data-togglable]", findRef(".membersList")).concat(
findRefs(".contents h2[data-togglable]", findRef(".membersList"))
),
sections: findRefs(".contents .tab[data-togglable]", findRef(".membersList")),
};

this.state = {
Expand All @@ -24,14 +26,12 @@ class DocumentableList extends Component {
ref.dataset.visibility = isVisible
}

toggleDisplayStyles(condition, ref, onVisibleStyle) {
ref.style.display = condition ? onVisibleStyle : 'none'
toggleDisplayStyles(condition, ref) {
ref.style.display = condition ? null : 'none'
}

render({ filter }) {
this.state.list.sectionsRefs.map(sectionRef => {
const tabRef = this.state.list.getTabRefFromSectionRef(sectionRef);

const isTabVisible = this.state.list
.getSectionListRefs(sectionRef)
.filter((listRef) => {
Expand All @@ -41,23 +41,26 @@ class DocumentableList extends Component {
.filter(elementData => {
const isElementVisible = this.state.list.isElementVisible(elementData, filter);

this.toggleDisplayStyles(isElementVisible, elementData.ref, "table");
this.toggleDisplayStyles(isElementVisible, elementData.ref);
this.toggleElementDatasetVisibility(isElementVisible, elementData.ref);

return isElementVisible;
}).length;

this.toggleDisplayStyles(isListVisible, listRef, "block");
this.toggleDisplayStyles(isListVisible, listRef);

return isListVisible;
}).length;

this.toggleDisplayStyles(isTabVisible, tabRef, "inline-block");
const outerThis = this
this.state.list.getTabRefFromSectionRef(sectionRef).forEach(function(tabRef){
outerThis.toggleDisplayStyles(isTabVisible, tabRef);
})
});
}
}

class List {
class List {
/**
* @param tabsRef { Element[] }
* @param sectionRefs { Element[] }
Expand All @@ -78,15 +81,15 @@ class List {
/**
* @param name { string }
*/
filterTab(name) {
filterTab(name) {
return name !== "Linear supertypes" && name !== "Known subtypes" && name !== "Type hierarchy"
}

/**
* @param sectionRef { Element }
*/
getTabRefFromSectionRef(sectionRef) {
return this.tabsRefs.find(
return this.tabsRefs.filter(
(tabRef) => this._getTogglable(tabRef) === this._getTogglable(sectionRef)
);
}
Expand Down Expand Up @@ -124,8 +127,8 @@ class List {
* @param filter { Filter }
*/
isElementVisible(elementData, filter) {
return !areFiltersFromElementSelected()
? false
return !areFiltersFromElementSelected()
? false
: includesInputValue()

function includesInputValue() {
Expand All @@ -141,7 +144,7 @@ class List {
.filter(([key]) => !!filter.filters[getFilterKey(key)])

/** @type { Dataset } */
const defaultFiltersForMembersWithoutDataAttribute =
const defaultFiltersForMembersWithoutDataAttribute =
defaultFilters.reduce((acc, [key, value]) => {
const filterKey = getFilterKey(key)
const shouldAddDefaultFilter = !dataset.some(([k]) => k === filterKey)
Expand All @@ -156,7 +159,7 @@ class List {
return defaultFilter ? [k, `${v},${defaultFilter[1]}`] : [k, v]
})

const datasetWithDefaultFilters = [
const datasetWithDefaultFilters = [
...defaultFiltersForMembersWithoutDataAttribute,
...datasetWithAppendedDefaultFilters
]
Expand Down
22 changes: 11 additions & 11 deletions scala3doc/resources/dotty_res/scripts/components/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Filter {
const newFilters = this._elementsRefs.reduce((filtersObject, elementRef) => {
this._getDatasetWithKeywordData(elementRef.dataset).forEach(([key, value]) =>
this._splitByComma(value).forEach((val) => {
filtersObject[key] = filtersObject[key]
filtersObject[key] = filtersObject[key]
? { ...filtersObject[key], [val]: filtersObject[key][val] ?? new FilterItem() }
: { [val]: new FilterItem() }
})
Expand All @@ -161,21 +161,21 @@ class Filter {
/**
* @private
* @param {Filters} newFilters
* @returns {Filters}
* @returns {Filters}
*/
_attachDefaultFilters(newFilters) {
return Object.entries(Filter.defaultFilters).reduce((acc, [key, defaultFilter]) => {
const filterKey = getFilterKey(key)
const shouldAddDefaultKeywordFilter = this._elementsRefs.some(ref => !!ref.dataset[filterKey])
return shouldAddDefaultKeywordFilter
? {
...acc,
[filterKey]: {
...acc[filterKey],
[defaultFilter]: new FilterItem()
}
}

return shouldAddDefaultKeywordFilter
? {
...acc,
[filterKey]: {
...acc[filterKey],
[defaultFilter]: new FilterItem()
}
}
: acc
}, newFilters)
}
Expand Down
33 changes: 0 additions & 33 deletions scala3doc/resources/dotty_res/scripts/diagram.js
Original file line number Diff line number Diff line change
@@ -1,33 +0,0 @@
$("#inheritance-diagram").ready(function() {
if ($("svg#graph").children().length == 0) {
var dotNode = document.querySelector("#dot")
if (dotNode){
var svg = d3.select("#graph");
var inner = svg.append("g");

// Set up zoom support
var zoom = d3.zoom()
.on("zoom", function({transform}) {
inner.attr("transform", transform);
});
svg.call(zoom);

var render = new dagreD3.render();
var g = graphlibDot.read(dotNode.text);
g.graph().rankDir = 'BT';
g.nodes().forEach(function (v) {
g.setNode(v, {
labelType: "html",
label: g.node(v).label,
style: g.node(v).style
});
});
g.edges().forEach(function(v) {
g.setEdge(v, {
arrowhead: "vee"
});
});
render(inner, g);
}
}
})
51 changes: 51 additions & 0 deletions scala3doc/resources/dotty_res/scripts/ux.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ window.addEventListener("DOMContentLoaded", () => {
$(this).parent().toggleClass("expanded")
});

$('.names .tab').on('click', function(){
parent = $(this).parents(".tabs").first()
shown = $(this).hasClass('selected')
single = parent.hasClass("single")

if (single) parent.find(".tab.selected").removeClass('selected')

id = $(this).attr('data-togglable')
myTab = parent.find("[data-togglable='" + id + "'].tab")
if (!shown) { myTab.addClass('selected') }
if (shown && !single) myTab.removeClass('selected')

if(!shown && $(this).find(".showGraph")){
showGraph()
$(this).find(".showGraph").removeClass("showGraph")
}
})

if (location.hash) {
var selected = document.getElementById(location.hash.substring(1));
Expand All @@ -37,3 +54,37 @@ window.addEventListener("DOMContentLoaded", () => {
hljs.registerAliases(["dotty", "scala3"], "scala");
hljs.initHighlighting();
});

function showGraph() {
if ($("svg#graph").children().length == 0) {
var dotNode = document.querySelector("#dot")
if (dotNode){
var svg = d3.select("#graph");
var inner = svg.append("g");

// Set up zoom support
var zoom = d3.zoom()
.on("zoom", function({transform}) {
inner.attr("transform", transform);
});
svg.call(zoom);

var render = new dagreD3.render();
var g = graphlibDot.read(dotNode.text);
g.graph().rankDir = 'BT';
g.nodes().forEach(function (v) {
g.setNode(v, {
labelType: "html",
label: g.node(v).label,
style: g.node(v).style
});
});
g.edges().forEach(function(v) {
g.setEdge(v, {
arrowhead: "vee"
});
});
render(inner, g);
}
}
}
51 changes: 44 additions & 7 deletions scala3doc/resources/dotty_res/styles/scalastyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ footer .pull-right {
}


.modifiers {
.documentableElement .modifiers {
display: table-cell;
padding-right: 0.5em;
min-width: 10em;
Expand All @@ -472,23 +472,27 @@ footer .pull-right {
text-indent: 0em;
}

.modifiers .other-modifiers {
.documentableElement .modifiers .other-modifiers {
color: gray;
}

.kind {
margin-left: 0.5em;
}

.other-modifiers a, .other-modifiers a:visited, .other-modifiers span[data-unresolved-link] {
color: var(--link-sig-fd);
}

.expand .modifiers {
.documentableElement.expand .modifiers {
display: inline-table;
min-width: 7em;
}

.signature {
.documentableElement .signature {
color: gray;
display: table-cell;
padding-left: 0.5em;
white-space: pre-wrap;
}

.signature a, .signature a:visited, .signature span[data-unresolved-link] {
Expand Down Expand Up @@ -551,12 +555,12 @@ footer .pull-right {
.expand.documentableElement {
border-left: 0.25em solid var(--leftbar-bg);
}
.annotations {
.documentableElement .annotations {
color: gray;
display: none;
}

.expand .annotations {
.documentableElement.expand .annotations {
display: inline-block;
}

Expand All @@ -575,6 +579,39 @@ footer .pull-right {
margin: .5em 0 0 0;
}

.tabs .names .tab {
border: none;
outline: none;
background: transparent;
padding: 0 6px 4px 6px;
margin: 1rem 1rem 0 0;
border-bottom: 1px solid grey;
cursor: pointer;
}

.tabs .names .tab.selected {
color: unset;
font-weight: bold;
border-bottom: 2px solid var(--active-tab-color);
}

.tabs .names {
margin-bottom: 20px;
}

.tabs .contents .tab{
display: none;
}

.tabs .contents .tab.selected {
display: block;
}

.diagram-class {
width: 100%;
max-height: 400px;
}

/* Large Screens */
@media(min-width: 1100px) {
:root {
Expand Down
7 changes: 0 additions & 7 deletions scala3doc/src/dotty/dokka/DottyDokkaPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
.overrideExtension(dokkaBase.getModulesAndPackagesDocumentation)
)

val ourSignatureProvider = extend(
_.extensionPoint(dokkaBase.getSignatureProvider)
.fromRecipe{ case ctx @ given DokkaContext =>
new ScalaSignatureProvider(ctx.single(dokkaBase.getCommentsToContentConverter))
}.overrideExtension(dokkaBase.getKotlinSignatureProvider)
)

val scalaResourceInstaller = extend(
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
.fromRecipe{ case ctx @ given DokkaContext => new ScalaResourceInstaller }
Expand Down
18 changes: 18 additions & 0 deletions scala3doc/src/dotty/dokka/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.*;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.function.Consumer;
import java.nio.charset.Charset;

/** This code is mostly using public snippets and tries to mimic sbt-io api. */
public class IO {
Expand All @@ -25,4 +27,20 @@ public FileVisitResult visitFile(
}
});
}

public static void foreachFileIn(Path dir, Consumer<Path> op) throws IOException {
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(
Path file, BasicFileAttributes attrs)
throws IOException {
op.accept(file);
return FileVisitResult.CONTINUE;
}
});
}

public static String read(Path path) throws IOException {
return new String(Files.readAllBytes(path), Charset.defaultCharset());
}
}
Loading