asciidoctor / asciidoctor-extensions-lab

A lab for testing and demonstrating Asciidoctor extensions. Please do not use this code in production. If you want to use one of these extensions in your application, create a new project, import the code, and distribute it as a RubyGem. You can then request to make it a top-level project under the Asciidoctor organization.
Other
104 stars 101 forks source link

Extended the chart module to allow Pie charts / Added pom.xml to produce jar which is usable in asciidoctor-maven-plugin #76

Closed chrisdutz closed 4 years ago

chrisdutz commented 7 years ago

I usually build my presentations with Asciidoctor and Reveal.JS. Being a Maven Fan-Boy I usually use the asciidoctor-maven-plugin to build my presentations. For my current use-case I needed to add some charts and I was unable to find a working way to do this. So I reverse engineered the existing asciidoctor-maven-plugin extensions and created a pom.xml that produces jars that can be used the same way.

With this all you need to do, is add a dependency to the artifact and "require" the module you want to use (in my case this was: chart-block-macro

After finishing this, I noticed that I want Pie charts and these weren't supported yet, so I added C3JS support for pie charts while I was at it.

ggrossetie commented 7 years ago

Wow that's so nice! Could you please share with us a simple example on how you integrate it with asciidoctor-maven-plugin (ie. a sample pom.xml). I think we should definitely add a section on the README to explain how to integrate Asciidoctor extensions in a Maven build.

mojavelinux commented 7 years ago

Thank you for this contribution!

Can you take the gemspec and pom.xml out of the PR? If we add a gemspec, I'd like to handle that as a separate PR. The pom.xml belongs in a new submodule over here: https://github.com/asciidoctor/asciidoctor-maven-examples

Thanks!

chrisdutz commented 7 years ago

Gee I wonder why I didn't get any email notification for your comments. So what I'm really interested in, is to be able to use the extension in my maven builds. Would have to find out how to split this up into multiple PRs.

Right now all you need to do in order to add charts support to an existing asciidoctor configuration is to add one single dependency to the plugin config and to add the module you want to use to the require section. See this config from one of my projects:

         <plugin>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <version>${asciidoctor.maven.plugin.version}</version>
            <dependencies>
                <!-- Comment this section to use the default jruby artifact provided by the plugin -->
                <dependency>
                    <groupId>org.jruby</groupId>
                    <artifactId>jruby-complete</artifactId>
                    <version>${jruby.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.asciidoctor</groupId>
                    <artifactId>asciidoctorj</artifactId>
                    <version>${asciidoctorj.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.asciidoctor</groupId>
                    <artifactId>asciidoctorj-diagram</artifactId>
                    <version>${asciidoctorj.diagram.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.asciidoctor</groupId>
                    <artifactId>asciidoctorj-extensions-lab</artifactId>
                    <version>${asciidoctorj.extensions-lab.version}</version>
                    <!-- Referenced locally till it's officially released -->
                    <scope>system</scope>
                    <systemPath>${basedir}/libs/asciidoctorj-extensions-lab-${asciidoctorj.extensions-lab.version}.jar</systemPath>
                </dependency>
            </dependencies>
            <configuration>
                <sourceDirectory>src/docs/asciidoc</sourceDirectory>
                <requires>
                    <require>asciidoctor-diagram</require>
                    <require>chart-block-macro</require>
                </requires>
            </configuration>
            <executions>
                <execution>
                    <id>generate-slides</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>process-asciidoc</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.slides.directory}</outputDirectory>
                        <backend>revealjs</backend>
                        <templateDir>${project.build.directory}/asciidoctor-reveal.js-${asciidoctor-revealjs.version}/templates/slim</templateDir>
                        <sourceHighlighter>highlightjs</sourceHighlighter>
                        <attributes>
                            <!-- 
                                As we are downloading reveal.js in runtime, it sits in a nonstandard folder `reveal.js-${revealjs.version}`
                            -->
                            <revealjsdir>reveal.js-${revealjs.version}</revealjsdir>
                            <!-- put here the reveal.js specific attributes -->
                            <sourcedir>${basedir}/src/main/java</sourcedir>
                            <!-- this is the css defined in "src/main/theme" -->
                            <revealjs_theme>cc</revealjs_theme>
                            <revealjs_transition>linear</revealjs_transition>
                            <project-version>${project.version}</project-version>
                        </attributes>
                    </configuration>
                </execution>                    
            </executions>
        </plugin>
chrisdutz commented 7 years ago

And I don't quite think the pom.xml belongs to the maven examples. It doesn't demonstrate using the extensions lab with maven, it allows building it with maven. Right now there isn't a way to use the extensions-lab with maven at all. With the pom.xml in this PR it would be possible to create a maven compatable artifact which could be deployed to Maven central.

mojavelinux commented 5 years ago

With the pom.xml in this PR it would be possible to create a maven compatable artifact which could be deployed to Maven central.

That's not a direction I want to go with the extensions lab. These are definitely not meant to be published. If an extension is worthy of being published, it should be graduated to a dedicated repository with its own build for publishing.

That doesn't mean we have to have a project for each extension. Perhaps we can group some extensions together into a common extensions package. But it certainly wouldn't have the name "lab" associated with it. That name was selected intentionally to indicate that this is just experimental or demonstration code.

I definitely think it's time to graduate the chart extension to asciidoctor-chart (a parallel to asciidoctor-diagram).

mojavelinux commented 5 years ago

Would you be willing to split out your pie chart enhancement so that we can integrate that before graduating the code?

@Mogztter would you like me to create the asciidoctor-chart repository?

ggrossetie commented 4 years ago

@Mogztter would you like me to create the asciidoctor-chart repository?

@mojavelinux Yes please :wink:

mojavelinux commented 4 years ago

I have set up the asciidoctor-chart repo, imported the code, and included this patch. See https://github.com/asciidoctor/asciidoctor-chart

I have not verified that the code works in its current form, so it will need to be tested and possibly fixed.

mojavelinux commented 4 years ago

Note that https://github.com/mogztter/asciidoctor-chart probably needs to become asciidoctor-chart.js to avoid confusion.

ggrossetie commented 4 years ago

@mojavelinux for Asciidoctor Kroki, I've decided to put the Ruby and the JavaScript extensions in the same repository. But it's too soon to know if it's a good idea or bad idea :smile:

mojavelinux commented 4 years ago

@Mogztter I have no objection to that strategy. If it makes it simpler, I'm all for it. You have admin rights on asciidoctor-chart, so I'll leave it up to you to decide whether you want to merge the code in. Let me know if I can help in any way.