Class: FontSquirrel::Download
- Inherits:
-
Object
- Object
- FontSquirrel::Download
- Defined in:
- lib/fontsquirrel-download/download.rb
Constant Summary collapse
- TEMPLATE =
<<-DOC @font-face { font-family: "{{name}}"; {{src}} font-weight: {{weight}}; font-style: {{style}}; } DOC
Instance Method Summary collapse
- #download! ⇒ Object
- #extract_and_apply! ⇒ Object
-
#initialize(name, options = {}) ⇒ Download
constructor
Provide Font-Name as written in URL of font-squirrel, like TeX-Gyre-Bonum.
- #remove_download_file ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Download
Provide Font-Name as written in URL of font-squirrel, like TeX-Gyre-Bonum
16 17 18 19 20 21 22 23 |
# File 'lib/fontsquirrel-download/download.rb', line 16 def initialize(name, ={}) @options = @name = name FileUtils.mkdir_p @options[:font_dir] unless File.exists? @options[:font_file] FileUtils.touch @options[:font_file] end end |
Instance Method Details
#download! ⇒ Object
25 26 27 |
# File 'lib/fontsquirrel-download/download.rb', line 25 def download! download(@name) end |
#extract_and_apply! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fontsquirrel-download/download.rb', line 29 def extract_and_apply! zipfile = nil quietly do zipfile = Zip::File.open(@options[:tmp_name]) end zipfile.each do |entry| case entry.name when %r{/stylesheet.css$}, "stylesheet.css" append_stylesheet(entry) when /ttf|woff|eot|svg/ extract_font(entry) else puts " skipping #{entry.name}" end end ensure zipfile.close if zipfile.present? end |
#remove_download_file ⇒ Object
49 50 51 |
# File 'lib/fontsquirrel-download/download.rb', line 49 def remove_download_file FileUtils.rm @options[:tmp_name].to_s end |