Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some example in README don't match implementation #14

Open
ysb33r opened this issue Jun 28, 2017 · 5 comments
Open

Some example in README don't match implementation #14

ysb33r opened this issue Jun 28, 2017 · 5 comments

Comments

@ysb33r
Copy link
Member

ysb33r commented Jun 28, 2017

  • README says inline_macro, but to get things to work one has to call inlinemacro instead.
  • block_macro does not work at all. Keeps coming back with an error saying blockMacro (not capitalization) not found. Was using the verson of the groocy-dsl that ships with the 1.5.3. version of the Gradle plugin for Asciidoctor.
  • docinfoprocessor does not document how to apply to head or footer.
@ysb33r
Copy link
Member Author

ysb33r commented Jun 28, 2017

Here are some examples related to docinfoprocessor which don't work.

This is what one would expect per documentation

docinfo_processor { document ->
      '<div>FOOBAR</div>'
}

Error is

Could not find method docinfo_processor() for arguments [build_35iwvdrdnszm23y6o4g0onhjn$_run_closure3$_closure6$_closure9@7067b161] on task ':asciidoctor' of type org.asciidoctor.gradle.AsciidoctorTask.

Now trying without underscore:

docinfoprocessor { document ->
      '<div>FOOBAR</div>'
}

and the error is

> Could not find method docinfoprocessor() for arguments [build_35iwvdrdnszm23y6o4g0onhjn$_run_closure3$_closure6$_closure9@6ef52536] on task ':asciidoctor' of type org.asciidoctor.gradle.AsciidoctorTask.

The anove I would expect as the code at https://github.com/asciidoctor/asciidoctorj-groovy-dsl/blob/v1.0.0.Alpha2/src/main/groovy/org/asciidoctor/groovydsl/AsciidoctorExtensionHandler.groovy#L136 only supports docinfo_processor.

But now reading that code I sould be able to pass a combination of options and the closure i.e.

docinfo_processor( at_location : 'footer') { document ->
      '<div>FOOBAR</div>'
}

Error is this case is

> Could not find method docinfo_processor() for arguments [{at_location=footer}, build_35iwvdrdnszm23y6o4g0onhjn$_run_closure3$_closure6$_closure9@7c47dfe0] on task ':asciidoctor' of type org.asciidoctor.gradle.AsciidoctorTask.

Looking at the code - https://github.com/asciidoctor/asciidoctorj-groovy-dsl/blob/v1.0.0.Alpha2/src/main/groovy/org/asciidoctor/groovydsl/extensions/DelegatingDocinfoProcessor.groovy#L25 - the above should be possible to construct.

@robertpanzer
Copy link
Member

Part of the problem is that the asciidoctor-gradle-plugin references an old version of the asciidoctorj-groovy-dsl in its current version, which unfortunately doesn't even match the test dependency.
https://github.com/asciidoctor/asciidoctor-gradle-plugin/blob/d381e7e6f2ce8e8a214dc88ed4c16e25a7d5e7dc/src/main/groovy/org/asciidoctor/gradle/AsciidoctorExtension.groovy#L26 references 1.0.0.preview2 while https://github.com/asciidoctor/asciidoctor-gradle-plugin/blob/d381e7e6f2ce8e8a214dc88ed4c16e25a7d5e7dc/build.gradle#L49 references 1.0.0.Alpha1.
In fact the renaming of the extension methods happened exactly between these two releases.

The current release though is 1.0.0.alpha2, I'll create a PR for that.

The DocInfo example should generally work, I got it working like so:

        docinfo_processor( location : ':footer') { document ->
            '<div>FOOBAR</div>'
        }

I can update the README to include this.

The block_macro and inline_macro examples worked for me (with the correct versions) like this:

asciidoctorj {
    version = '1.5.5'
    groovyDslVersion = '1.0.0.Alpha2'
}
asciidoctor {
    extensions {
        docinfo_processor( location : ':footer') { document ->
            '<div>FOOBAR</div>'
        }
        block(name: 'BIG', contexts: [':paragraph']) {
            parent, reader, attributes ->
                def upperLines = reader.readLines()
                        .collect {it.toUpperCase()}
                        .inject('') {a, b -> a + '\n' + b}

                createBlock(parent, 'paragraph', [upperLines], attributes, [:])
        }
        block('small') {
            parent, reader, attributes ->
                def lowerLines = reader.readLines()
                        .collect {it.toLowerCase()}
                        .inject('') {a, b -> a + '\n' + b}

                createBlock(parent, 'paragraph', [lowerLines], attributes, [:])
        }
        block_macro('capitalize') {
            parent, target, attributes ->
                def capitalLines = target.toLowerCase()
                        .tokenize('_')
                        .collect { it.capitalize() }
                        .join(' ')
                createBlock(parent, 'pass', [capitalLines], attributes)
        }
        inline_macro('man') {
            parent, target, attributes ->
                def options = ["type": ":link", "target": target + ".html"]
                println "parent $parent"
                createInline(parent, "anchor", target, attributes, options).convert()
        }
    }
}

@robertpanzer
Copy link
Member

Actually the blockMacro example isn't fully correct.
I got it working like this now:

        block_macro('capitalize') {
            parent, target, attributes ->
                def capitalLines = target.toLowerCase()
                        .tokenize('_')
                        .collect { it.capitalize() }
                        .join(' ')
                createBlock(parent, 'pass', [capitalLines], attributes, [:])
        }

Note the additional parameter for the options in the call to createBlock().

@chess-levin
Copy link

chess-levin commented Jan 3, 2020

This example isn't working either:

inline_macro('man') {
    parent, target, attributes ->
        def options = ["type": ":link", "target": target + ".html"]
        println "parent $parent"
        createInline(parent, "anchor", target, attributes, options).convert()
}

Caused by: groovy.lang.MissingMethodException: No signature of method: asciidoc_ext.createInline() is applicable for argument types: (org.asciidoctor.jruby.ast.impl.BlockImpl, String, String, org.asciidoctor.jruby.internal.RubyAttributesMapDecorator...) values: [org.asciidoctor.jruby.ast.impl.BlockImpl@44da7eb3, anchor, gittutorial, ...]

excert of my build.gradle:

plugins {
    id 'java'
    id 'org.asciidoctor.jvm.convert' version '2.4.0'
    id 'org.asciidoctor.jvm.pdf' version '2.4.0'
}

dependencies {
    compile group: 'org.asciidoctor', name: 'asciidoctorj-groovy-dsl', version: '1.6.0'
}

asciidoctorj {
    docExtensions  new File('asciidoc_ext.groovy')

    version '2.2.0'

It would be great to know, if the groovy dsl is still an active project or if it's better to use java api.

@abelsromero
Copy link
Member

It would be great to know, if the groovy dsl is still an active project or if it's better to use java api.

The project is active, but not currently updated to the last AsciidoctorJ version and also there's an error in the documentation that affects your scenario.
For the documentation error, instead of createInline you should use createPhraseNode. You can see that the tests of the branch 1.6.0 use that.

For the version update, I already have a PR ready with that and the fix in the documentation. But there are other things that I think would be nice to include, I'll open another for discussion. Feel free to join if there's anything you find is missing.

@abelsromero abelsromero mentioned this issue Jan 3, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants