Class: Frameit::Editor

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

Direct Known Subclasses

MacEditor

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#frameObject

the frame of the device



4
5
6
# File 'lib/frameit/editor.rb', line 4

def frame
  @frame
end

#imageObject

the current image used for editing



5
6
7
# File 'lib/frameit/editor.rb', line 5

def image
  @image
end

#screenshotObject

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



3
4
5
# File 'lib/frameit/editor.rb', line 3

def screenshot
  @screenshot
end

#top_space_above_deviceObject

Returns the value of attribute top_space_above_device.



6
7
8
# File 'lib/frameit/editor.rb', line 6

def top_space_above_device
  @top_space_above_device
end

Instance Method Details

#frame!(screenshot) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/frameit/editor.rb', line 8

def frame!(screenshot)
  self.screenshot = screenshot
  prepare_image

  if load_frame # Mac doesn't need a frame
    self.frame = MiniMagick::Image.open(load_frame)
    self.frame.rotate(90) unless self.screenshot.portrait? # we use portrait device frames for landscape screenshots
  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 should_add_title?
    @image = complex_framing
  else
    # easy mode from 1.0 - no title or background
    width = offset['width']
    image.resize width # resize the image to fit the frame
    put_into_frame # put it in the frame
  end

  store_result # write to file system
end

#load_frameObject



33
34
35
# File 'lib/frameit/editor.rb', line 33

def load_frame
  TemplateFinder.get_template(screenshot)
end

#prepare_imageObject



37
38
39
# File 'lib/frameit/editor.rb', line 37

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