Sha256: ddba934e128c98dd8ac1ed1bcb92e44f48134c54cb09e28fdf8f626cad6b950a

Contents?: true

Size: 928 Bytes

Versions: 1

Compression:

Stored size: 928 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.setContent(url);
          }
          return await page.pdf(options);
        } finally {
          if (browser) {
            await browser.close();
          }
        }
      }
    FUNCTION
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grover-0.2.0 lib/grover/processor.rb