class Frameit::Screenshot
Represents one screenshot
Attributes
Public Class Methods
Source
# File frameit/lib/frameit/screenshot.rb, line 17 def initialize(path, color, config, platform_command) UI.user_error!("Couldn't find file at path '#{path}'") unless File.exist?(path) @color = color @path = path @size = FastImage.size(path) # There are three ways how we can get settings to Frameit: # - options.rb # - gets parameters via CLI (e. g. fastlane run frameit use_platform:"android") or fastfile (Fastlane's global # settings for a given project) # - see Parameters in the doc # - contains default values and validates values # - accessed via Frameit.config[:key] # - default value is either general platform from fastfile or IOS if run directly # - lowest priority # - commands_generator.rb # - commands entered directly to CLI (e. g. fastlane frameit android) # - they are passed via constructors to other classes # - higher priority than options.rb (user may enter a command to override fastfile's global setting) # - config_parser.rb # - gets key / values from Framefile.json # - see Advanced usage in the doc # - both default and specific values can be entered in the file (filtered by file name) # - accessed via ConfigParser.fetch_value(screenshot.path)[key] (the ConfigParser's instance is passed # to Screenshot's constructor as config, i.e. we call config[key]) # - should have the highest priority, because user might set a specific value for a specific screenshot which # should override CLI parameters and fastfile global setting platform = config['use_platform'] || platform_command || Frameit.config[:use_platform] @device = Device.find_device_by_id_or_name(config['force_device_type'] || Frameit.config[:force_device_type]) || Device.detect_device(path, platform) end
path: Path to screenshot color: Color
to use for the frame
Public Instance Methods
Source
# File frameit/lib/frameit/screenshot.rb, line 54 def default_color @device.default_color end
Source
# File frameit/lib/frameit/screenshot.rb, line 58 def deliver_screen_id @device.deliver_screen_id end
Source
# File frameit/lib/frameit/screenshot.rb, line 49 def device_name @device.formatted_name # rubocop:enable Require/MissingRequireStatement end
Device
name for a given screen size. Used to use the correct template
Source
# File frameit/lib/frameit/screenshot.rb, line 82 def frame_orientation filename = File.basename(self.path, ".*") block = Frameit.config[:force_orientation_block] unless block.nil? orientation = block.call(filename) valid = [:landscape_left, :landscape_right, :portrait, nil] UI.user_error("orientation_block must return #{valid[0..-2].join(', ')} or nil") unless valid.include?(orientation) end puts("Forced orientation: #{orientation}") unless orientation.nil? return orientation unless orientation.nil? return :portrait if self.orientation_name == Orientation::PORTRAIT return :landscape_right # Default landscape orientation end
Source
# File frameit/lib/frameit/screenshot.rb, line 111 def landscape? return self.landscape_left? || self.landscape_right end
Source
# File frameit/lib/frameit/screenshot.rb, line 103 def landscape_left? return (frame_orientation == :landscape_left) end
Source
# File frameit/lib/frameit/screenshot.rb, line 107 def landscape_right? return (frame_orientation == :landscape_right) end
Source
# File frameit/lib/frameit/screenshot.rb, line 126 def language @language ||= Pathname.new(path).parent.basename.to_s end
Source
# File frameit/lib/frameit/screenshot.rb, line 72 def mac? device_name == 'MacBook' end
Source
# File frameit/lib/frameit/screenshot.rb, line 68 def mini? !device.density_ppi.nil? && device.density_ppi < 300 end
Super old devices (iPhone 4)
Source
# File frameit/lib/frameit/screenshot.rb, line 77 def orientation_name return Orientation::PORTRAIT if size[0] < size[1] return Orientation::LANDSCAPE end
The name of the orientation of a screenshot. Used to find the correct template
Source
# File frameit/lib/frameit/screenshot.rb, line 121 def outdated? return true unless File.exist?(output_path) return File.mtime(path) > File.mtime(output_path) end
If the framed screenshot was generated before the screenshot file, then we must be outdated.
Source
# File frameit/lib/frameit/screenshot.rb, line 115 def output_path path.gsub('.png', '_framed.png').gsub('.PNG', '_framed.png') end
Source
# File frameit/lib/frameit/screenshot.rb, line 99 def portrait? return (frame_orientation == :portrait) end
Source
# File frameit/lib/frameit/screenshot.rb, line 63 def triple_density? !device.density_ppi.nil? && device.density_ppi > 400 end
Is the device a 3x device? (e.g. iPhone 6 Plus, iPhone X)