Set attribute only when not already set?

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

Set attribute only when not already set?

elygre
We have a document structure somewhat like this:

./MainDocument.adoc (contains include-statements)
./images/lots-of-images.png
./includes/document-sections.adoc

When processing the MainDocument, images must be referenced as "./images/image.png", both from inside MainDocument.adoc and includes/some-section.adoc. However, when using an editor (Intellij, AsciidocFx) to edit includes/document-sections.adoc, "./images/image.png" is not visible.

Is it possible to have a "conditional" attribute statement, so that MainDocument.adoc sets ":imagedir: ./images" and includes/some-section.adoc sets ":imagedir:../images" -- but where only the first declaration is used?

In other word: Is is possible to avoid processing attribute

Eirik
Reply | Threaded
Open this post in threaded view
|

Re: Set attribute only when not already set?

abelsromero
You'll be happy to know, it is supported very easily :)
For those scenarios you can use the conditional statements. They work with predefined attributes and custom ones as well: http://asciidoctor.org/docs/user-manual/#ifdef-directive.

For example, see how icons get a special treatment when an attribute set by GitHub is defined (env-github) here
https://raw.githubusercontent.com/asciidoctor/asciidoctor/master/README.adoc
If you use IntelliJ, it defines the attribute `env-idea` to customize the images path for a specific document.

ifdef::env-github[]
:status:
:outfilesuffix: .adoc
:caution-caption: :fire:
:important-caption: :exclamation:
:note-caption: :paperclip:
:tip-caption: :bulb:
:warning-caption: :warning:
endif::[]
Also, you may be interested in checking how to unset attributes with the `!` symbol: http://asciidoctor.org/docs/user-manual/#using-attributes-set-assign-and-reference.

Reply | Threaded
Open this post in threaded view
|

Re: Set attribute only when not already set?

mojavelinux
Administrator
In reply to this post by elygre
> Is it possible to have a "conditional" attribute statement, so that MainDocument.adoc sets ":imagedir: ./images" and includes/some-section.adoc sets ":imagedir:../images" -- but where only the first declaration is used?

ifndef::imagesdir[:imagesdir: fallback/if/not/already/set]

As Abel suggested, you can check for other attributes instead.

-Dan

On Wed, Oct 4, 2017 at 4:31 AM, elygre [via Asciidoctor :: Discussion] <[hidden email]> wrote:
We have a document structure somewhat like this:

./MainDocument.adoc (contains include-statements)
./images/lots-of-images.png
./includes/document-sections.adoc

When processing the MainDocument, images must be referenced as "./images/image.png", both from inside MainDocument.adoc and includes/some-section.adoc. However, when using an editor (Intellij, AsciidocFx) to edit includes/document-sections.adoc, "./images/image.png" is not visible.

Is it possible to have a "conditional" attribute statement, so that MainDocument.adoc sets ":imagedir: ./images" and includes/some-section.adoc sets ":imagedir:../images" -- but where only the first declaration is used?

In other word: Is is possible to avoid processing attribute

Eirik


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Set-attribute-only-when-not-already-set-tp5953.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