Skip to content

Commit

Permalink
Upgrade to reveal.js 2.0 and activate plugin support (asciidoctor#330,a…
Browse files Browse the repository at this point in the history
  • Loading branch information
ysb33r committed Apr 10, 2019
1 parent 20e7c4e commit 03acad7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ package org.asciidoctor.gradle.jvm.slides
import org.asciidoctor.gradle.jvm.slides.internal.FunctionalSpecification
import org.asciidoctor.gradle.testfixtures.jvm.JRubyTestVersions
import org.gradle.testkit.runner.BuildResult
import spock.lang.PendingFeature

@SuppressWarnings(['DuplicateStringLiteral', 'DuplicateListLiteral'])
class AsciidoctorRevealJSTaskFunctionalSpec extends FunctionalSpecification {

final static String JRUBY_TEST_VERSION = JRubyTestVersions.AJ16_SAFE_MAXIMUM
final static String REVEALJS_DIR_NAME = 'reveal.js'
final static String DEFAULT_REVEALJS_PATH = "build/docs/asciidocRevealJs/${REVEALJS_DIR_NAME}"

void setup() {
createTestProject('revealjs')
Expand All @@ -39,10 +40,10 @@ class AsciidoctorRevealJSTaskFunctionalSpec extends FunctionalSpecification {
then:
verifyAll {
new File(testProjectDir.root, 'build/docs/asciidocRevealJs/revealjs.html').exists()
new File(testProjectDir.root, 'build/docs/asciidocRevealJs/reveal.js/css').exists()
new File(testProjectDir.root, 'build/docs/asciidocRevealJs/reveal.js/lib').exists()
new File(testProjectDir.root, 'build/docs/asciidocRevealJs/reveal.js/plugin').exists()
new File(testProjectDir.root, 'build/docs/asciidocRevealJs/reveal.js/js').exists()
new File(testProjectDir.root, "${DEFAULT_REVEALJS_PATH}/css").exists()
new File(testProjectDir.root, "${DEFAULT_REVEALJS_PATH}/lib").exists()
new File(testProjectDir.root, "${DEFAULT_REVEALJS_PATH}/plugin").exists()
new File(testProjectDir.root, "${DEFAULT_REVEALJS_PATH}/js").exists()
}
}

Expand All @@ -66,12 +67,11 @@ class AsciidoctorRevealJSTaskFunctionalSpec extends FunctionalSpecification {
verifyAll {
new File(testProjectDir.root, 'build/docs/asciidocRevealJs/revealjs.html').exists()
new File(testProjectDir.root, 'build/github-cache/hakimel/reveal.js/3.6.0').exists()
new File(testProjectDir.root, 'build/docs/asciidocRevealJs/reveal.js/js/reveal.js').text.contains('var VERSION = \'3.6.0\';')
new File(testProjectDir.root, "${DEFAULT_REVEALJS_PATH}/js/reveal.js").text.contains('var VERSION = \'3.6.0\';')
}
}

// Only supported with reveal.js > 1.1.3
@PendingFeature
void 'Run a revealJS generator with plugins'() {
given:
getBuildFile('''
Expand All @@ -93,21 +93,21 @@ class AsciidoctorRevealJSTaskFunctionalSpec extends FunctionalSpecification {

when:
build()
File revealjsHtml = new File(testProjectDir.root, 'build/docs/asciidocRevealJs/revealjs.html')
File pluginList = new File(testProjectDir.root, 'build/docs/asciidocRevealJs/reveal.js/revealjs-plugins.js')
File pluginConfig = new File(testProjectDir.root, 'build/docs/asciidocRevealJs/reveal.js/revealjs-plugin-configuration.js')
String revealjsHtml = new File(testProjectDir.root, 'build/docs/asciidocRevealJs/revealjs.html').text
String pluginConfig = new File(testProjectDir.root, 'src/docs/asciidoc/empty-plugin-configuration.js').text
File pluginList = new File(testProjectDir.root, "${DEFAULT_REVEALJS_PATH}/revealjs-plugins.js")

then:
verifyAll {
!revealjsHtml.text.contains("src: 'reveal.js/plugin/notes/notes.js'")
revealjsHtml.text.contains("src: 'reveal.js/plugin/print-pdf/print-pdf.js'")
pluginList.text.contains('reveal.js/plugin/rajgoel/chart/Chart.js')
pluginConfig.exists()
new File(testProjectDir.root, 'build/docs/asciidocRevealJs/reveal.js/plugin/rajgoel/chart/Chart.js').exists()
!pluginList.exists()
!revealjsHtml.contains('plugin/notes/notes')
revealjsHtml.contains("src: '${REVEALJS_DIR_NAME}/plugin/print-pdf/")
revealjsHtml.contains("src: '${REVEALJS_DIR_NAME}/plugin/rajgoel/chart/Chart.js'")
revealjsHtml.contains(pluginConfig)
new File(testProjectDir.root, "${DEFAULT_REVEALJS_PATH}/plugin/rajgoel/chart/Chart.js").exists()
}
}


@SuppressWarnings('FactoryMethodName')
BuildResult build() {
getGradleRunner(['asciidoctorRevealJs', '-s']).build()
Expand Down Expand Up @@ -145,13 +145,4 @@ class AsciidoctorRevealJSTaskFunctionalSpec extends FunctionalSpecification {

}

// /** Adds files to a {@link CopySpec} for copying to final artifact.
// *
// * @param cs CopySpec to enhance.
// */
// void enhanceCopySpec(CopySpec cs) {
// copyActionFor(cs, parallaxBackgroundImageIfFile, getParallaxBackgroundImageRelativePath())
// copyActionFor(cs, highlightJsThemeLocationIfFile, getHighlightJsThemeRelativePath())
// copyActionFor(cs, customThemeLocationIfFile, getCustomThemeRelativePath())


Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ import org.asciidoctor.gradle.base.Transform
import org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask
import org.gradle.api.Action
import org.gradle.api.file.CopySpec
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory

@java.lang.SuppressWarnings('NoWildcardImports')
import org.gradle.api.tasks.*
import org.gradle.workers.WorkerExecutor
import org.ysb33r.grolifant.api.StringUtils
import org.ysb33r.grolifant.api.Version
Expand Down Expand Up @@ -229,6 +225,7 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask {
checkRevealJsVersion()
processTemplateResources()
super.processAsciidocSources()
cleanupPluginTempFiles()
}

/** A task may add some default attributes.
Expand All @@ -246,33 +243,36 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask {
Map<String, Object> attrs = super.getTaskSpecificDefaultAttributes(workingSourceDir)

attrs.putAll revealjsdir: getTemplateRelativeDir(),
revealjs_theme: getTheme()
revealjs_theme: getTheme(),
'source-highlighter': 'highlightjs'

attrs.putAll revealjsOptions.asAttributeMap

if(pluginSupportAvailable) {
if (pluginSupportAvailable) {
this.builtinPlugins.each { String pluginName, Boolean state ->
attrs.put "revealjs_plugins_${pluginName}".toString(), state.toString()
attrs.put(
"revealjs_plugin_${pluginName}".toString(),
(state ? 'enabled' : 'disabled')
)
}

if (!requiredPlugins.empty) {
attrs.put 'revealjs_plugins', pluginListLocation
attrs.put 'revealjs_plugins', pluginListFile.absolutePath

if (getPluginConfigurationFile() != null) {
attrs.put 'revealjs_plugins_configuration', pluginConfigurationLocation
attrs.put 'revealjs_plugins_configuration', getPluginConfigurationFile().absolutePath
}
}
}

attrs.put 'source-highlighter', 'highlightjs'
attrs
}

/** Gets the CopySpec for additional resources
* Enhances the default operation from {@link AbstractAsciidoctorTask#getResourceCopySpec}
* to also include any custom background images and themes.
*
* @return A {@link CopySpec}. Never {@code null}.
* @return A{@link CopySpec}. Never {@code null}.
*/
@Override
protected CopySpec getResourceCopySpec() {
Expand All @@ -291,7 +291,6 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask {
final File fromSource = templateSourceDir
final File target = templateDir
final Set<ResolvedRevealJSPlugin> fromPlugins = resolvedPlugins
final File configLocation = getPluginConfigurationFile()

project.copy(new Action<CopySpec>() {
@Override
Expand All @@ -307,21 +306,19 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask {
cs.into "plugin/${plugin.name}"
}
}

if(!fromPlugins.empty && configLocation != null) {
copySpec.from configLocation, { CopySpec cs ->
cs.rename( configLocation.name, PLUGIN_CONFIGURATION_FILENAME )
}
}
}
})

if(!fromPlugins.empty) {
final String relativePath = pluginListLocation
generatePluginList(new File(target,relativePath),relativePath)
if (!fromPlugins.empty) {
final String relativePathForPlugins = "${templateRelativeDir}/plugin"
generatePluginList(pluginListFile, relativePathForPlugins)
}
}

private void cleanupPluginTempFiles() {
pluginListFile.delete()
}

@Internal
protected RevealJSExtension getRevealjsExtension() {
project.extensions.getByType(RevealJSExtension)
Expand All @@ -332,11 +329,11 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask {
project.extensions.getByType(RevealJSPluginExtension)
}

private void generatePluginList(File targetFile,String relativePath) {
private void generatePluginList(File targetFile, String relativePathForPlugins) {
targetFile.parentFile.mkdirs()

String pluginList = Transform.toList(plugins,{ String fullName ->
"{ src: '${relativePath}/${fullName}' }"
String pluginList = Transform.toList(plugins, { String fullName ->
"{ src: '${relativePathForPlugins}/${fullName}' }"
}).join(',\n')

targetFile.withWriter { Writer w ->
Expand All @@ -345,7 +342,7 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask {
}

private void checkRevealJsVersion() {
if(!pluginSupportAvailable) {
if (!pluginSupportAvailable) {
project.logger.warn("You are using Reveal.Js converter version ${revealjsExtension.version}, which does not support plugins. Any plugin settings will be ignored.")
}
}
Expand All @@ -354,12 +351,8 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask {
Version.of(revealjsExtension.version) >= FIRST_VERSION_WITH_PLUGIN_SUPPORT
}

private String getPluginListLocation() {
"${templateRelativeDir}/${PLUGIN_LIST_FILENAME}"
}

private String getPluginConfigurationLocation() {
"${templateRelativeDir}/${PLUGIN_CONFIGURATION_FILENAME}"
private File getPluginListFile() {
new File(templateDir, PLUGIN_LIST_FILENAME)
}

private Set<String> getPluginBundles() {
Expand All @@ -369,13 +362,13 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask {
}

private Set<ResolvedRevealJSPlugin> getResolvedPlugins() {
if(isPluginSupportAvailable()) {
if (isPluginSupportAvailable()) {
final RevealJSPluginExtension pluginExtension = revealsjsPluginExtension
pluginBundles.collect {
pluginExtension.getByName(it)
} as Set
} else {
[] as Set
[].toSet()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RevealJSExtension {

final static String NAME = 'revealjs'
final static String DEFAULT_VERSION = '2.0.0'
final static String DEFAULT_TEMPLATE_VERSION = '3.7.0'
final static String DEFAULT_TEMPLATE_VERSION = '3.8.0'
final static Version FIRST_VERSION_WITH_PLUGIN_SUPPORT = Version.of('2.0.0')

private String version = DEFAULT_VERSION
Expand Down

0 comments on commit 03acad7

Please sign in to comment.