Conditional processing using gradle/asciidoctorj

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Conditional processing using gradle/asciidoctorj

apj68
Has anyone experienced problems doing conditional processing using asciidoctorj through the asciidoctor-gradle plugin (1.5.3)?  I'm passing attributes through successfully in my gradle script so that this works:

Attribute is {myattrib}.

So I can see the attribute value.  But this doesn't work:

ifdef::myattrib[Shouldn't this work?]

Even if I do this, it doesn't work:

ifdef::myattrib[Shouldn't this work?]

ifndef::myattrib[Neither of these work]

It's like the conditional processing doesn't work at all.  Is there something I need to do in the task configuration other than just pass the attributes?

Thanks!

Andy
Reply | Threaded
Open this post in threaded view
|

Re: Conditional processing using gradle/asciidoctorj

mojavelinux
Administrator
I recommend consulting / trying it with the Gradle examples.


If you want further assistance, you'll need to provide more context so that we can help you debug. What do your task configuration look like? Which version of Gradle? Which version of AsciidoctorJ? Which version of the Gradle plugin? etc

Cheers,

-Dan

On Wed, May 9, 2018 at 10:43 AM, apj68 [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Has anyone experienced problems doing conditional processing using asciidoctorj through the asciidoctor-gradle plugin (1.5.3)?  I'm passing attributes through successfully in my gradle script so that this works:

Attribute is {myattrib}.

So I can see the attribute value.  But this doesn't work:

ifdef::myattrib[Shouldn't this work?]

Even if I do this, it doesn't work:

ifdef::myattrib[Shouldn't this work?]

ifndef::myattrib[Neither of these work]

It's like the conditional processing doesn't work at all.  Is there something I need to do in the task configuration other than just pass the attributes?

Thanks!

Andy



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Conditional-processing-using-gradle-asciidoctorj-tp6319.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: Conditional processing using gradle/asciidoctorj

apj68
Ok, sorry about that!  In the process of creating a simplified script that illustrates my problem, things got a little better... :)  What wasn't working in my original was both `ifeval` and `ifdef` but I only posted about `ifdef`.  Now `ifdef` works so I must have a problem in my source document in that case.  

However, `ifeval` still isn't working so that's what I need help with.  Here's the script:

build.gradle:
import org.asciidoctor.gradle.AsciidoctorTask
apply plugin: "maven"
apply plugin: "java"

buildscript{
  repositories {
    jcenter()
  }
  dependencies {
    classpath "org.asciidoctor:asciidoctor-gradle-plugin:1.5.3"
  }
}

apply plugin: 'org.asciidoctor.convert'

asciidoctorj {
  version = '1.5.2'
}

asciidoctor {
  sourceDir = file("src")

  doFirst{
    attributes = project.properties
  }
}
 
gradle.properties:
projcode=cm

src/sample.adoc:
Sample document.  Attribute is {projcode}.

ifeval::["{projcode}"=="cm"}]

If `projcode == cm` then you should see this.

endif::[]

ifdef::projcode[project was defined as {projcode}]

ifndef::projcode[project was not defined]


And here's the output (extracted from the HTML, etc):
Sample document. Attribute is cm.

project was defined as cm

Is there something wrong with my `ifeval` syntax?  

Asciidoctor's the best - thanks for all your work!

Andy

Reply | Threaded
Open this post in threaded view
|

Re: Conditional processing using gradle/asciidoctorj

abelsromero
I don't think you need to add quotes to`ifeval`. Just `ifeval::[{projcode}==cm}]` or `ifeval::[{projcode}=="cm"}]` should do the trick.

Btw, the last version of AsciidoctorJ is 1.5.6, you should update your build if you can.
Reply | Threaded
Open this post in threaded view
|

Re: Conditional processing using gradle/asciidoctorj

mojavelinux
Administrator
The problem is that there's an stray closing curly brace in the expression.

It currently looks like this:

ifeval::["{projcode}"=="cm"}]

It should be

ifeval::["{projcode}"=="cm"]

We do recommend enclosing the attribute reference in quotes when you're comparing it to another string, so that part is correct.

-Dan

On Sat, May 12, 2018 at 1:16 PM, abelsromero [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I don't think you need to add quotes to`ifeval`. Just `ifeval::[{projcode}==cm}]` or `ifeval::[{projcode}=="cm"}]` should do the trick.

Btw, the last version of AsciidoctorJ is 1.5.6, you should update your build if you can.


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Conditional-processing-using-gradle-asciidoctorj-tp6319p6325.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: Conditional processing using gradle/asciidoctorj

apj68
Omigosh.... so sorry about the goose chase!  I thought I was going to have to say it worked in the sample but not in my actual case but in fact, I had the same typo in both places so all is well everywhere...

Thanks so much for your help!

Andy
Reply | Threaded
Open this post in threaded view
|

Re: Conditional processing using gradle/asciidoctorj

mojavelinux
Administrator
No problem. Glad to help! Sometimes finding the right path just requires an extra set of eyes.

Cheers,

-Dan

On Mon, May 14, 2018 at 11:06 AM, apj68 [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Omigosh.... so sorry about the goose chase!  I thought I was going to have to say it worked in the sample but not in my actual case but in fact, I had the same typo in both places so all is well everywhere...

Thanks so much for your help!

Andy


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Conditional-processing-using-gradle-asciidoctorj-tp6319p6327.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux