Skip to content

Commit

Permalink
Merge pull request #745 from cstuht/revealjs-5
Browse files Browse the repository at this point in the history
Upgrade reveal.js to version 5.1.0
  • Loading branch information
ysb33r authored Dec 30, 2024
2 parents 471a9ab + 066d278 commit 4a9154b
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 90 deletions.
67 changes: 65 additions & 2 deletions docs/modules/ROOT/pages/asciidoctorj-revealjs-plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ The version of the Reveal.js GEM and the Reveal.js template is configured via th
[source,groovy]
----
revealjs {
version = '1.1.3' // <1>
version = '5.1.0' // <1>
templateGitHub { // <2>
organisation = 'hakimel'
repository = 'reveal.js'
tag = '3.7.0'
tag = '5.1.0'
}
}
----
Expand Down Expand Up @@ -122,3 +122,66 @@ verticalCenter:: Vertical centering of slides.
Type is boolean.
viewDistance:: Number of slides away from the current that are visible.
Type is integer.

[[RevealJsPlugins]]
== Reveal.js Plugins

To add additional Reveal.js plugins declare the source in the `revealjsPlugins` block:

[source,groovy,role="primary"]
.build.gradle
----
revealjsPlugins {
github("rajgoel") {
setOrganisation("rajgoel")
setRepository("reveal.js-plugins")
setBranch("master")
}
github("denehyg") {
setOrganisation("denehyg")
setRepository("reveal.js-menu")
setBranch("master")
}
}
----

[source,kotlin,role="secondary"]
.build.gradle.kts
----
revealjsPlugins {
github("rajgoel") {
setOrganisation("rajgoel")
setRepository("reveal.js-plugins")
setBranch("master")
}
github("denehyg") {
setOrganisation("denehyg")
setRepository("reveal.js-menu")
setBranch("master")
}
}
----

The Reveal.js plugins referenced in the `asciidoctorRevealJs` will be downloaded and copied to the Reveal.js plugins folder:

[source,groovy,role="primary"]
----
asciidoctorRevealJs {
plugins 'rajgoel/chalkboard', 'denehyg/menu'
}
----

[source,kotlin,role="secondary"]
----
asciidoctorRevealJs {
plugins("rajgoel/chalkboard", "denehyg/menu")
}
----

The Reveal.js plugins are be registered and configured by <<docinfo.adoc#docinfo>> files.

See https://docs.asciidoctor.org/reveal.js-converter/latest/converter/revealjs-plugins/[reveal.js Plugins] in https://docs.asciidoctor.org/reveal.js-converter/latest/[Asciidoctor reveal.js Documentation] for an example.

NOTE: You have to adopt the plugin links in the docinfo file from `revealjs-plugins/` to `reveal.js/plugin/`.
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/docinfo.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[[docinfo]]
= Extra content for HTML & Docbook backends

You may need to include extra content into the head of the exported document.
Expand Down
3 changes: 1 addition & 2 deletions jvm-slides/src/gradleTest/basic-slides/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ asciidoctorRevealJs {
}

plugins 'rajgoel/chart/Chart.js'
// pluginConfigurationFile 'src/docs/asciidoc/empty-plugin-configuration.js'

toggleBuiltinPlugin 'pdf', true
toggleBuiltinPlugin 'search', true
toggleBuiltinPlugin 'notes', false
}
// end::revealjs-basics[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ class AsciidoctorRevealJSTaskCachingFunctionalSpec extends FunctionalSpecificati
asciidoctorRevealJs {
plugins 'rajgoel/chart/Chart.js'
pluginConfigurationFile 'src/docs/asciidoc/empty-plugin-configuration.js'
toggleBuiltinPlugin 'pdf', true
toggleBuiltinPlugin 'notes', false
toggleBuiltinPlugin 'search', false
toggleBuiltinPlugin 'notes', true
}
''')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AsciidoctorRevealJSTaskFunctionalSpec extends FunctionalSpecification {
new File(projectDir, 'build/docs/asciidocRevealJs/revealjs.html').exists()
new File(projectDir, 'build/docs/asciidocRevealJs/subdir/revealjs2.html').exists()
new File(projectDir, "${DEFAULT_REVEALJS_PATH}/css").exists()
new File(projectDir, "${DEFAULT_REVEALJS_PATH}/lib").exists()
new File(projectDir, "${DEFAULT_REVEALJS_PATH}/dist").exists()
new File(projectDir, "${DEFAULT_REVEALJS_PATH}/plugin").exists()
new File(projectDir, "${DEFAULT_REVEALJS_PATH}/js").exists()
}
Expand All @@ -54,7 +54,7 @@ class AsciidoctorRevealJSTaskFunctionalSpec extends FunctionalSpecification {
templateGitHub {
organisation = 'hakimel'
repository = 'reveal.js'
tag = '3.6.0'
tag = '5.1.0'
}
}
''')
Expand All @@ -65,9 +65,10 @@ class AsciidoctorRevealJSTaskFunctionalSpec extends FunctionalSpecification {
then:
verifyAll {
new File(projectDir, 'build/docs/asciidocRevealJs/revealjs.html').exists()
new File(projectDir, 'build/github-cache/hakimel/reveal.js/3.6.0').exists()
new File(projectDir, 'build/github-cache/hakimel/reveal.js/5.1.0').exists()
new File(projectDir, "${DEFAULT_REVEALJS_PATH}/dist").exists()
new File(projectDir, "${DEFAULT_REVEALJS_PATH}/js/reveal.js").
text.contains('var VERSION = \'3.6.0\';')
text.contains('export const VERSION = \'5.1.0\';')
}
}

Expand All @@ -85,25 +86,24 @@ class AsciidoctorRevealJSTaskFunctionalSpec extends FunctionalSpecification {
asciidoctorRevealJs {
plugins 'rajgoel/chart/plugin.js'
pluginConfigurationFile 'src/docs/asciidoc/empty-plugin-configuration.js'
toggleBuiltinPlugin 'pdf', true
toggleBuiltinPlugin 'search', true
toggleBuiltinPlugin 'notes', false
}
''')

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

then:
verifyAll {
!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/plugin.js'")
revealjsHtml.contains(pluginConfig)
!revealjsHtml.contains('plugin/notes')
revealjsHtml.contains("src: '${REVEALJS_DIR_NAME}/plugin/search/search.js'")
// plugins must be registered using presentation-docinfo-footer,
// see https://docs.asciidoctor.org/reveal.js-converter/5.0/converter/revealjs-plugins/#additional-plugins
// revealjsHtml.contains("src: '${REVEALJS_DIR_NAME}/plugin/rajgoel/chart/plugin.js'")
new File(projectDir, "${DEFAULT_REVEALJS_PATH}/plugin/rajgoel/chart/plugin.js").exists()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ import static org.gradle.api.tasks.PathSensitivity.RELATIVE
@CompileStatic
class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask implements SlidesToExportAware {

public static final String PLUGIN_LIST_FILENAME = 'revealjs-plugins.js'
public final static String REVEALJS_GEM = 'asciidoctor-revealjs'

private static final String BACKEND_NAME = 'revealjs'

private Object templateRelativeDir = 'reveal.js'
private String theme = 'white'
private Object pluginConfigurationFile
private final Map<String, Boolean> builtinPlugins = [:]
private final List<Object> requiredPlugins = []

Expand All @@ -77,9 +75,6 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask implements Slides
inputs.file( { RevealJSOptions opt -> opt.highlightJsThemeIfFile }.curry(this.revealjsOptions) ).optional()
inputs.file( { RevealJSOptions opt -> opt.parallaxBackgroundImageIfFile }.
curry(this.revealjsOptions) ).optional()

// support cleanupPluginTempFiles() in exec()
awaitMode = true
}

/** Options for Reveal.JS slides.
Expand Down Expand Up @@ -219,25 +214,6 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask implements Slides
this.builtinPlugins.put(name, pluginState)
}

/** Returns the location of the file for configuring external plugins.
*
* @return Location of file. Can be {@code null}
*/
@Optional
@InputFile
@PathSensitive(RELATIVE)
File getPluginConfigurationFile() {
this.pluginConfigurationFile ? project.file(this.pluginConfigurationFile) : null
}

/** Sets the location of the project configuration file.
*
* @param f Location of the configuration file
*/
void setPluginConfigurationFile(Object f) {
this.pluginConfigurationFile = f
}

@Internal
@Override
Profile getProfile() {
Expand All @@ -249,7 +225,6 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask implements Slides
checkRevealJsVersion()
processTemplateResources()
super.exec()
cleanupPluginTempFiles()
}

/** A task may add some default attributes.
Expand Down Expand Up @@ -281,13 +256,7 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask implements Slides
)
}

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

if (getPluginConfigurationFile() != null) {
attrs.put 'revealjs_plugins_configuration', getPluginConfigurationFile().absolutePath
}
}
// 'revealjs_plugins not supported by asciidoctor-revealjs >= 5.0
}

attrs
Expand Down Expand Up @@ -334,15 +303,6 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask implements Slides
}
}
})

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

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

@Internal
Expand All @@ -351,22 +311,10 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask implements Slides
}

@Internal
protected RevealJSPluginExtension getRevealsjsPluginExtension() {
protected RevealJSPluginExtension getRevealjsPluginExtension() {
project.extensions.getByType(RevealJSPluginExtension)
}

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

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

targetFile.withWriter { Writer w ->
w.println pluginList
}
}

private void checkRevealJsVersion() {
if (!pluginSupportAvailable) {
project.logger.warn("You are using Reveal.Js converter version ${revealjsExtension.version}, " +
Expand All @@ -378,10 +326,6 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask implements Slides
Version.of(revealjsExtension.version) >= FIRST_VERSION_WITH_PLUGIN_SUPPORT
}

private File getPluginListFile() {
new File(templateDir, PLUGIN_LIST_FILENAME)
}

private Set<String> getPluginBundles() {
Transform.toSet(plugins) {
it.split('/', 2)[0]
Expand All @@ -390,7 +334,7 @@ class AsciidoctorJRevealJSTask extends AbstractAsciidoctorTask implements Slides

private Set<ResolvedRevealJSPlugin> getResolvedPlugins() {
if (pluginSupportAvailable) {
final RevealJSPluginExtension pluginExtension = revealsjsPluginExtension
final RevealJSPluginExtension pluginExtension = revealjsPluginExtension
Transform.toSet(pluginBundles) {
pluginExtension.getByName(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ class RevealJSPluginExtension extends AbstractDownloadableComponent<LocalRevealJ

public final static String NAME = 'revealjsPlugins'

@SuppressWarnings('ClassName')
static class ResolvedLocalRevealJsPlguin implements ResolvedRevealJSPlugin {
final File location
final String name

ResolvedLocalRevealJsPlguin(final File location, final String name) {
this.location = location
this.name = name
}
}

RevealJSPluginExtension(Project project) {
super(project)
}
Expand Down
4 changes: 2 additions & 2 deletions module-versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ asciidoctorjs=4.0.0
asciidoctorjs.docbook=3.0.0-beta.1

# revealjs-extension
revealjs.gem=2.0.0
revealjs.template=3.8.0
revealjs.gem=5.1.0
revealjs.template=5.1.0

# kindlegen-extension
kindlegen=2_9
Expand Down

0 comments on commit 4a9154b

Please sign in to comment.