Class: Frameit::FrameDownloader

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

Constant Summary collapse

FRAME_PATH =
'.frameit/devices_frames_2'
HOST_URL =
"https://fastlane.github.io/frameit-frames"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.templates_pathObject



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

def self.templates_path
  File.join(ENV['HOME'], FRAME_PATH, Frameit.frames_version)
end

Instance Method Details

#download_framesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/frameit/frame_downloader.rb', line 6

def download_frames
  print_disclaimer

  require 'json'
  require 'fileutils'

  UI.message("Downloading device frames...")
  FileUtils.mkdir_p(templates_path)

  frames_version = download_file("version.txt")
  File.write(File.join(templates_path, "version.txt"), frames_version)
  UI.important("Using frame version '#{frames_version}', you can optionally lock that version in your Framefile.json using `device_frame_version`")

  files = JSON.parse(download_file("files.json"))
  files.each_with_index do |current, index|
    content = download_file(current, txt: "#{index + 1} of #{files.count} files")
    File.write(File.join(templates_path, current), content)
  end
  File.write(File.join(templates_path, "offsets.json"), download_file("offsets.json"))

  UI.success("Successfully downloaded all required image assets")
end

#frames_exist?(version: "latest") ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/frameit/frame_downloader.rb', line 29

def frames_exist?(version: "latest")
  Dir["#{templates_path}/*.png"].count > 0 && File.read(File.join(templates_path, "version.txt")).to_i > 0
end


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/frameit/frame_downloader.rb', line 41

def print_disclaimer
  UI.header "Device frames disclaimer"
  UI.important "All used device frames are available via Facebook Design: http://facebook.design/devices"
  UI.message "----------------------------------------"
  UI.message "While Facebook has redrawn and shares these assets for the benefit"
  UI.message "of the design community, Facebook does not own any of the underlying"
  UI.message "product or user interface designs."
  UI.message "By accessing these assets, you agree to obtain all necessary permissions"
  UI.message "from the underlying rights holders and/or adhere to any applicable brand"
  UI.message "use guidelines before using them."
  UI.message "Facebook disclaims all express or implied warranties with respect to these assets, including"
  UI.message "non-infringement of intellectual property rights."
  UI.message "----------------------------------------"
end

#templates_pathObject



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

def templates_path
  self.class.templates_path
end