Class: Frameit::FrameDownloader
- Inherits:
-
Object
- Object
- Frameit::FrameDownloader
- Defined in:
- frameit/lib/frameit/frame_downloader.rb
Constant Summary collapse
- HOST_URL =
"https://fastlane.github.io/frameit-frames"
Class Method Summary collapse
Instance Method Summary collapse
- #download_frames ⇒ Object
- #frames_exist?(version: "latest") ⇒ Boolean
- #print_disclaimer ⇒ Object
- #templates_path ⇒ Object
Class Method Details
.templates_path ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'frameit/lib/frameit/frame_downloader.rb', line 41 def self.templates_path # Previously ~/.frameit/device_frames_2/x legacy_path = File.join(ENV['HOME'], ".frameit/devices_frames_2", Frameit.frames_version) return legacy_path if File.directory?(legacy_path) # New path, being ~/.fastlane/frameit/x return File.join(FastlaneCore.fastlane_user_dir, "frameit", Frameit.frames_version) end |
Instance Method Details
#download_frames ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'frameit/lib/frameit/frame_downloader.rb', line 9 def download_frames print_disclaimer require 'json' require 'fileutils' UI.("Downloading device frames to '#{templates_path}'") FileUtils.mkdir_p(templates_path) frames_version = download_file("version.txt") 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.binwrite(File.join(templates_path, current), content) end File.write(File.join(templates_path, "offsets.json"), download_file("offsets.json")) # Write the version.txt at the very end to properly resume downloads # if it's interrupted File.write(File.join(templates_path, "version.txt"), frames_version) UI.success("Successfully downloaded all required image assets") end |
#frames_exist?(version: "latest") ⇒ Boolean
35 36 37 38 39 |
# File 'frameit/lib/frameit/frame_downloader.rb', line 35 def frames_exist?(version: "latest") version_path = File.join(templates_path, "version.txt") version = File.read(version_path) if File.exist?(version_path) Dir["#{templates_path}/*.png"].count > 0 && version.to_i > 0 end |
#print_disclaimer ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'frameit/lib/frameit/frame_downloader.rb', line 54 def print_disclaimer UI.header("Device frames disclaimer") UI.important("All used device frames are available via Facebook Design: http://facebook.design/devices") UI.("----------------------------------------") UI.("While Facebook has redrawn and shares these assets for the benefit") UI.("of the design community, Facebook does not own any of the underlying") UI.("product or user interface designs.") UI.("By accessing these assets, you agree to obtain all necessary permissions") UI.("from the underlying rights holders and/or adhere to any applicable brand") UI.("use guidelines before using them.") UI.("Facebook disclaims all express or implied warranties with respect to these assets, including") UI.("non-infringement of intellectual property rights.") UI.("----------------------------------------") end |
#templates_path ⇒ Object
50 51 52 |
# File 'frameit/lib/frameit/frame_downloader.rb', line 50 def templates_path self.class.templates_path end |