Skip to content

Commit 2118de1

Browse files
committed
Fix #176: Add Paradox directive to show binding build tool integration
1 parent e5a9210 commit 2118de1

File tree

8 files changed

+94
-67
lines changed

8 files changed

+94
-67
lines changed

build.sbt

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ lazy val docsScalaNativeBindingsDirectory = settingKey[File]("wordcount source")
145145
lazy val docs = nativeProject("docs")
146146
.enablePlugins(GhpagesPlugin, ParadoxSitePlugin, ParadoxMaterialThemePlugin)
147147
.enablePlugins(ScalaNativeBindgenPlugin)
148+
.settings(
149+
org.scalanative.bindgen.build.ParadoxSupport.paradoxWithCustomDirectives)
148150
.settings(
149151
publish / skip := true,
150152
docsUsingBindingsDirectory := (Test / resourceDirectory).value / "using-bindings",

docs/src/paradox/bindings/iconv.md

+1-14
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,7 @@
22

33
To use this binding add the following resolver and the dependency:
44

5-
sbt
6-
: @@snip [build.sbt](../resources/build.sbt)
7-
8-
Maven
9-
: @@snip [pom.xml](../resources/pom.xml) { #library_resolver }
10-
11-
Gradle
12-
: @@snip [build.gradle](../resources/build.gradle)
13-
14-
@@dependency[sbt,Maven,Gradle] {
15-
group="org.scala-native.bindgen"
16-
artifact="libiconv_$scala.binary.version$"
17-
version="$project.version$"
18-
}
5+
@@binding[iconv]
196

207
The [`iconv.h`] header allows to convert text between different character sets, for example UTF-8 to ISO-8859-1.
218

docs/src/paradox/bindings/posix.md

+1-15
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,7 @@
22

33
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:
44

5-
sbt
6-
: @@snip [build.sbt](../resources/build.sbt)
7-
8-
Maven
9-
: @@snip [pom.xml](../resources/pom.xml) { #library_resolver }
10-
11-
Gradle
12-
: @@snip [build.gradle](../resources/build.gradle)
13-
14-
15-
@@dependency[sbt,Maven,Gradle] {
16-
group="org.scala-native.bindgen"
17-
artifact="libposix_$scala.binary.version$"
18-
version="$project.version$"
19-
}
5+
@@binding[posix]
206

217
Binding objects are available under the package name `
228

docs/src/paradox/bindings/utf8proc.md

+1-14
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,7 @@ This binding for [`utf8proc.h`] provides Unicode normalization, case-folding, an
44

55
To use it add the following resolver and the dependency:
66

7-
sbt
8-
: @@snip [build.sbt](../resources/build.sbt)
9-
10-
Maven
11-
: @@snip [pom.xml](../resources/pom.xml) { #library_resolver }
12-
13-
Gradle
14-
: @@snip [build.gradle](../resources/build.gradle)
15-
16-
@@dependency[sbt,Maven,Gradle] {
17-
group="org.scala-native.bindgen"
18-
artifact="libutf8proc_$scala.binary.version$"
19-
version="$project.version$"
20-
}
7+
@@binding[utf8proc]
218

229
## Example
2310

docs/src/paradox/resources/build.gradle

-5
This file was deleted.

docs/src/paradox/resources/build.sbt

-1
This file was deleted.

docs/src/paradox/resources/pom.xml

-18
This file was deleted.

project/ParadoxSupport.scala

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.scalanative.bindgen.build
2+
3+
import com.lightbend.paradox.markdown._
4+
import com.lightbend.paradox.sbt.ParadoxPlugin.autoImport.paradoxDirectives
5+
import org.pegdown.Printer
6+
import org.pegdown.ast.{DirectiveNode, TextNode, Visitor}
7+
import scala.collection.JavaConverters._
8+
9+
object ParadoxSupport {
10+
val paradoxWithCustomDirectives = Seq(
11+
paradoxDirectives ++= Seq(
12+
{ context: Writer.Context
13+
new BindingDependencyDirective(context.location.tree.label,
14+
context.properties)
15+
}
16+
)
17+
)
18+
19+
/* Based on the DependencyDirective from Paradox. */
20+
case class BindingDependencyDirective(page: Page,
21+
variables: Map[String, String])
22+
extends LeafBlockDirective("binding") {
23+
val projectVersion = variables("project.version")
24+
val scalaBinaryVersion = variables("scala.binary.version")
25+
26+
def render(node: DirectiveNode,
27+
visitor: Visitor,
28+
printer: Printer): Unit = {
29+
node.contentsNode.getChildren.asScala.headOption match {
30+
case Some(text: TextNode) =>
31+
renderBindingDependency(text.getText, printer)
32+
case _ => node.contentsNode.accept(visitor)
33+
}
34+
}
35+
36+
def renderBindingDependency(binding: String, printer: Printer): Unit = {
37+
val group = "org.scala-native.bindgen"
38+
val artifactName = s"lib$binding"
39+
val artifactId = s"${artifactName}_native0.3_${scalaBinaryVersion}"
40+
val bintrayRepo = "http://dl.bintray.com/scala-native-bindgen/maven"
41+
42+
printer.print(
43+
s"""
44+
|<dl>
45+
|<dt>sbt</dt>
46+
|<dd>
47+
|<pre class="prettyprint"><code class="language-scala">resolvers += Resolver.bintrayRepo("scala-native-bindgen", "maven")
48+
|libraryDependencies += "${group}" %%% "${artifactName}" % "${projectVersion}"
49+
|</code></pre>
50+
|</dd>
51+
|
52+
|<dt>Maven</dt>
53+
|<dd>
54+
|<pre class="prettyprint"><code class="language-xml">&lt;repositories&gt;
55+
| &lt;repository&gt;
56+
| &lt;id&gt;maven&lt;/id&gt;
57+
| &lt;url&gt;${bintrayRepo}&lt;/url&gt;
58+
| &lt;/repository&gt;
59+
|&lt;/repositories&gt;
60+
|
61+
|&lt;dependencies&gt;
62+
| &lt;dependency&gt;
63+
| &lt;groupId&gt;${group}&lt;/groupId&gt;
64+
| &lt;artifactId&gt;${artifactId}&lt;/artifactId&gt;
65+
| &lt;version&gt;${projectVersion}&lt;/version&gt;
66+
| &lt;/dependency&gt;
67+
|&lt;/dependencies&gt;
68+
|</code></pre>
69+
|</dd>
70+
|
71+
|<dt>Gradle</dt>
72+
|<dd>
73+
|<pre class="prettyprint"><code class="language-gradle">repositories {
74+
| maven {
75+
| url "${bintrayRepo}"
76+
| }
77+
|}
78+
|
79+
|dependencies {
80+
| compile group: '${group}', name: '${artifactId}', version: '${projectVersion}'
81+
|}
82+
|</code></pre>
83+
|</dd>
84+
|</dl>
85+
|""".stripMargin
86+
)
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)