Class: Snapshot::ReportsGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/snapshot/reports_generator.rb

Instance Method Summary collapse

Instance Method Details

#generateObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/snapshot/reports_generator.rb', line 6

def generate
  UI.message "Generating HTML Report"

  screens_path = Snapshot.config[:output_directory]

  @data = {}

  Dir[File.join(screens_path, "*")].sort.each do |language_folder|
    language = File.basename(language_folder)
    Dir[File.join(language_folder, '*.png')].sort.each do |screenshot|
      available_devices.each do |key_name, output_name|
        next unless File.basename(screenshot).include?(key_name)

        # This screenshot is from this device
        @data[language] ||= {}
        @data[language][output_name] ||= []

        resulting_path = File.join('.', language, File.basename(screenshot))
        @data[language][output_name] << resulting_path
        break # to not include iPhone 6 and 6 Plus (name is contained in the other name)
      end
    end
  end

  html_path = File.join(lib_path, "snapshot/page.html.erb")
  html = ERB.new(File.read(html_path)).result(binding) # http://www.rrn.dk/rubys-erb-templating-system

  export_path = "#{screens_path}/screenshots.html"
  File.write(export_path, html)

  export_path = File.expand_path(export_path)
  UI.success "Successfully created HTML file with an overview of all the screenshots: '#{export_path}'"
  system("open '#{export_path}'") unless Snapshot.config[:skip_open_summary]
end