Sha256: 9f73a43ed22fd9ec8bb4eb733c088d19de3164d64db7e716a6de58ae9c74340b
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
module WebFont class Downloader attr_reader :finder def initialize @finder = Finder.new end # Download font from Google and save it locally # # Returns nothing def download(font_family, destination_path, from_cache = true) downloaded_fonts = [] item = finder.find(font_family) return downloaded_fonts if item.empty? font_family = item['family'].gsub(/\s/, '-') item['files'].each do |variant, url| filename = "#{font_family}-#{variant}#{File.extname(url)}" font_path = File.join(destination_path, filename) if from_cache && LocalCache.enable? && cache_path = LocalCache.path(filename) FileUtils.copy(cache_path, destination_path) downloaded_fonts << font_path else unless File.exist?(font_path) Command.wget(url, font_path) LocalCache.save(font_path) downloaded_fonts << font_path end end end downloaded_fonts end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
web_font-0.1.14 | lib/web_font/downloader.rb |
web_font-0.1.13 | lib/web_font/downloader.rb |