Skip to content

Commit 8138baa

Browse files
BarkingBadpikinier20
authored andcommitted
Automatically publish Scala3doc with Scala.js files
1 parent 57e96d4 commit 8138baa

File tree

7 files changed

+77
-57
lines changed

7 files changed

+77
-57
lines changed

project/Build.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,19 @@ object Build {
16341634
),
16351635
Compile / buildInfoKeys := Seq[BuildInfoKey](version),
16361636
Compile / buildInfoPackage := "dotty.dokka",
1637+
Compile / resourceGenerators += Def.task {
1638+
val jsDestinationFile = (Compile / resourceManaged).value / "dotty_res" / "scripts" / "searchbar.js"
1639+
sbt.IO.copyFile((fullOptJS in Compile in `scala3doc-js`).value.data, jsDestinationFile)
1640+
Seq(jsDestinationFile)
1641+
}.taskValue,
1642+
Compile / resourceGenerators += Def.task {
1643+
val cssDesitnationFile = (Compile / resourceManaged).value / "dotty_res" / "styles" / "scala3doc-searchbar.css"
1644+
val cssSourceFile = (resourceDirectory in Compile in `scala3doc-js`).value / "scala3doc-searchbar.css"
1645+
FileFunction.cached(streams.value.cacheDirectory / "css-cache") { (in: Set[File]) =>
1646+
in.headOption.map(sbt.IO.copyFile(_, cssDesitnationFile))
1647+
Set(cssDesitnationFile)
1648+
}.apply(Set(cssSourceFile)).toSeq
1649+
}.taskValue,
16371650
testDocumentationRoot := (baseDirectory.value / "test-documentations").getAbsolutePath,
16381651
buildInfoPackage in Test := "dotty.dokka.test",
16391652
BuildInfoPlugin.buildInfoScopedSettings(Test),

scala3doc-js/resources/scala3doc-searchbar.css

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@
22
--inkuire-logo-size: 20px;
33
}
44

5+
/* button */
6+
.search span {
7+
background: #ED3522;
8+
fill: #fff;
9+
cursor: pointer;
10+
border: none;
11+
padding: 9px;
12+
border-radius: 24px;
13+
box-shadow: 0 0 16px #F27264;
14+
}
15+
.search span:hover {
16+
fill: #F27264;
17+
}
18+
19+
@media(max-width: 576px) {
20+
.search span {
21+
background: none;
22+
fill: var(--icon-color);
23+
cursor: pointer;
24+
border: none;
25+
padding: 0;
26+
box-shadow: none;
27+
margin-top: 2px;
28+
}
29+
.search span:hover {
30+
fill: var(--link-hover-fg);
31+
}
32+
}
33+
534
#scala3doc-search {
635
margin-top: 2px;
736
cursor: pointer;
@@ -11,13 +40,6 @@
1140
z-index: 5;
1241
}
1342

14-
#scala3doc-search::before {
15-
content: "";
16-
display:block;
17-
height: var(--inkuire-logo-size);
18-
width: var(--inkuire-logo-size);
19-
}
20-
2143
#scala3doc-searchbar.hidden {
2244
display: none;
2345
}

scala3doc-js/src/Main.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ object Main extends App {
44
def initializeSearchbar(): Unit = Searchbar()
55

66
initializeSearchbar()
7-
}
7+
}

scala3doc-js/src/searchbar/SearchbarComponent.scala

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package dotty.dokka
33
import org.scalajs.dom._
44
import org.scalajs.dom.html.Input
55

