diff --git a/asciidoctor-gradle-jvm-slides/src/intTest/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorRevealJSTaskFunctionalSpec.groovy b/asciidoctor-gradle-jvm-slides/src/intTest/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorRevealJSTaskFunctionalSpec.groovy index 030c4794a..494d07009 100644 --- a/asciidoctor-gradle-jvm-slides/src/intTest/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorRevealJSTaskFunctionalSpec.groovy +++ b/asciidoctor-gradle-jvm-slides/src/intTest/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorRevealJSTaskFunctionalSpec.groovy @@ -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') @@ -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() } } @@ -65,13 +66,12 @@ class AsciidoctorRevealJSTaskFunctionalSpec extends FunctionalSpecification { then: 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, "build/github-cache/hakimel/reveal.js/3.6.0").exists() + 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(''' @@ -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() @@ -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()) - diff --git a/asciidoctor-gradle-jvm-slides/src/main/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorJRevealJSTask.groovy b/asciidoctor-gradle-jvm-slides/src/main/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorJRevealJSTask.groovy index 01af324da..b67fa0d7a 100644 --- a/asciidoctor-gradle-jvm-slides/src/main/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorJRevealJSTask.groovy +++ b/asciidoctor-gradle-jvm-slides/src/main/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorJRevealJSTask.groovy @@ -21,13 +21,7 @@ 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 +import org.gradle.api.tasks.* import org.gradle.workers.WorkerExecutor import org.ysb33r.grolifant.api.StringUtils import org.ysb33r.grolifant.api.Version @@ -229,6 +223,7 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask { checkRevealJsVersion() processTemplateResources() super.processAsciidocSources() + cleanupPluginTempFiles() } /** A task may add some default attributes. @@ -246,25 +241,28 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask { Map 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 } @@ -272,7 +270,7 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask { * 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() { @@ -307,21 +305,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) @@ -332,11 +328,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 -> @@ -345,7 +341,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.") } } @@ -354,8 +350,8 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask { Version.of(revealjsExtension.version) >= FIRST_VERSION_WITH_PLUGIN_SUPPORT } - private String getPluginListLocation() { - "${templateRelativeDir}/${PLUGIN_LIST_FILENAME}" + private File getPluginListFile() { + new File(templateDir, PLUGIN_LIST_FILENAME) } private String getPluginConfigurationLocation() { @@ -369,13 +365,13 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask { } private Set getResolvedPlugins() { - if(isPluginSupportAvailable()) { + if (isPluginSupportAvailable()) { final RevealJSPluginExtension pluginExtension = revealsjsPluginExtension pluginBundles.collect { pluginExtension.getByName(it) } as Set } else { - [] as Set + [].toSet() } } } diff --git a/asciidoctor-gradle-jvm-slides/src/main/groovy/org/asciidoctor/gradle/jvm/slides/RevealJSExtension.groovy b/asciidoctor-gradle-jvm-slides/src/main/groovy/org/asciidoctor/gradle/jvm/slides/RevealJSExtension.groovy index 727d6c099..27b5bfcfb 100644 --- a/asciidoctor-gradle-jvm-slides/src/main/groovy/org/asciidoctor/gradle/jvm/slides/RevealJSExtension.groovy +++ b/asciidoctor-gradle-jvm-slides/src/main/groovy/org/asciidoctor/gradle/jvm/slides/RevealJSExtension.groovy @@ -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 diff --git a/asciidoctor-gradle-jvm-slides/src/test/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorRevealJSPluginSpec.groovy b/asciidoctor-gradle-jvm-slides/src/test/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorRevealJSPluginSpec.groovy index 8aee6df12..1f61f7fec 100644 --- a/asciidoctor-gradle-jvm-slides/src/test/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorRevealJSPluginSpec.groovy +++ b/asciidoctor-gradle-jvm-slides/src/test/groovy/org/asciidoctor/gradle/jvm/slides/AsciidoctorRevealJSPluginSpec.groovy @@ -52,7 +52,7 @@ class AsciidoctorRevealJSPluginSpec extends Specification { } and: 'Revels.js Asciiidoctor task is configured' - tasks.getByName(REVEALJS_TASK).templateRelativeDir == 'reveal.js' + tasks.getByName(REVEALJS_TASK).templateRelativeDir == 'template-reveal.js' tasks.getByName(REVEALJS_TASK).outputDir == project.file("${project.buildDir}/docs/asciidocRevealJs") tasks.getByName(REVEALJS_TASK).dependsOn.find { it instanceof AsciidoctorGemPrepare }