Redefining attributes?

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

Redefining attributes?

LightGuardjp
Did I miss something and you can't redefine an attribute?

Here's my use case: writing a book with each chapter being it's own adoc file. I'd like to be able to reuse an attribute but have it mean different things for each chapter. For example, the directory for source inclusions. Chapter one should be at `/path/ch01/src/blah` and chapter two at `/path/ch02/src/blah`.

That works great for individual files, but once you include them into one master document, the first definition of the attribute wins. Yes, I could use a different attribute for each file, but I'd really rather not.
Reply | Threaded
Open this post in threaded view
|

Re: Redefining attributes?

Jeremie Bresson
I am not sure if this will help you or not, but I think you should read this discussion:
http://discuss.asciidoctor.org/Understanding-include-directive-and-file-path-td3137.html

I have the feeling that I had a similar problem but the other way around.

From my experience I have also the feeling that if you redefine a variable, it will win.
I just tried something like that:

Given this structure:

Root
|   document.adoc
|
+---chap1
|   \---src
|           test.txt
|
\---chap2
    \---src
            test.txt

~~~~ document.adoc ~~~
== Chapter 1

:sourcefolder: chap1/src

.test.txt in the first chapter
----
include::{sourcefolder}/test.txt[]
----


== Chapter 2

:sourcefolder: chap2/src

.test.txt in the second chapter
----
include::{sourcefolder}/test.txt[]
----
~~~~ end of document.adoc ~~~

I works also if you split the chapters in separated files:

Root
|   chapter1.adoc
|   chapter2.adoc
|   master.adoc
|
+---chap1
|   \---src
|           test.txt
|
\---chap2
    \---src
            test.txt

What did I miss?
Reply | Threaded
Open this post in threaded view
|

Re: Redefining attributes?

mojavelinux
Administrator
* If the attribute is only defined in the document (not by the API or CLI), then it will update as it is redefined in the document. * If the attribute is defined by the caller (API or CLI), the declarations in the document are ignored.
  - There is one exception to this rule. If the attribute value ends with a @, then the declarations in the document will win.

So, if you are defining the attribute when calling Asciidoctor, it's best to do something like:

-a includedir=chapters@

I hope that clears things up.

-Dan

On Sun, Jul 19, 2015 at 11:30 AM, Jeremie Bresson [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I am not sure if this will help you or not, but I think you should read this discussion:
http://discuss.asciidoctor.org/Understanding-include-directive-and-file-path-td3137.html

I have the feeling that I had a similar problem but the other way around.

From my experience I have also the feeling that if you redefine a variable, it will win.
I just tried something like that:

Given this structure:

Root
|   document.adoc
|
+---chap1
|   \---src
|           test.txt
|
\---chap2
    \---src
            test.txt

~~~~ document.adoc ~~~
== Chapter 1

:sourcefolder: chap1/src

.test.txt in the first chapter
----
include::{sourcefolder}/test.txt[]
----


== Chapter 2

:sourcefolder: chap2/src

.test.txt in the second chapter
----
include::{sourcefolder}/test.txt[]
----
~~~~ end of document.adoc ~~~

I works also if you split the chapters in separated files:

Root
|   chapter1.adoc
|   chapter2.adoc
|   master.adoc
|
+---chap1
|   \---src
|           test.txt
|
\---chap2
    \---src
            test.txt

What did I miss?


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



--