web_font 0.0.3 → 0.0.4
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/lib/web_font/data.rb +12 -8
- data/lib/web_font/version.rb +1 -1
- data/test/data/google/fonts.json +666 -666
- 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: 1797db0f5be3a95b6051fa734a0792eb31008d2a
|
4
|
+
data.tar.gz: 8335727402909e97cd97e99473fdb68a97e3cee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67a78d99efcd2aee784a49c04394affd67cf59cccd3fa8224398639a7e400be1d26876f42073cc8944b32df85215cfc4744274134adeed314960cf718478cccd
|
7
|
+
data.tar.gz: 756237552de9293071d2fe19b3b5c0ed03d83b22a0616bee67bb47206e6e160b2d8078f8aa4aa2af8682544c5d0ad41306efd85eaafe93978bc7d354be7f013a
|
data/lib/web_font/data.rb
CHANGED
@@ -11,16 +11,20 @@ module WebFont
|
|
11
11
|
# Download fonts data from Google and index it
|
12
12
|
#
|
13
13
|
# Returns nothing
|
14
|
-
def self.download
|
14
|
+
def self.download
|
15
|
+
assert_path!
|
15
16
|
raise ArgumentError, "ENV['GOOGLE_API_KEY'] is nil" unless ENV['GOOGLE_API_KEY']
|
16
17
|
|
17
|
-
|
18
|
-
FileUtils.mkdir_p(destination) unless Dir.exist?(destination)
|
18
|
+
FileUtils.mkdir_p(path) unless Dir.exist?(path)
|
19
19
|
|
20
20
|
url = "https://www.googleapis.com/webfonts/v1/webfonts?key=#{ENV['GOOGLE_API_KEY']}"
|
21
|
-
system("wget -O #{
|
21
|
+
system("wget -O #{path}/fonts.json #{url}")
|
22
22
|
|
23
|
-
index
|
23
|
+
index
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.assert_path!
|
27
|
+
raise ArgumentError, 'path is empty' unless path
|
24
28
|
end
|
25
29
|
|
26
30
|
private
|
@@ -28,12 +32,12 @@ module WebFont
|
|
28
32
|
# Index fonts data so it will speed things up when search
|
29
33
|
#
|
30
34
|
# Returns nothing
|
31
|
-
def self.index
|
35
|
+
def self.index
|
32
36
|
indices = {}
|
33
37
|
alphabet = 'a'
|
34
38
|
indices[alphabet] = { 'start' => 0 }
|
35
39
|
|
36
|
-
hash = JSON.parse(File.open("#{
|
40
|
+
hash = JSON.parse(File.open("#{path}/fonts.json").read)
|
37
41
|
hash['items'].each_with_index do |item, index|
|
38
42
|
family = item['family']
|
39
43
|
|
@@ -46,7 +50,7 @@ module WebFont
|
|
46
50
|
end
|
47
51
|
indices[alphabet]['end'] = hash['items'].size - 1
|
48
52
|
|
49
|
-
File.open("#{
|
53
|
+
File.open("#{path}/index.json", 'w') { |file| file.write(indices.to_json) }
|
50
54
|
end
|
51
55
|
end
|
52
56
|
end
|
data/lib/web_font/version.rb
CHANGED