class BrowserCrawler::Followups::ScreenshotsIndexer

Indexes screenshots captured by the crawler, creates index.html from the captured screenshots. ERB Template can be provided that will receive the list of files.

Public Class Methods

new(template:) click to toggle source
# File lib/browser_crawler/followups/screenshots_indexer.rb, line 7
def initialize(template:)
  @template = template || File.read(default_template_file)
end

Public Instance Methods

index_directory(path, file_mask: '*.png') click to toggle source

Produce index.html with links to screenshots found in the `path` specified. Optionally file_mask can be provided to filter out files to be indexed.

# File lib/browser_crawler/followups/screenshots_indexer.rb, line 13
def index_directory(path, file_mask: '*.png')
  files = Dir[File.join(path, file_mask)].map { |file| File.basename(file) }
  html = render_index(files: files)
  index_path = File.join(path, 'index.html')
  File.write(index_path, html)
  index_path
end
index_report(report) click to toggle source
# File lib/browser_crawler/followups/screenshots_indexer.rb, line 21
def index_report(report)
  sorted_pages = Hash[report.pages.sort_by { |(k, _v)| k }]
  files = Hash[sorted_pages.map do |(k, _v)|
    k
  end]
end

Private Instance Methods

default_template_file() click to toggle source
# File lib/browser_crawler/followups/screenshots_indexer.rb, line 30
def default_template_file
  File.join(__dir__, 'templates/index.html.erb')
end
render_index(files:) click to toggle source
# File lib/browser_crawler/followups/screenshots_indexer.rb, line 34
def render_index(files:)
  renderer = ERB.new(@template)
  renderer.result(binding)
end