Sha256: 5d800b83811a5f29e22defbcb357a9904ccd3e43a9989aea4eb64e3ef98b6bc8

Contents?: true

Size: 973 Bytes

Versions: 2

Compression:

Stored size: 973 Bytes

Contents

require 'schmooze'

class Grover
  #
  # Processor helper class for calling out to Puppeteer NodeJS library
  #
  class Processor < Schmooze::Base
    dependencies puppeteer: 'puppeteer'

    def self.launch_params
      ENV['CI'] == 'true' ? "{args: ['--no-sandbox', '--disable-setuid-sandbox']}" : ''
    end
    private_class_method :launch_params

    method :convert_pdf, Utils.squish(<<-FUNCTION)
      async (url, options) => {
        let browser;
        try {
          browser = await puppeteer.launch(#{launch_params});
          const page = await browser.newPage();
          if (url.match(/^http/i)) {
            await page.goto(url, { waitUntil: 'networkidle2' });
          } else {
            await page.goto(`data:text/html,${url}`, { waitUntil: 'networkidle0' });
          }
          return await page.pdf(options);
        } finally {
          if (browser) {
            await browser.close();
          }
        }
      }
    FUNCTION
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grover-0.2.2 lib/grover/processor.rb
grover-0.2.1 lib/grover/processor.rb