Skip to content

Commit

Permalink
Merge pull request #186 from scala-native/binding-artifact-id
Browse files Browse the repository at this point in the history
Fix #176: Add Paradox directive to show binding build tool integration
  • Loading branch information
kornilova203 authored Sep 7, 2018
2 parents e5a9210 + 0351ff5 commit c42019e
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 67 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 1 addition & 14 deletions docs/src/paradox/bindings/iconv.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 1 addition & 15 deletions docs/src/paradox/bindings/posix.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `

Expand Down
15 changes: 1 addition & 14 deletions docs/src/paradox/bindings/utf8proc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions docs/src/paradox/resources/build.gradle

This file was deleted.

1 change: 0 additions & 1 deletion docs/src/paradox/resources/build.sbt

This file was deleted.

18 changes: 0 additions & 18 deletions docs/src/paradox/resources/pom.xml

This file was deleted.

89 changes: 89 additions & 0 deletions project/ParadoxSupport.scala
Original file line number Diff line number Diff line change
@@ -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"""
|<dl>
|<dt>sbt</dt>
|<dd>
|<pre class="prettyprint"><code class="language-scala">resolvers += Resolver.bintrayRepo("scala-native-bindgen", "maven")
|libraryDependencies += "${group}" %%% "${artifactName}" % "${projectVersion}"
|</code></pre>
|</dd>
|
|<dt>Maven</dt>
|<dd>
|<pre class="prettyprint"><code class="language-xml">&lt;repositories&gt;
| &lt;repository&gt;
| &lt;id&gt;maven&lt;/id&gt;
| &lt;url&gt;${bintrayRepo}&lt;/url&gt;
| &lt;/repository&gt;
|&lt;/repositories&gt;
|
|&lt;dependencies&gt;
| &lt;dependency&gt;
| &lt;groupId&gt;${group}&lt;/groupId&gt;
| &lt;artifactId&gt;${artifactId}&lt;/artifactId&gt;
| &lt;version&gt;${projectVersion}&lt;/version&gt;
| &lt;/dependency&gt;
|&lt;/dependencies&gt;
|</code></pre>
|</dd>
|
|<dt>Gradle</dt>
|<dd>
|<pre class="prettyprint"><code class="language-gradle">repositories {
| maven {
| url "${bintrayRepo}"
| }
|}
|
|dependencies {
| compile group: '${group}', name: '${artifactId}', version: '${projectVersion}'
|}
|</code></pre>
|</dd>
|</dl>
|""".stripMargin
)
}
}
}

0 comments on commit c42019e

Please sign in to comment.