Class: XCHtmlGenerator
- Inherits:
-
Object
- Object
- XCHtmlGenerator
- Defined in:
- lib/xc_html_generator.rb
Instance Attribute Summary collapse
-
#screenshots_path ⇒ Object
Returns the value of attribute screenshots_path.
Instance Method Summary collapse
- #available_devices ⇒ Object
-
#generate ⇒ String
Tweet.
- #html_path ⇒ Object
-
#initialize(params = {}) ⇒ XCHtmlGenerator
constructor
A new instance of XCHtmlGenerator.
- #path ⇒ Object
- #result_path ⇒ Object
- #root ⇒ Object
- #xcode_9_and_above_device_name_mappings ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ XCHtmlGenerator
Returns a new instance of XCHtmlGenerator.
12 13 14 |
# File 'lib/xc_html_generator.rb', line 12 def initialize(params = {}) @screenshots_path = params.fetch(:screenshots_path, path) end |
Instance Attribute Details
#screenshots_path ⇒ Object
Returns the value of attribute screenshots_path.
6 7 8 |
# File 'lib/xc_html_generator.rb', line 6 def screenshots_path @screenshots_path end |
Instance Method Details
#available_devices ⇒ Object
123 124 125 |
# File 'lib/xc_html_generator.rb', line 123 def available_devices return xcode_9_and_above_device_name_mappings end |
#generate ⇒ String
Tweet
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/xc_html_generator.rb', line 29 def generate screens_path = screenshots_path @data_by_language = {} @data_by_screen = {} Dir[File.join(screens_path, "*")].sort.each do |device_name_folders| device_name = File.basename(device_name_folders) Dir[File.join(device_name_folders, "*")].sort.each do |language_folder| language = File.basename(language_folder) Dir[File.join(language_folder, '*.png')].sort.each do |screenshot| file_name = File.basename(screenshot) available_devices.each do |key_name, output_name| next unless device_name.include?(key_name) # This screenshot is from this device @data_by_language[language] ||= {} @data_by_language[language][output_name] ||= [] screen_name = file_name.sub(key_name + '-', '').sub('.png', '') @data_by_screen[screen_name] ||= {} @data_by_screen[screen_name][output_name] ||= {} resulting_path = device_name + '/' + language + '/' + file_name @data_by_language[language][output_name] << resulting_path @data_by_screen[screen_name][output_name][language] = resulting_path break # to not include iPhone 6 and 6 Plus (name is contained in the other name) end end end end html = ERB.new(File.read(html_path)).result(binding) # https://web.archive.org/web/20160430190141/www.rrn.dk/rubys-erb-templating-system export_path = "#{screens_path}/screenshots.html" File.write(export_path, html) export_path = File.(export_path) p "Successfully created HTML file with an overview of all the screenshots: '#{export_path}'" #system("open '#{export_path}'") unless Snapshot.config[:skip_open_summary] end |
#html_path ⇒ Object
20 21 22 |
# File 'lib/xc_html_generator.rb', line 20 def html_path File.join(root, "lib", "html", "page.html.erb") end |
#path ⇒ Object
16 17 18 |
# File 'lib/xc_html_generator.rb', line 16 def path Dir.pwd end |
#result_path ⇒ Object
24 25 26 |
# File 'lib/xc_html_generator.rb', line 24 def result_path path end |
#root ⇒ Object
8 9 10 |
# File 'lib/xc_html_generator.rb', line 8 def root File.dirname __dir__ end |
#xcode_9_and_above_device_name_mappings ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/xc_html_generator.rb', line 71 def xcode_9_and_above_device_name_mappings { # snapshot in Xcode 9 saves screenshots with the SIMULATOR_DEVICE_NAME # which includes spaces 'iPhone 12 Pro Max' => "iPhone 12 Pro Max", 'iPhone 12 Pro' => "iPhone 12 Pro", 'iPhone 12 mini' => "iPhone 12 mini", 'iPhone 12' => "iPhone 12", 'iPhone 11 Pro Max' => "iPhone 11 Pro Max", 'iPhone 11 Pro' => "iPhone 11 Pro", 'iPhone 11' => "iPhone 11", 'iPhone XS Max' => "iPhone XS Max", 'iPhone XS' => "iPhone XS", 'iPhone XR' => "iPhone XR", 'iPhone 8 Plus' => "iPhone 8 Plus", 'iPhone 8' => "iPhone 8", 'iPhone X' => "iPhone X", 'iPhone 7 Plus' => "iPhone 7 Plus (5.5-Inch)", 'iPhone 7' => "iPhone 7 (4.7-Inch)", 'iPhone 6s Plus' => "iPhone 6s Plus (5.5-Inch)", 'iPhone 6 Plus' => "iPhone 6 Plus (5.5-Inch)", 'iPhone 6s' => "iPhone 6s (4.7-Inch)", 'iPhone 6' => "iPhone 6 (4.7-Inch)", 'iPhone 5s' => "iPhone 5s (4-Inch)", 'iPhone 5' => "iPhone 5 (4-Inch)", 'iPhone SE' => "iPhone SE", 'iPhone 4s' => "iPhone 4s (3.5-Inch)", 'iPad 2' => 'iPad 2', 'iPad Air (3rd generation)' => 'iPad Air (3rd generation)', 'iPad Air 2' => 'iPad Air 2', 'iPad Air' => 'iPad Air', 'iPad (5th generation)' => 'iPad (5th generation)', 'iPad (7th generation)' => 'iPad (7th generation)', 'iPad Pro (9.7-inch)' => 'iPad Pro (9.7-inch)', 'iPad Pro (9.7 inch)' => 'iPad Pro (9.7-inch)', # iOS 10.3.1 simulator 'iPad Pro (10.5-inch)' => 'iPad Pro (10.5-inch)', 'iPad Pro (11-inch) (2nd generation)' => 'iPad Pro (11-inch) (2nd generation)', 'iPad Pro (11-inch)' => 'iPad Pro (11-inch)', 'iPad Pro (12.9-inch) (4th generation)' => 'iPad Pro (12.9-inch) (4th generation)', 'iPad Pro (12.9-inch) (3rd generation)' => 'iPad Pro (12.9-inch) (3rd generation)', 'iPad Pro (12.9-inch) (2nd generation)' => 'iPad Pro (12.9-inch) (2nd generation)', 'iPad Pro (12.9-inch)' => 'iPad Pro (12.9-inch)', 'iPad Pro (12.9 inch)' => 'iPad Pro (12.9-inch)', # iOS 10.3.1 simulator 'iPad Pro' => 'iPad Pro (12.9-inch)', # iOS 9.3 simulator 'Apple TV 1080p' => 'Apple TV', 'Apple TV 4K (at 1080p)' => 'Apple TV 4K (at 1080p)', 'Apple TV 4K' => 'Apple TV 4K', 'Apple TV' => 'Apple TV', 'Mac' => 'Mac' } end |