-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from scala-native/binding-artifact-id
Fix #176: Add Paradox directive to show binding build tool integration
- Loading branch information
Showing
8 changed files
with
94 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"><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 | ||
) | ||
} | ||
} | ||
} |