<commit_before>require 'fileutils'

require "capybara"
require 'capybara/poltergeist'
require "capybara/dsl"

require 'monet/router'
require 'monet/image'

module Monet
  class Capture
    include Capybara::DSL

    MAX_HEIGHT = 10000

    def initialize(config)
      @config = config
      @router = Monet::Router.new config

      Capybara.default_driver = @config.driver
    end

    def capture_all
      images = []
      @router.capture_routes.map do |url, paths|
        visit_once url

        paths.each do |path|
          image = Monet::Image.new path
          capture(url, image)

          images << image
        end
      end

      images
    end

    def capture(url, image_or_save_path)
      if image_or_save_path.is_a? String
        image = Monet::Image.new image_or_save_path
      else
        image = image_or_save_path
      end

      visit_once url

      page.driver.resize(image.width, MAX_HEIGHT)
      page.driver.render(image.path, full: true)

      image.thumbnail!(@router.thumbnail_dir) if @config.thumbnail?
    end

    private
    def visit_once(url)
      visit url unless current_url == url
    end
  end
end<commit_msg>ignore polgergeist errors<commit_after>require 'fileutils'

require "capybara"
require 'capybara/poltergeist'
require "capybara/dsl"

require 'monet/router'
require 'monet/image'

module Monet
  class Capture
    include Capybara::DSL

    MAX_HEIGHT = 10000

    def initialize(config)
      @config = config
      @router = Monet::Router.new config

      Capybara.register_driver :poltergeist do |app|
        Capybara::Poltergeist::Driver.new(app, {js_errors: false})
      end
      Capybara.default_driver = @config.driver
    end

    def capture_all
      images = []
      @router.capture_routes.map do |url, paths|
        visit_once url

        paths.each do |path|
          image = Monet::Image.new path
          capture(url, image)

          images << image
        end
      end

      images
    end

    def capture(url, image_or_save_path)
      if image_or_save_path.is_a? String
        image = Monet::Image.new image_or_save_path
      else
        image = image_or_save_path
      end

      visit_once url

      page.driver.resize(image.width, MAX_HEIGHT)
      page.driver.render(image.path, full: true)

      image.thumbnail!(@router.thumbnail_dir) if @config.thumbnail?
    end

    private
    def visit_once(url)
      visit url unless current_url == url
    end
  end
end
{'fraction_non_alphanumeric': 0.0806320907617504, 'fraction_numerical': 0.004051863857374392, 'mean_word_length': 2.433936022253129, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3996598', 'n_tokens_mistral': 817, 'n_tokens_neox': 784, 'n_words': 185}