in project/AsciidocPlugin.scala [41:84]
override def projectSettings = asciidoctorSettings(Asciidoc)
/** Creates settings necessary for running Asciidoctor in the given configuration. */
def asciidoctorSettings(config: Configuration): Seq[Setting[_]] =
inConfig(config)(
Seq(
includeFilter := AllPassFilter,
unmanagedSources := (sourceDirectory.value ** "*.adoc").get,
managedSources := Seq(),
sources := unmanagedSources.value ++ managedSources.value,
siteProperties := Seq("project-version" -> version.value),
mappings := generate(sources.value, target.value, includeFilter.value, siteProperties.value),
siteSubdirName := ""
)
) ++
SiteHelpers.directorySettings(config) ++
SiteHelpers.watchSettings(config) ++
SiteHelpers.addMappingsToSiteDir(mappings in config, siteSubdirName in config)
/** Run asciidoctor in new ClassLoader. */
private def generate(inputs: Seq[File], outputDirectory: File, includeFilter: FileFilter, props: Seq[(String, AnyRef)])
: Seq[(File, String)] = {
val oldContextClassLoader = Thread.currentThread().getContextClassLoader
Thread.currentThread().setContextClassLoader(this.getClass.getClassLoader)
try {
val asciidoctor = Factory.create()
if (!outputDirectory.exists()) outputDirectory.mkdirs()
val options = new Options
options.setToDir(outputDirectory.getAbsolutePath)
options.setDestinationDir(outputDirectory.getAbsolutePath)
options.setSafe(SafeMode.UNSAFE)
// need to do this explicitly through HashMap because otherwise JRuby complains
val attributes = new util.HashMap[String, AnyRef]
for ((key, value) <- props) attributes.put(key, value)
options.setAttributes(attributes)
val walker = new DirectoryWalker {
override def scan(): util.List[File] = inputs.asJava
}
asciidoctor.renderDirectory(walker, options)
} finally {
Thread.currentThread().setContextClassLoader(oldContextClassLoader)
}
outputDirectory ** includeFilter --- outputDirectory pair Path.relativeTo(outputDirectory)
}