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

asciidoctor pdf command pipe #254

Closed
jeremyVignelles opened this issue Jun 30, 2015 · 5 comments
Closed

asciidoctor pdf command pipe #254

jeremyVignelles opened this issue Jun 30, 2015 · 5 comments
Assignees

Comments

@jeremyVignelles
Copy link

I'm trying to use the asciidoctor-pdf with pipes for integration inside a gulp script (the .js I found on the web are too young yet and does not provide the PDF backend)

I found that when I'm trying this command

$ cat test.adoc | asciidoc-pdf -o - - > test.pdf

and the error I get is

can't convert IO into String
  Use --trace for backtrace

The error disappears when I use the following syntax

$ cat test.adoc | asciidoc-pdf -o test.pdf -

Thanks,


For those who are looking for a gulp integration of the asciidoctor command line, here is what I do:

function genAsciiDoc(file, backend) {
    var args = [];
    if(backend == 'pdf') {
        args = args.concat(['-r', 'asciidoctor-pdf'])
    }

    args = args.concat([
        '-b',
        backend,
        '-o',
        '-',
        '-'
    ]);

    var ext = (backend == 'html5' ? 'html' : backend);

    return gulp.src(file)
    .pipe(spawn({
        cmd: 'asciidoctor',
        args: args
    }))
    .pipe(ext_replace('.' + ext))
    .pipe(gulp.dest('doc/'));
}
@mojavelinux mojavelinux added this to the v1.5.0 milestone Jun 30, 2015
@mojavelinux mojavelinux self-assigned this Jun 30, 2015
@mojavelinux
Copy link
Member

Thanks for pointing this out. It looks like Prawn's render_file method doesn't support IO objects, so we'll need to handle this ourselves in the converter.

Here's code I just tested that seems to work

  def write pdf_doc, target
    if ::IO === target
      if target == STDOUT
        ::StringIO.open do |io|
          pdf_doc.render io
          io.rewind
          target.write io.read
        end
      else
        pdf_doc.render target
      end
    else
      pdf_doc.render_file target
      @pdfmarks.generate_file target if @pdfmarks
    end
    nil
  end

Sadly, we can't stream to STDOUT as Prawn relies on the size method, which isn't available on the STDOUT object.

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jun 30, 2015
@mojavelinux
Copy link
Member

PR sent. Please check it out when you get a chance.

@jeremyVignelles
Copy link
Author

Hi,
Sorry for the delay but I was on other topics these days. I tried your code and it worked as expected using the command line. I did not try using my gulp plugin yet, as I don't know how to say which asciidoctor-pdf to use in the command line.

I hope this could be merged and released soon 😄

@mojavelinux
Copy link
Member

Thanks for the feedback @jeremyVignelles! I'll try to get this into the upcoming 1.5.0.alpha.9 release, out by the end of this week hopefully.

@mojavelinux mojavelinux modified the milestones: v1.5.0.alpha.9, v1.5.0 Jul 21, 2015
mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Jul 28, 2015
…cts)

- use Prawn's Document#render method if the target responds to the write method
- wrap STDOUT to adapt it to work with Prawn / PDF Core
@mojavelinux
Copy link
Member

I sorted out how to get streaming to STDOUT working! \o/

I had to wrap STDOUT in a decorator to track the size and expose that information using an accessor. Then, it works!

mojavelinux added a commit that referenced this issue Jul 28, 2015
resolves #254 support writing to STDOUT (and other IO objects)
mojavelinux added a commit that referenced this issue Jul 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants