Class: Frameit::TemplateFinder
- Inherits:
-
Object
- Object
- Frameit::TemplateFinder
- Defined in:
- frameit/lib/frameit/template_finder.rb
Overview
Responsible for finding the correct device
Class Method Summary collapse
- .create_file_name(device_name, color) ⇒ Object
-
.get_template(screenshot) ⇒ Object
This will detect the screen size and choose the correct template.
Class Method Details
.create_file_name(device_name, color) ⇒ Object
40 41 42 43 |
# File 'frameit/lib/frameit/template_finder.rb', line 40 def self.create_file_name(device_name, color) return "#{device_name} #{color}" unless color.nil? return device_name end |
.get_template(screenshot) ⇒ Object
This will detect the screen size and choose the correct template
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 |
# File 'frameit/lib/frameit/template_finder.rb', line 10 def self.get_template(screenshot) return nil if screenshot.mac? filename = create_file_name(screenshot.device_name, screenshot.color.nil? ? screenshot.default_color : screenshot.color) templates = Dir["#{FrameDownloader.templates_path}/#{filename}.{png,jpg}"] # ~/.frameit folder UI.verbose("Looking for #{filename} and found #{templates.count} template(s)") return filename if Helper.test? if templates.count == 0 && !screenshot.color.nil? && screenshot.color != screenshot.default_color filename = create_file_name(screenshot.device_name, screenshot.default_color) UI.important("Unfortunately device type '#{screenshot.device_name}' is not available in #{screenshot.color}, falling back to " + (screenshot.default_color.nil? ? "default" : screenshot.default_color) + "...") templates = Dir["#{FrameDownloader.templates_path}/#{filename}.{png,jpg}"] # ~/.frameit folder UI.verbose("Looking for #{filename} and found #{templates.count} template(s)") end if templates.count == 0 if screenshot.deliver_screen_id == Deliver::AppScreenshot::ScreenSize::IOS_35 UI.important("Unfortunately 3.5\" device frames were discontinued. Skipping screen '#{screenshot.path}'") UI.error("Looked for: '#{filename}.png'") else UI.error("Couldn't find template for screenshot type '#{filename}'") UI.error("Please run `fastlane frameit download_frames` to download the latest frames") end return nil else return templates.first.tr(" ", "\ ") end end |