diff --git a/build.sbt b/build.sbt index 4034e7a..96b4ca7 100644 --- a/build.sbt +++ b/build.sbt @@ -145,6 +145,8 @@ lazy val docsScalaNativeBindingsDirectory = settingKey[File]("wordcount source") lazy val docs = nativeProject("docs") .enablePlugins(GhpagesPlugin, ParadoxSitePlugin, ParadoxMaterialThemePlugin) .enablePlugins(ScalaNativeBindgenPlugin) + .settings( + org.scalanative.bindgen.build.ParadoxSupport.paradoxWithCustomDirectives) .settings( publish / skip := true, docsUsingBindingsDirectory := (Test / resourceDirectory).value / "using-bindings", diff --git a/docs/src/paradox/bindings/iconv.md b/docs/src/paradox/bindings/iconv.md index 3ad83f5..0743948 100644 --- a/docs/src/paradox/bindings/iconv.md +++ b/docs/src/paradox/bindings/iconv.md @@ -2,20 +2,7 @@ To use this binding add the following resolver and the dependency: -sbt -: @@snip [build.sbt](../resources/build.sbt) - -Maven -: @@snip [pom.xml](../resources/pom.xml) { #library_resolver } - -Gradle -: @@snip [build.gradle](../resources/build.gradle) - -@@dependency[sbt,Maven,Gradle] { - group="org.scala-native.bindgen" - artifact="libiconv_$scala.binary.version$" - version="$project.version$" -} +@@binding[iconv] The [`iconv.h`] header allows to convert text between different character sets, for example UTF-8 to ISO-8859-1. diff --git a/docs/src/paradox/bindings/posix.md b/docs/src/paradox/bindings/posix.md index d3df746..77d6f0c 100644 --- a/docs/src/paradox/bindings/posix.md +++ b/docs/src/paradox/bindings/posix.md @@ -2,21 +2,7 @@ An addition to Scala Native's [POSIX](http://www.scala-native.org/en/latest/lib/posixlib.html) bindings. To use one of the POSIX bindings you must add the resolver and the dependency: -sbt -: @@snip [build.sbt](../resources/build.sbt) - -Maven -: @@snip [pom.xml](../resources/pom.xml) { #library_resolver } - -Gradle -: @@snip [build.gradle](../resources/build.gradle) - - -@@dependency[sbt,Maven,Gradle] { - group="org.scala-native.bindgen" - artifact="libposix_$scala.binary.version$" - version="$project.version$" -} +@@binding[posix] Binding objects are available under the package name ` diff --git a/docs/src/paradox/bindings/utf8proc.md b/docs/src/paradox/bindings/utf8proc.md index f844fee..1e61ab3 100644 --- a/docs/src/paradox/bindings/utf8proc.md +++ b/docs/src/paradox/bindings/utf8proc.md @@ -4,20 +4,7 @@ This binding for [`utf8proc.h`] provides Unicode normalization, case-folding, an To use it add the following resolver and the dependency: -sbt -: @@snip [build.sbt](../resources/build.sbt) - -Maven -: @@snip [pom.xml](../resources/pom.xml) { #library_resolver } - -Gradle -: @@snip [build.gradle](../resources/build.gradle) - -@@dependency[sbt,Maven,Gradle] { - group="org.scala-native.bindgen" - artifact="libutf8proc_$scala.binary.version$" - version="$project.version$" -} +@@binding[utf8proc] ## Example diff --git a/docs/src/paradox/resources/build.gradle b/docs/src/paradox/resources/build.gradle deleted file mode 100644 index 3b95f25..0000000 --- a/docs/src/paradox/resources/build.gradle +++ /dev/null @@ -1,5 +0,0 @@ -repositories { - maven { - url "https://dl.bintray.com/scala-native-bindgen/maven" - } -} diff --git a/docs/src/paradox/resources/build.sbt b/docs/src/paradox/resources/build.sbt deleted file mode 100644 index 841a663..0000000 --- a/docs/src/paradox/resources/build.sbt +++ /dev/null @@ -1 +0,0 @@ -resolvers += Resolver.bintrayRepo("scala-native-bindgen", "maven") diff --git a/docs/src/paradox/resources/pom.xml b/docs/src/paradox/resources/pom.xml deleted file mode 100644 index e9ff9dd..0000000 --- a/docs/src/paradox/resources/pom.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - 4.0.0 - - maven-scala-test - - - - - maven - http://dl.bintray.com/scala-native-bindgen/maven - - - - - diff --git a/project/ParadoxSupport.scala b/project/ParadoxSupport.scala new file mode 100644 index 0000000..daa3294 --- /dev/null +++ b/project/ParadoxSupport.scala @@ -0,0 +1,89 @@ +package org.scalanative.bindgen.build + +import com.lightbend.paradox.markdown._ +import com.lightbend.paradox.sbt.ParadoxPlugin.autoImport.paradoxDirectives +import org.pegdown.Printer +import org.pegdown.ast.{DirectiveNode, TextNode, Visitor} +import scala.collection.JavaConverters._ + +object ParadoxSupport { + val paradoxWithCustomDirectives = Seq( + paradoxDirectives ++= Seq( + { context: Writer.Context ⇒ + new BindingDependencyDirective(context.location.tree.label, + context.properties) + } + ) + ) + + /* Based on the DependencyDirective from Paradox. */ + case class BindingDependencyDirective(page: Page, + variables: Map[String, String]) + extends LeafBlockDirective("binding") { + val projectVersion = variables("project.version") + val scalaBinaryVersion = variables("scala.binary.version") + + def render(node: DirectiveNode, + visitor: Visitor, + printer: Printer): Unit = { + node.contentsNode.getChildren.asScala.headOption match { + case Some(text: TextNode) => + renderBindingDependency(text.getText, printer) + case _ => node.contentsNode.accept(visitor) + } + } + + def renderBindingDependency(binding: String, printer: Printer): Unit = { + val group = "org.scala-native.bindgen" + val artifactName = s"lib$binding" + val artifactId = s"${artifactName}_native0.3_${scalaBinaryVersion}" + val bintrayRepo = "http://dl.bintray.com/scala-native-bindgen/maven" + + printer.print( + s""" + |
+ |
sbt
+ |
+ |
resolvers += Resolver.bintrayRepo("scala-native-bindgen", "maven")
+           |libraryDependencies += "${group}" %%% "${artifactName}" % "${projectVersion}"
+           |
+ |
+ | + |
Maven
+ |
+ |
<repositories>
+           |  <repository>
+           |    <id>maven</id>
+           |    <url>${bintrayRepo}</url>
+           |  </repository>
+           |</repositories>
+           |
+           |<dependencies>
+           |  <dependency>
+           |    <groupId>${group}</groupId>
+           |    <artifactId>${artifactId}</artifactId>
+           |    <version>${projectVersion}</version>
+           |  </dependency>
+           |</dependencies>
+           |
+ |
+ | + |
Gradle
+ |
+ |
repositories {
+           |  maven {
+           |    url "${bintrayRepo}"
+           |  }
+           |}
+           |
+           |dependencies {
+           |  compile group: '${group}', name: '${artifactId}', version: '${projectVersion}'
+           |}
+           |
+ |
+ |
+ |""".stripMargin + ) + } + } +}