Module: WebFont::Index

Defined in:
lib/web_font/index.rb

Constant Summary collapse

INDEX_URL =
'https://www.googleapis.com/webfonts/v1/webfonts'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/web_font/index.rb', line 7

def path
  @path
end

Class Method Details

.downloadObject

Download font index from Google, save it locally and index it.

fonts.json schema: {

"kind": "webfonts#webfontList",
"items": [
  {
    "kind": "webfonts#webfont",
    "family": "ABeeZee",
    "variants": [
      "regular",
      "italic"
    ],
    "subsets": [
      "latin"
    ],
    "version": "v1",
    "lastModified": "2013-12-16",
    "files": {
      "regular": "http://themes.googleusercontent.com/static/fonts/abeezee/v1/mE5BOuZKGln_Ex0uYKpIaw.ttf",
      "italic": "http://themes.googleusercontent.com/static/fonts/abeezee/v1/kpplLynmYgP0YtlJA3atRw.ttf"
    }
  },
  { ... },
  { ... }
]

}

Returns nothing



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/web_font/index.rb', line 39

def self.download
  raise 'WebFont::Index.path is empty' unless path
  raise "ENV['GOOGLE_API_KEY'] is empty" unless ENV['GOOGLE_API_KEY']

  FileUtils.mkdir_p(path) unless Dir.exist?(path)

  uri         = "#{INDEX_URL}?key=#{ENV['GOOGLE_API_KEY']}"
  output_path = "#{path}/fonts.json"
  HTTP.get(uri, output_path)

  index
end