-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathParadoxSupport.scala
89 lines (83 loc) · 3.05 KB
/
ParadoxSupport.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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.bindings"
val artifactName = 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"><repositories>
| <repository>
| <id>maven</id>
| <url>${bintrayRepo}</url>
| </repository>
|</repositories>
|
|<dependencies>
| <dependency>
| <groupId>${group}</groupId>
| <artifactId>${artifactId}</artifactId>
| <version>${projectVersion}</version>
| </dependency>
|</dependencies>
|</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
)
}
}
}