|
| 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"><repositories> |
| 55 | + | <repository> |
| 56 | + | <id>maven</id> |
| 57 | + | <url>${bintrayRepo}</url> |
| 58 | + | </repository> |
| 59 | + |</repositories> |
| 60 | + | |
| 61 | + |<dependencies> |
| 62 | + | <dependency> |
| 63 | + | <groupId>${group}</groupId> |
| 64 | + | <artifactId>${artifactId}</artifactId> |
| 65 | + | <version>${projectVersion}</version> |
| 66 | + | </dependency> |
| 67 | + |</dependencies> |
| 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