Skip to content

Commit

Permalink
Linking to javadoc inner classes (#395)
Browse files Browse the repository at this point in the history
* Linking to javadoc inner classes

* Move tests the the right place
  • Loading branch information
raboof authored Dec 3, 2019
1 parent 35007de commit 6288ac0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
19 changes: 13 additions & 6 deletions core/src/main/scala/com/lightbend/paradox/markdown/Directive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ case class ScaladocDirective(ctx: Writer.Context)

object JavadocDirective {

type LinkStyle = String
val LinkStyleFrames = "frames"
val LinkStyleDirect = "direct"

Expand All @@ -333,6 +334,16 @@ object JavadocDirective {
val jdkDependentLinkStyle = if (sys.props.get("java.specification.version").exists(_.startsWith("1."))) LinkStyleFrames else LinkStyleDirect

final val JavadocLinkStyleProperty = raw"""javadoc\.(.*).link_style""".r

private[markdown] def url(link: String, baseUrl: Url, linkStyle: LinkStyle): Url = {
val url = Url(link).base
val path = url.getPath.replaceAll("(\\b[a-z]+)\\.", "$1/") + ".html"
linkStyle match {
case LinkStyleFrames => baseUrl.withEndingSlash.withQuery(path).withFragment(url.getFragment)
case LinkStyleDirect => (baseUrl / path).withFragment(url.getFragment)
}
}

}

case class JavadocDirective(ctx: Writer.Context)
Expand All @@ -353,12 +364,8 @@ case class JavadocDirective(ctx: Writer.Context)
val packagesDeepestFirst = packages.reverse
val baseUrl = packagesDeepestFirst.collectFirst(baseUrls).getOrElse(defaultBaseUrl).resolve()
val linkStyle = packagesDeepestFirst.collectFirst(packageLinkStyle).getOrElse(rootLinkStyle)
val url = Url(link).base
val path = url.getPath.replace('.', '/') + ".html"
linkStyle match {
case LinkStyleFrames => baseUrl.withEndingSlash.withQuery(path).withFragment(url.getFragment)
case LinkStyleDirect => (baseUrl / path).withFragment(url.getFragment)
}
url(link, baseUrl, linkStyle)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import com.lightbend.paradox.ParadoxException

class JavadocDirectiveSpec extends MarkdownBaseSpec {

import JavadocDirective._

implicit val context = writerContextWithProperties(
"javadoc.base_url" -> "http://www.reactive-streams.org/reactive-streams-1.0.0-javadoc/",
"javadoc.link_style" -> "frames",
Expand Down Expand Up @@ -115,4 +117,20 @@ class JavadocDirectiveSpec extends MarkdownBaseSpec {
|Direct: <a href="http://www.reactive-streams.org/reactive-streams-1.0.0-javadoc/org/reactivestreams/Publisher.html" title="org.reactivestreams.Publisher"><code>Publisher</code></a></p>""".stripMargin)
}

it should "correctly link to an inner JRE class" in {
url(
"java.util.concurrent.Flow.Subscriber",
Url("https://docs.oracle.com/en/java/javase/11/docs/api/java.base/"),
LinkStyleDirect
) should be(Url("https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/Flow.Subscriber.html"))
}

it should "correctly link to an inner Akka class" in {
url(
"akka.actor.testkit.typed.Effect.MessageAdapter",
Url("https://doc.akka.io/japi/akka/current/"),
LinkStyleDirect
) should be(Url("https://doc.akka.io/japi/akka/current/akka/actor/testkit/typed/Effect.MessageAdapter.html"))
}

}

0 comments on commit 6288ac0

Please sign in to comment.