web_font 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0d8d2461c2cb78dac3588cd7931d18df3b224fd
4
- data.tar.gz: 29d992b865a5269e535c67a5d570080911a2f88d
3
+ metadata.gz: 184ff8a59aa7e27841c201f7c93f93a6f0eb97c3
4
+ data.tar.gz: 48911740783864c288235ef96f946537fb441f54
5
5
  SHA512:
6
- metadata.gz: 960e90afc819598b1aec864e99ae752dbe19067ffe1c176a083fdda32d57ad78ae3b9a4051ce0a98ff926788b0e1b48a84a3bb54c593d755e6c50f45eac60e03
7
- data.tar.gz: 99006b36361eaf44927a527009f1f6f677d8cb7440bc5ce2a753bf9cba10e0afc7c6335f6a94a1a33b510c343582824cb7da1ebd250759465f3758ca066bb3b4
6
+ metadata.gz: 1a330371700105c9818a37457e735aa32021f9bea2a4a2a7882adaca587d8c61b5dbcaeb1cc68546ee0f5028c5bb1a13c8dccf4458cfb12daf37df47dbb3ad5a
7
+ data.tar.gz: 8c98d1c58047a4429ff5359297b45a419f25ab6632935468855465f279a69f2b83c10ca747d63f4b2f56bd1e5ee7caf787214c4ed3825c5628f6c50097995189
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # WebFont
2
2
 
3
- TODO: Write a gem description
3
+ WebFont is a Ruby library that will help you download fonts from Google. For now, we support only [Google Font](http://www.google.com/fonts).
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,9 +16,36 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install web_font
18
18
 
19
+ ## Dependencies
20
+
21
+ WebFont depends on [wget](http://en.wikipedia.org/wiki/Wget). Make sure you have it installed first.
22
+
23
+ For Ubuntu:
24
+ ```
25
+ sudo apt-get install wget
26
+ ```
27
+
28
+ To download font from Google, you need to have [Google API Key](https://www.google.com/search?q=google+api+key), then set ``GOOGLE_API_KEY`` environment variable.
29
+
19
30
  ## Usage
20
31
 
21
- TODO: Write usage instructions here
32
+ ```ruby
33
+ require 'web_font'
34
+
35
+ ENV['GOOGLE_API_KEY'] = '...'
36
+ WebFont::Data.path = '/some/where/in/your/disk'
37
+
38
+ # First you need to have font index
39
+ WebFont::Data.download
40
+
41
+ # Then you can download font 'Open Sans' and store it in /users/foo
42
+ downloader = WebFont::Downloader.new
43
+ downloader.download('Open Sans', '/users/foo')
44
+
45
+ # You can also find font in index as well
46
+ finder = WebFont::Finder.new
47
+ finder.find('Open Sans')
48
+ ```
22
49
 
23
50
  ## Contributing
24
51
 
data/lib/web_font/data.rb CHANGED
@@ -8,30 +8,52 @@ module WebFont
8
8
  attr_accessor :path
9
9
  end
10
10
 
11
- # Download fonts data from Google and index it
11
+ # Download font index from Google, save it locally and index it.
12
+ #
13
+ # fonts.json schema:
14
+ # {
15
+ # "kind": "webfonts#webfontList",
16
+ # "items": [
17
+ # {
18
+ # "kind": "webfonts#webfont",
19
+ # "family": "ABeeZee",
20
+ # "variants": [
21
+ # "regular",
22
+ # "italic"
23
+ # ],
24
+ # "subsets": [
25
+ # "latin"
26
+ # ],
27
+ # "version": "v1",
28
+ # "lastModified": "2013-12-16",
29
+ # "files": {
30
+ # "regular": "http://themes.googleusercontent.com/static/fonts/abeezee/v1/mE5BOuZKGln_Ex0uYKpIaw.ttf",
31
+ # "italic": "http://themes.googleusercontent.com/static/fonts/abeezee/v1/kpplLynmYgP0YtlJA3atRw.ttf"
32
+ # }
33
+ # },
34
+ # { ... },
35
+ # { ... }
36
+ # ]
37
+ # }
12
38
  #
13
39
  # Returns nothing
14
40
  def self.download
15
- assert_path!
41
+ raise ArgumentError, 'path is empty' unless path
16
42
  raise ArgumentError, "ENV['GOOGLE_API_KEY'] is nil" unless ENV['GOOGLE_API_KEY']
17
43
 
18
44
  FileUtils.mkdir_p(path) unless Dir.exist?(path)
19
45
 
20
46
  url = "https://www.googleapis.com/webfonts/v1/webfonts?key=#{ENV['GOOGLE_API_KEY']}"
21
- system("wget -O #{path}/fonts.json #{url}")
47
+ system("wget -q -O #{path}/fonts.json #{url}")
22
48
 
23
49
  index
24
50
  end
25
51
 
26
- def self.assert_path!
27
- raise ArgumentError, 'path is empty' unless path
28
- end
29
-
30
52
  private
31
53
 
32
- # Index fonts data so it will speed things up when search
33
- #
34
- # Returns nothing
54
+ # Index font data so it will speed things up when searching
55
+ #
56
+ # Returns nothing
35
57
  def self.index
36
58
  indices = {}
37
59
  alphabet = 'a'
@@ -21,7 +21,7 @@ module WebFont
21
21
  filename = File.join(destination_path, "#{font_family}-#{variant}")
22
22
  extname = File.extname(url)
23
23
 
24
- system("wget -O #{filename}#{extname} #{url}") unless File.exist?("#{filename}#{extname}")
24
+ system("wget -q -O #{filename}#{extname} #{url}") unless File.exist?("#{filename}#{extname}")
25
25
  end
26
26
  end
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module WebFont
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end