Asciidoctorj-diagrams target directory

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

Asciidoctorj-diagrams target directory

patrickm
Hello,
I'm trying to use diagrams using asciidoctor-j (1.5.3-SNAPSHOT) and working well.
How can I specify the target directory for generated diagrams ?

Thanks
Patrick
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

mojavelinux
Administrator

If you use Asciidoctor Diagram 1.3 preview, you can specify using the imagesoutdir attribute. It also has a more sane default. A final version of 1.3 should be released shortly.

Cheers,

-Dan

Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

patrickm
I am not able to specify the output directory... (I am using asciidoctor-j 1.6 SNAPSHOT)

I tried something like:

Attributes attributes = new Attributes ();
attributes.setAttribute ("imagesoutdir", new File ("/tmp/test-images"));

Options options = new Options ();
options.setAttributes (attributes);
String asciiDocHtml = asciidoctor.convert (asciiDocStr, options);

and

Options options = new Options ();
options.setAttribute ("imagesoutdir", new File ("/tmp/test-images"));
String asciiDocHtml = asciidoctor.convert (asciiDocStr, options);

What am I missing ?

Patrick
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

abelsromero
I found two problems here.

First, AsciidoctorJ includes the ruby gem asciidoctor-diagram 1.3.preview.1 (https://github.com/asciidoctor/asciidoctorj/blob/asciidoctorj-1.6.0/asciidoctorj-diagram/gradle.properties#L3). However, the attribute Dan mentioned was included in 1.3.preview.3. I could make your code work changing the version in asciidoctorj-diagram (the jar) and installing asciidoctorj-diagram locally.
So, I'm sorry to say there's no public fix for your problem.

Second, in your code, you use convert which outputs the generated files to a String, I've tested it and I see that it does not create any output file, html or images. Using convertFile created the images in the folder set in imagesoutdir. If you need to get the content of the HTML this could be a problem.
Here is a snippet of my test:

        File asciiDocFile = new File(YOUR_ASCIIDOC_FILEPATH);

        OptionsBuilder optionsBuilder =  
        OptionsBuilder.options().safe(SafeMode.UNSAFE).backend("html5").mkDirs(true);

        Attributes attributes = new Attributes();
        attributes.setAttribute("imagesoutdir", "myFolder"); // Note the path is a string relative to the generated HTML
        optionsBuilder.attributes(attributes);

        asciidoctor.convertFile(asciiDocFile, optionsBuilder.asMap());
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

patrickm
I changed  the version in asciidoctorj-diagram (to 1.3.preview.3).
the diagrams are generated in the output directory (great !!) but...
The generated html doesn't include the output directory ...

I get

< img src="diagram-classes.png" alt="diagram classes" width="256" height="283">

instead of

< img src="myfolder/diagram-classes.png" alt="diagram classes" width="256" height="283">



Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

abelsromero
Now, here it come one of those funny cases. There's a simple solution but I think this may collide with your use case.
Before getting into details, can you explain what are you trying to achieve?

Now the solution; the thing is that asciidoctor-diagram uses 'imagesoutdir' to define the target folder to generate the images. But, it uses 'imagesdir' to set the path in the image element of the document.
So the simple solution is setting the 'imagesdir' attribute to the same value as 'imagesoutdir'. But depending on what you would like to do, mixing folders may be a problem.
Part of me thinks this could be considered a bug, but not sure.
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

abelsromero
BTW, here it is the original conversation about the attribute. There're some interesting comments about the meaning of attributes you may be interested on.

https://github.com/asciidoctor/asciidoctor-diagram/issues/39
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

patrickm
Actually, I am rendering the html as string and writing it to a target directory myself.
When rendering a String, the output directory of Asciidoctorj-diagrams is the WORKING directory...

I am using the imagesDir for all images and working as expected. When imagesDir is used, imagesoutdir is not used at all. The images are generated in imagesDir (in the working directory)

I would need to use imagesoutdir as an ABSOLUTE target to generate diagrams and I could set imagesDir accordingly.

I think currently the only way achieve my goal is to move the generated diagrams to my target directory after the generation...
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

mojavelinux
Administrator

On Tue, Aug 4, 2015 at 1:15 AM, patrickm [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I think currently the only way achieve my goal is to move the generated diagrams to my target directory after the generation...

That's in part the design behind the imagesoutdir. The idea is to prevent it from putting the images into a source folder, not necessarily the right final folder. A build tool can then get them to the final resting spot.

...another solution is to specify an absolute path for imagesoutdir as you have pointed out. No real harm in that, bien sûr.

Cheers,

Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

patrickm
mojavelinux wrote
...another solution is to specify an absolute path for imagesoutdir as you
have pointed out. No real harm in that, bien sûr.
Yes, except that imagesoutdir is not used when using imagesdir (and I have to use it)...


Thanks ...

Patrick
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

mojavelinux
Administrator

On Tue, Aug 4, 2015 at 7:45 AM, patrickm [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Yes, except that imagesoutdir is not used when using imagesdir (and I have to use it)...

It should be.


-Dan

Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

patrickm
Strange... With asciidoctorj 1.6-SNAPSHOT patched with  asciidoctorj-diagram to 1.3.preview.3.

    public static void main (String[] args)
        throws Exception
    {
        OptionsBuilder optionsBuilder = OptionsBuilder.options ().safe (SafeMode.UNSAFE).backend ("html5").mkDirs (true);

        Attributes attributes = new Attributes ();
        attributes.setAttribute ("imagesoutdir", "/tmp/images-1"); 
        
        attributes.setImagesDir (new File ("/tmp/images-2").getPath ());
        optionsBuilder.attributes (attributes);

        Asciidoctor asciidoctor = Asciidoctor.Factory.create ();
        asciidoctor.requireLibrary ("asciidoctor-diagram");

        String asciiDocString = "[plantuml, diagram-sequence, png]     \n" +
              "....\n" +
              "Alice -> Bob: Authentication Request\n" +
              "Bob --> Alice: Authentication Response\n" +
              "Alice -> Bob: Another authentication Request\n" +
              "Alice <-- Bob: another authentication Response\n" +
              "...." ;

        System.out.println (asciidoctor.render (asciiDocString, optionsBuilder.asMap ()));
    }
the images are generated in "/tmp/images-2" and the produced String is:
<div class="imageblock">
  <div class="content">
    <img src="/tmp/images-2/diagram-sequence.png" alt="diagram sequence" width="293" height="215">
  </div>
</div>
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctorj-diagrams target directory

mojavelinux
Administrator
On a side note, 1.3.0 is now available.


I strongly recommend that you first try it with the Ruby version of Asciidoctor and Asciidoctor Diagram just to ensure that it is behaving as you expect. Then try it with AsciidoctorJ. That way, we know where the problem is occurring. It could very well be somewhere in between.

-Dan

On Wed, Aug 5, 2015 at 2:28 AM, patrickm [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Strange... With asciidoctorj 1.6-SNAPSHOT patched with  asciidoctorj-diagram to 1.3.preview.3.

    public static void main (String[] args)
        throws Exception
    {
        OptionsBuilder optionsBuilder = OptionsBuilder.options ().safe (SafeMode.UNSAFE).backend ("html5").mkDirs (true);

        Attributes attributes = new Attributes ();
        attributes.setAttribute ("imagesoutdir", "/tmp/images-1"); 
        
        attributes.setImagesDir (new File ("/tmp/images-2").getPath ());
        optionsBuilder.attributes (attributes);

        Asciidoctor asciidoctor = Asciidoctor.Factory.create ();
        asciidoctor.requireLibrary ("asciidoctor-diagram");

        String asciiDocString = "[plantuml, diagram-sequence, png]     \n" +
              "....\n" +
              "Alice -> Bob: Authentication Request\n" +
              "Bob --> Alice: Authentication Response\n" +
              "Alice -> Bob: Another authentication Request\n" +
              "Alice <-- Bob: another authentication Response\n" +
              "...." ;

        System.out.println (asciidoctor.render (asciiDocString, optionsBuilder.asMap ()));
    }
the images are generated in "/tmp/images-2" and the produced String is:
<div class="imageblock">
  <div class="content">
    <img src="/tmp/images-2/diagram-sequence.png" alt="diagram sequence" width="293" height="215">
  </div>
</div>



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



--