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
40
41
42
43
44
# File 'lib/snapshot/reports_generator.rb', line 6

def generate

  config = SnapshotConfig.shared_instance
  screens_path = config.screenshots_path

  @title = config.html_title    
  @data = {}

  Dir["#{screens_path}/*"].sort.each do |language_path|
    language = File.basename(language_path)
    Dir[File.join(language_path, '*')].sort.each do |screenshot|

      ["portrait", "landscape"].each do |orientation|
        available_devices.each do |key_name, output_name|
          if File.basename(screenshot).include?key_name and File.basename(screenshot).include?orientation
            output_name += " (#{orientation.capitalize})"
            # This screenshot it 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
    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)
  Helper.log.info "Successfully created HTML file with an overview of all the screenshots: '#{export_path}'".green
  system("open '#{export_path}'") unless ENV["SNAPSHOT_SKIP_OPEN_SUMMARY"]
end