Skip to content

Commit 9603491

Browse files
committed
Migrate away from scala tags
1 parent 12507f5 commit 9603491

File tree

4 files changed

+103
-27
lines changed

4 files changed

+103
-27
lines changed

scala3doc/build.sbt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ libraryDependencies ++= Seq(
99

1010
"com.virtuslab.dokka" % "dokka-site" % dokkaSiteVersion,
1111
"com.vladsch.flexmark" % "flexmark-all" % flexmarkVersion,
12-
"com.lihaoyi" % "scalatags_2.13" % scalaTagsVersion,
1312
"nl.big-o" % "liqp" % "0.6.7",
1413
"args4j" % "args4j" % "2.33",
15-
) //a a
14+
)
1615

1716
val generateSelfDocumentation = inputKey[Unit]("Generate example documentation")
1817
generateSelfDocumentation := Def.inputTaskDyn {

scala3doc/src/dotty/renderers/DotDiagramBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.jetbrains.dokka.links.DRI
66
import org.jetbrains.dokka.base.resolvers.local.LocationProvider
77
import org.jetbrains.dokka.pages._
88
import dotty.dokka.model.api.Kind
9-
import scalatags.Text.all._
9+
import HTML._
1010
import dotty.dokka.model.api._
1111

1212
object DotDiagramBuilder:

scala3doc/src/dotty/renderers/ScalaHtmlRenderer.scala

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import org.jetbrains.dokka.plugability.DokkaContext
44
import org.jetbrains.dokka.pages._
55
import org.jetbrains.dokka.model._
66
import org.jetbrains.dokka._
7-
import scalatags.Text.all._
8-
import scalatags.Text.svgTags._
9-
import scalatags.Text.svgTags.attr
10-
import scalatags.Text.tags2.{title, main, nav}
11-
import scalatags.Text.TypedTag
7+
import HTML._
128
import collection.JavaConverters._
139
import com.virtuslab.dokka.site.SiteRenderer
1410
import com.virtuslab.dokka.site.BaseStaticSiteProcessor
@@ -26,17 +22,17 @@ import org.jetbrains.dokka.base.resolvers.local.LocationProvider
2622
class SignatureRenderer(pageContext: ContentPage, sourceSetRestriciton: JSet[DisplaySourceSet], locationProvider: LocationProvider):
2723
def link(dri: DRI): Option[String] = Option(locationProvider.resolve(dri, sourceSetRestriciton, pageContext))
2824

29-
def renderLink(name: String, dri: DRI, modifiers: scalatags.Text.all.Modifier*) =
25+
def renderLink(name: String, dri: DRI, modifiers: AppliedAttr*) =
3026
link(dri) match
3127
case Some(link) => a(href := link, modifiers)(name)
3228
case None if modifiers.isEmpty => raw(name)
3329
case _ => span(modifiers)(name)
3430

3531

36-
def renderElementWith(e: String | (String, DRI) | Link, modifiers: scalatags.Text.all.Modifier*) = e match
37-
case (name, dri) => renderLink(name, dri, modifiers)
32+
def renderElementWith(e: String | (String, DRI) | Link, modifiers: AppliedAttr*) = e match
33+
case (name, dri) => renderLink(name, dri, modifiers:_*)
3834
case name: String => raw(name)
39-
case Link(name, dri) => renderLink(name, dri, modifiers)
35+
case Link(name, dri) => renderLink(name, dri, modifiers:_*)
4036

4137

4238
def renderElement(e: String | (String, DRI) | Link) = renderElementWith(e)
@@ -77,8 +73,6 @@ class ScalaHtmlRenderer(ctx: DokkaContext) extends SiteRenderer(ctx) {
7773
}
7874
}
7975

