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 +4 -4
- data/README.md +29 -2
- data/lib/web_font/data.rb +32 -10
- data/lib/web_font/downloader.rb +1 -1
- data/lib/web_font/version.rb +1 -1
- data/test/data/google/fonts.json +2512 -2512
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 184ff8a59aa7e27841c201f7c93f93a6f0eb97c3
|
4
|
+
data.tar.gz: 48911740783864c288235ef96f946537fb441f54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a330371700105c9818a37457e735aa32021f9bea2a4a2a7882adaca587d8c61b5dbcaeb1cc68546ee0f5028c5bb1a13c8dccf4458cfb12daf37df47dbb3ad5a
|
7
|
+
data.tar.gz: 8c98d1c58047a4429ff5359297b45a419f25ab6632935468855465f279a69f2b83c10ca747d63f4b2f56bd1e5ee7caf787214c4ed3825c5628f6c50097995189
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# WebFont
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
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'
|
data/lib/web_font/downloader.rb
CHANGED
@@ -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
|
data/lib/web_font/version.rb
CHANGED