Sha256: 2b50fc11ac869f2c7c3fc3e6ab3ff14ae11e747037624e9b9d8301fc7dfde233

Contents?: true

Size: 1.75 KB

Versions: 520

Compression:

Stored size: 1.75 KB

Contents

require 'deliver/app_screenshot'

require_relative 'module'
require_relative 'device_types'
require_relative 'frame_downloader'

module Frameit
  # Responsible for finding the correct device
  class TemplateFinder
    # This will detect the screen size and choose the correct template
    def self.get_template(screenshot)
      return nil if screenshot.mac?

      filename = "Apple #{screenshot.device_name} #{screenshot.color}"

      templates = Dir["#{FrameDownloader.templates_path}/#{filename}.{png,jpg}"] # ~/.frameit folder

      UI.verbose("Looking for #{filename} and found #{templates.count} template(s)")

      if templates.count == 0
        if screenshot.screen_size == Deliver::AppScreenshot::ScreenSize::IOS_35
          UI.important("Unfortunately 3.5\" device frames were discontinued. Skipping screen '#{screenshot.path}'")
          UI.error("Looked for: '#{filename}.png'")
        elsif screenshot.color == Frameit::Color::ROSE_GOLD || screenshot.color == Frameit::Color::GOLD
          # Unfortunately not every device type is available in rose gold or gold
          # This is why we can't have nice things #yatusabes
          # fallback to a white iPhone, which looks similar
          UI.important("Unfortunately device type '#{screenshot.device_name}' is not available in #{screenshot.color}, falling back to silver...")
          screenshot.color = Frameit::Color::SILVER
          return self.get_template(screenshot)
        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 filename if Helper.test?
        return nil
      else
        return templates.first.tr(" ", "\ ")
      end
    end
  end
end

Version data entries

520 entries across 520 versions & 2 rubygems

Version Path
fastlane-2.142.0 frameit/lib/frameit/template_finder.rb
fastlane-2.141.0 frameit/lib/frameit/template_finder.rb
fastlane-2.140.0 frameit/lib/frameit/template_finder.rb
fastlane-2.139.0 frameit/lib/frameit/template_finder.rb
fastlane-2.138.0 frameit/lib/frameit/template_finder.rb
fastlane-2.137.0 frameit/lib/frameit/template_finder.rb
fastlane-2.136.0 frameit/lib/frameit/template_finder.rb
fastlane-2.135.2 frameit/lib/frameit/template_finder.rb
fastlane-2.135.1 frameit/lib/frameit/template_finder.rb
fastlane-2.135.0 frameit/lib/frameit/template_finder.rb
fastlane-2.134.0 frameit/lib/frameit/template_finder.rb
fastlane-2.133.0 frameit/lib/frameit/template_finder.rb
fastlane-2.132.0 frameit/lib/frameit/template_finder.rb
fastlane-2.132.0.beta.20190930200026 frameit/lib/frameit/template_finder.rb
fastlane-2.132.0.beta.20190929200020 frameit/lib/frameit/template_finder.rb
fastlane-2.132.0.beta.20190928200106 frameit/lib/frameit/template_finder.rb
fastlane-2.132.0.beta.20190927200017 frameit/lib/frameit/template_finder.rb
fastlane-2.132.0.beta.20190926200023 frameit/lib/frameit/template_finder.rb
fastlane-2.132.0.beta.20190925200108 frameit/lib/frameit/template_finder.rb
fastlane-2.132.0.beta.20190924200030 frameit/lib/frameit/template_finder.rb