80-
private val cls = `class`
81-
8276
private val anchor = raw("""
8377
<svg width="24" height="24" viewBox="0 0 24 24" fill="darkgray" xmlns="http://www.w3.org/2000/svg">
8478
<path d="M21.2496 5.3C20.3496 4.5 19.2496 4 18.0496 4C16.8496 4 15.6496 4.5 14.8496 5.3L10.3496 9.8L11.7496 11.2L16.2496 6.7C17.2496 5.7 18.8496 5.7 19.8496 6.7C20.8496 7.7 20.8496 9.3 19.8496 10.3L15.3496 14.8L16.7496 16.2L21.2496 11.7C22.1496 10.8 22.5496 9.7 22.5496 8.5C22.5496 7.3 22.1496 6.2 21.2496 5.3Z"></path>
@@ -95,7 +89,7 @@ class ScalaHtmlRenderer(ctx: DokkaContext) extends SiteRenderer(ctx) {
9589
import renderer._
9690

9791
def buildDocumentable(element: DocumentableElement) =
98-
def topLevelAttr = Seq(cls := "documentableElement") ++ element.attributes.map{ case (n, v) => attr(s"data-f-$n") := v }
92+
def topLevelAttr = Seq(cls := "documentableElement") ++ element.attributes.map{ case (n, v) => Attr(s"data-f-$n") := v }
9993
val kind = element.modifiers.takeRight(1)
10094
val otherModifiers = element.modifiers.dropRight(1)
10195

@@ -193,10 +187,11 @@ class ScalaHtmlRenderer(ctx: DokkaContext) extends SiteRenderer(ctx) {
193187

194188
def buildDiagram(f: FlowContent, diagram: HierarchyDiagram, pageContext: ContentPage) =
195189
val renderer = SignatureRenderer(pageContext, sourceSets, getLocationProvider)
196-
withHtml(f, div( id := "inheritance-diagram",
190+
withHtml(f, div( id := "inheritance-diagram")(
197191
svg(id := "graph"),
198-
script(`type` := "text/dot", id := "dot", raw(DotDiagramBuilder.build(diagram, renderer)))
199-
).render
192+
script(`type` := "text/dot", id := "dot"),
193+
raw(DotDiagramBuilder.build(diagram, renderer))
194+
).toString()
200195
)
201196

202197
override def buildHtml(page: PageNode, resources: JList[String], kotlinxContent: FlowContentConsumer): String =
@@ -219,18 +214,14 @@ class ScalaHtmlRenderer(ctx: DokkaContext) extends SiteRenderer(ctx) {
219214
if fromTemplate then
220215
raw(buildWithKotlinx(kotlinxContent))
221216
else
222-
div(
223-
id := "container",
224-
div(
225-
id := "leftColumn",
217+
div(id := "container")(
218+
div(id := "leftColumn")(
226219
div(id := "logo"),
227220
div(id := "paneSearch"),
228221
nav(id := "sideMenu"),
229222
),
230-
div(
231-
id := "main",
232-
div (
233-
id := "leftToggler",
223+
div(id := "main")(
224+
div (id := "leftToggler")(
234225
span(cls := "icon-toggler")
235226
),
236227
div(id := "searchBar"),
@@ -259,7 +250,7 @@ class ScalaHtmlRenderer(ctx: DokkaContext) extends SiteRenderer(ctx) {
259250
private def resolveRoot(page: PageNode, path: String) =
260251
getLocationProvider.pathToRoot(page) + path
261252

262-
private def linkResources(page: PageNode, resources: Iterable[String]): Iterable[Frag] =
253+
private def linkResources(page: PageNode, resources: Iterable[String]): Iterable[AppliedTag] =
263254
def fileExtension(url: String): String =
264255
val param = url.indexOf('?')
265256
val end = if param < 0 then url.length else param
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package dotty.dokka
2+
3+
/**
4+
* This is trivial html renderer using api inspired by ScalaTags
5+
* It probably could be more efficient but for now on it should be good enough.
6+
*/
7+
object HTML:
8+
type AttrArg = AppliedAttr | Seq[AppliedAttr]
9+
type TagArg = AppliedTag | Seq[AppliedTag] | String | Seq[String]
10+
11+
case class Tag(name: String):
12+
def apply(tags: TagArg*): AppliedTag = apply()(tags:_*)
13+
def apply(first: AttrArg, rest: AttrArg*): AppliedTag = apply((first +: rest):_*)()
14+
def apply(attrs: AttrArg*)(tags: TagArg*): AppliedTag = {
15+
val sb = StringBuilder()
16+
sb.append(s"<$name")
17+
attrs.foreach{
18+
case s: Seq[AppliedAttr] =>
19+
s.foreach(sb.append(" ").append)
20+
case e: AppliedAttr =>
21+
sb.append(" ").append(e)
22+
}
23+
sb.append(">")
24+
tags.foreach{
25+
case t: AppliedTag =>
26+
sb.append(t)
27+
case s: String =>
28+
sb.append(s)
29+
case s: Seq[AppliedTag | String] =>
30+
s.foreach{
31+
case a: AppliedTag =>
32+
sb.append(a)
33+
case s: String =>
34+
sb.append(s)
35+
}
36+
}
37+
sb.append(s"</$name>")
38+
sb
39+
}
40+
41+
case class Attr(name: String):
42+
def :=(value: String): AppliedAttr = AppliedAttr(s"""$name="$value"""")
43+
44+
opaque type AppliedTag = StringBuilder
45+
46+
opaque type AppliedAttr = String
47+
48+
val div = Tag("div")
49+
val span = Tag("span")
50+
val a = Tag("a")
51+
val h1 = Tag("h1")
52+
val h2 = Tag("h2")
53+
val h3 = Tag("h3")
54+
val h4 = Tag("h4")
55+
val dl = Tag("dl")
56+
val dd = Tag("dd")
57+
val dt = Tag("dt")
58+
val svg = Tag("svg")
59+
val button = Tag("button")
60+
val input = Tag("input")
61+
val script = Tag("script")
62+
val link = Tag("link")
63+
val footer = Tag("footer")
64+
val html = Tag("html")
65+
val head = Tag("head")
66+
val meta = Tag("meta")
67+
val main = Tag("main")
68+
val title = Tag("title")
69+
val body = Tag("body")
70+
val nav = Tag("nav")
71+
72+
val cls = Attr("class")
73+
val href = Attr("href")
74+
val style = Attr("style")
75+
val id = Attr("id")
76+
val `type` = Attr("type")
77+
val placeholder = Attr("placeholder")
78+
val defer = Attr("defer")
79+
val src = Attr("src")
80+
val rel = Attr("rel")
81+
val charset = Attr("charset")
82+
val name = Attr("name")
83+
val content = Attr("content")
84+
85+
def raw(content: String): AppliedTag = AppliedTag(content)
86+

0 commit comments

Comments
 (0)