Class: Frameit::Editor

Inherits:
Object
  • Object
show all
Defined in:
frameit/lib/frameit/editor.rb

Overview

Currently the class is 2 lines too long. Reevaluate refactoring when it's length changes significantly

Direct Known Subclasses

MacEditor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(screenshot, config, debug_mode = false) ⇒ Editor

Returns a new instance of Editor.


21
22
23
24
25
# File 'frameit/lib/frameit/editor.rb', line 21

def initialize(screenshot, config, debug_mode = false)
  @screenshot = screenshot
  @config = config
  self.debug_mode = debug_mode
end

Instance Attribute Details

#debug_modeObject

Returns the value of attribute debug_mode


15
16
17
# File 'frameit/lib/frameit/editor.rb', line 15

def debug_mode
  @debug_mode
end

#frameObject

the frame of the device


17
18
19
# File 'frameit/lib/frameit/editor.rb', line 17

def frame
  @frame
end

#frame_pathObject

Returns the value of attribute frame_path


16
17
18
# File 'frameit/lib/frameit/editor.rb', line 16

def frame_path
  @frame_path
end

#imageObject

the current image used for editing


18
19
20
# File 'frameit/lib/frameit/editor.rb', line 18

def image
  @image
end

#screenshotObject

reference to the screenshot object to fetch the path, title, etc.


14
15
16
# File 'frameit/lib/frameit/editor.rb', line 14

def screenshot
  @screenshot
end

#space_to_deviceObject

Returns the value of attribute space_to_device


19
20
21
# File 'frameit/lib/frameit/editor.rb', line 19

def space_to_device
  @space_to_device
end

Instance Method Details

#frame!Object


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'frameit/lib/frameit/editor.rb', line 27

def frame!
  prepare_image

  @frame_path = load_frame
  if @frame_path # Mac doesn't need a frame
    self.frame = MiniMagick::Image.open(@frame_path)
    # Rotate the frame according to the device orientation
    self.frame.rotate(self.rotation_for_device_orientation)
  elsif self.class == Editor
    # Couldn't find device frame (probably an iPhone 4, for which there are no images available any more)
    # Message is already shown elsewhere
    return
  end

  if is_complex_framing_mode?
    @image = complex_framing
  else
    # easy mode from 1.0 - no title or background
    put_into_frame # put it in the frame
  end

  store_result # write to file system
end

#load_frameObject


51
52
53
54
55
56
57
# File 'frameit/lib/frameit/editor.rb', line 51

def load_frame
  color = fetch_frame_color
  if color
    screenshot.color = color
  end
  TemplateFinder.get_template(screenshot)
end

#prepare_imageObject


59
60
61
# File 'frameit/lib/frameit/editor.rb', line 59

def prepare_image
  @image = MiniMagick::Image.open(screenshot.path)
end

#rotation_for_device_orientationObject


63
64
65
66
67
# File 'frameit/lib/frameit/editor.rb', line 63

def rotation_for_device_orientation
  return 90 if self.screenshot.landscape_right?
  return -90 if self.screenshot.landscape_left?
  return 0
end

#should_skip?Boolean

Returns:


69
70
71
# File 'frameit/lib/frameit/editor.rb', line 69

def should_skip?
  return is_complex_framing_mode? && !fetch_text(:title)
end