6-
class SearchbarComponent(val callback: (String) => List[PageEntry]) {
6+
class SearchbarComponent(val callback: (String) => List[PageEntry]):
77
extension (p: PageEntry)
8-
def toHTML = {
8+
def toHTML =
99
val wrapper = document.createElement("div")
1010
wrapper.classList.add("scala3doc-searchbar-result")
1111
wrapper.classList.add("monospace")
@@ -22,41 +22,53 @@ class SearchbarComponent(val callback: (String) => List[PageEntry]) {
2222
wrapper.appendChild(resultA)
2323
wrapper.appendChild(location)
2424
wrapper
25-
}
2625

27-
def handleNewQuery(query: String) = {
26+
def handleNewQuery(query: String) =
2827
val result = callback(query).map(_.toHTML)
2928
while (resultsDiv.hasChildNodes()) resultsDiv.removeChild(resultsDiv.lastChild)
3029
result.foreach(resultsDiv.appendChild)
31-
}
3230

33-
private val logoClick: html.Span = {
34-
val element = document.createElement("span").asInstanceOf[html.Span]
35-
element.id = "scala3doc-search"
36-
element.onclick = (event: Event) =>
31+
private val logoClick: html.Div =
32+
val span = document.createElement("span").asInstanceOf[html.Span]
33+
span.innerHTML = """<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20"><path d="M19.64 18.36l-6.24-6.24a7.52 7.52 0 10-1.28 1.28l6.24 6.24zM7.5 13.4a5.9 5.9 0 115.9-5.9 5.91 5.91 0 01-5.9 5.9z"></path></svg>"""
34+
span.id = "scala3doc-search"
35+
span.onclick = (event: Event) =>
3736
if (rootDiv.className.contains("hidden"))
3837
rootDiv.className = rootShowClasses
3938
else rootDiv.className = rootHiddenClasses
40-
document.getElementById("searchBar").appendChild(element)
39+
40+
val element = createNestingDiv("search-content")(
41+
createNestingDiv("search-conatiner")(
42+
createNestingDiv("search")(
43+
span
44+
)
45+
)
46+
)
47+
document.getElementById("scala3doc-searchBar").appendChild(element)
4148
element
42-
}
4349

44-
private val input: html.Input = {
50+
51+
private val input: html.Input =
4552
val element = document.createElement("input").asInstanceOf[html.Input]
4653
element.id = "scala3doc-searchbar-input"
4754
element.addEventListener("input", (e) => handleNewQuery(e.target.asInstanceOf[html.Input].value))
4855
element
49-
}
5056

51-
private val resultsDiv: html.Div = {
57+
private val resultsDiv: html.Div =
5258
val element = document.createElement("div").asInstanceOf[html.Div]
5359
element.id = "scala3doc-searchbar-results"
5460
element
55-
}
5661

5762
private val rootHiddenClasses = "hidden"
5863
private val rootShowClasses = ""
59-
private val rootDiv: html.Div = {
64+
65+
private def createNestingDiv(className: String)(innerElement: html.Element): html.Div =
66+
val element = document.createElement("div").asInstanceOf[html.Div]
67+
element.className = className
68+
element.appendChild(innerElement)
69+
element
70+
71+
private val rootDiv: html.Div =
6072
val element = document.createElement("div").asInstanceOf[html.Div]
6173
element.addEventListener("click", (e: Event) => e.stopPropagation())
6274
logoClick.addEventListener("click", (e: Event) => e.stopPropagation())
@@ -67,7 +79,5 @@ class SearchbarComponent(val callback: (String) => List[PageEntry]) {
6779
element.appendChild(resultsDiv)
6880
document.body.appendChild(element)
6981
element
70-
}
7182

7283
handleNewQuery("")
73-
}

scala3doc/resources/dotty_res/styles/search-bar.css

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,6 @@
99
background: none;
1010
}
1111

12-
/* button */
13-
.search button {
14-
background: #ED3522;
15-
fill: #fff;
16-
cursor: pointer;
17-
border: none;
18-
padding: 9px;
19-
border-radius: 24px;
20-
box-shadow: 0 0 16px #F27264;
21-
}
22-
.search button:hover {
23-
fill: #F27264;
24-
}
25-
2612
/* popup */
2713
.popup-wrapper {
2814
box-shadow: 0 0 10px var(--border-light) !important;
@@ -58,18 +44,6 @@
5844

5945
/* Portrait phones */
6046
@media(max-width: 576px) {
61-
.search button {
62-
background: none;
63-
fill: var(--icon-color);
64-
cursor: pointer;
65-
border: none;
66-
padding: 0;
67-
box-shadow: none;
68-
margin-top: 2px;
69-
}
70-
.search button:hover {
71-
fill: var(--link-hover-fg);
72-
}
7347
.search-content {
7448
margin: 0 !important;
7549
top: 9px !important;
@@ -88,4 +62,4 @@
8862
min-width: 100%;
8963
width: auto !important;
9064
}
91-
}
65+
}

scala3doc/src/dotty/dokka/preprocessors/ScalaEmbeddedResourceApppender.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ScalaEmbeddedResourceAppender extends PageTransformer {
2121
"styles/diagram.css",
2222
"styles/filter-bar.css",
2323
"styles/search-bar.css",
24+
"styles/scala3doc-searchbar.css",
2425
"https://code.jquery.com/jquery-3.5.1.min.js",
2526
"https://d3js.org/d3.v6.min.js",
2627
"https://cdn.jsdelivr.net/npm/[email protected]/dist/graphlib-dot.min.js",
@@ -36,7 +37,8 @@ class ScalaEmbeddedResourceAppender extends PageTransformer {
3637
"scripts/components/Input.js",
3738
"scripts/components/FilterGroup.js",
3839
"scripts/components/Filter.js",
39-
"scripts/data.js"
40+
"scripts/data.js",
41+
"scripts/searchbar.js"
4042
)).asJava,
4143
page.getChildren
4244
)

scala3doc/src/dotty/renderers/ScalaHtmlRenderer.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class ScalaHtmlRenderer(using ctx: DokkaContext) extends HtmlRenderer(ctx) {
279279
div (id := "leftToggler")(
280280
span(cls := "icon-toggler")
281281
),
282-
div(id := "searchBar"),
282+
div(id := "scala3doc-searchBar"),
283283
main(
284284
raw(buildWithKotlinx(kotlinxContent))
285285
),
@@ -297,8 +297,7 @@ class ScalaHtmlRenderer(using ctx: DokkaContext) extends HtmlRenderer(ctx) {
297297
)
298298
)
299299
),
300-
script(`type` := "text/javascript", src := resolveRoot(page, "scripts/pages.js")),
301-
script(`type` := "text/javascript", src := resolveRoot(page, "scripts/main.js"))
300+
script(`type` := "text/javascript", src := resolveRoot(page, "scripts/pages.js"))
302301
)
303302
).toString
304303

0 commit comments

Comments
 (0)