web_font 0.0.7 → 0.1.1

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.
@@ -1 +1 @@
1
- {"a":{"start":0,"end":67},"b":{"start":68,"end":99},"c":{"start":100,"end":160},"d":{"start":161,"end":185},"e":{"start":186,"end":204},"f":{"start":205,"end":231},"g":{"start":232,"end":259},"h":{"start":260,"end":272},"i":{"start":273,"end":293},"j":{"start":294,"end":308},"k":{"start":309,"end":326},"l":{"start":327,"end":353},"m":{"start":354,"end":411},"n":{"start":412,"end":435},"o":{"start":436,"end":455},"p":{"start":456,"end":500},"q":{"start":501,"end":508},"r":{"start":509,"end":544},"s":{"start":545,"end":604},"t":{"start":605,"end":620},"u":{"start":621,"end":632},"v":{"start":633,"end":644},"w":{"start":645,"end":651},"y":{"start":652,"end":655},"z":{"start":656,"end":656}}
1
+ {"a":{"start":0,"end":67},"b":{"start":68,"end":99},"c":{"start":100,"end":160},"d":{"start":161,"end":185},"e":{"start":186,"end":204},"f":{"start":205,"end":231},"g":{"start":232,"end":259},"h":{"start":260,"end":272},"i":{"start":273,"end":293},"j":{"start":294,"end":308},"k":{"start":309,"end":326},"l":{"start":327,"end":353},"m":{"start":354,"end":411},"n":{"start":412,"end":435},"o":{"start":436,"end":455},"p":{"start":456,"end":500},"q":{"start":501,"end":508},"r":{"start":509,"end":546},"s":{"start":547,"end":606},"t":{"start":607,"end":622},"u":{"start":623,"end":634},"v":{"start":635,"end":646},"w":{"start":647,"end":653},"y":{"start":654,"end":657},"z":{"start":658,"end":658}}
@@ -7,11 +7,31 @@ describe WebFont::Downloader do
7
7
  after { FileUtils.rm(Dir.glob("#{destination_path}/*.ttf")) }
8
8
 
9
9
  describe '#download' do
10
- it 'downloads all fonts in the item' do
11
- downloader = WebFont::Downloader.new
12
- downloader.download('Open Sans', destination_path)
13
10
 
14
- Dir.glob(File.join(destination_path, '*.ttf')).size.must_equal 10
11
+ describe 'when fonts do not exist in local cache' do
12
+ before { FileUtils.rm(Dir.glob("#{WebFont.test_root}/local_cache/*.ttf")) }
13
+ after { FileUtils.rm(Dir.glob("#{WebFont.test_root}/local_cache/*.ttf")) }
14
+
15
+ it 'downloads all fonts in the item' do
16
+ downloader = WebFont::Downloader.new
17
+ downloader.download('Open Sans', destination_path)
18
+
19
+ Dir.glob(File.join(destination_path, '*.ttf')).size.must_equal 10
20
+ end
21
+ end
22
+
23
+ describe 'when fonts are in local cache' do
24
+ before { FileUtils.copy(Dir.glob('test/data/fonts/*.ttf'), 'test/local_cache/') }
25
+ after { FileUtils.rm(Dir.glob("#{WebFont.test_root}/local_cache/*.ttf")) }
26
+
27
+ it 'copies files from local cache' do
28
+ Dir.glob('test/data/fonts/*.ttf').size.must_equal 11
29
+
30
+ downloader = WebFont::Downloader.new
31
+ downloader.download('Open Sans', destination_path)
32
+
33
+ Dir.glob(File.join(destination_path, '*.ttf')).size.must_equal 10
34
+ end
15
35
  end
16
36
  end
17
37
  end
@@ -1,15 +1,15 @@
1
1
  require './test/test_helper'
2
2
 
3
- describe WebFont::Data do
3
+ describe WebFont::Index do
4
4
  describe '.download' do
5
5
 
6
6
  it 'download google fonts data and creates index.json' do
7
- WebFont::Data.download
7
+ WebFont::Index.download
8
8
 
9
- File.exist?("#{WebFont::Data.path}/fonts.json").must_equal true
10
- File.exist?("#{WebFont::Data.path}/index.json").must_equal true
9
+ File.exist?("#{WebFont::Index.path}/fonts.json").must_equal true
10
+ File.exist?("#{WebFont::Index.path}/index.json").must_equal true
11
11
 
12
- file = File.open("#{WebFont::Data.path}/index.json")
12
+ file = File.open("#{WebFont::Index.path}/index.json")
13
13
  indices = JSON.parse(file.read)
14
14
  file.close
15
15
 
@@ -0,0 +1,64 @@
1
+ require './test/test_helper'
2
+
3
+ describe WebFont::LocalCache do
4
+ before do
5
+ WebFont::LocalCache.cache = true
6
+ WebFont::LocalCache.cache_path = 'test/local_cache'
7
+
8
+ FileUtils.rm_rf([File.join(WebFont::LocalCache.cache_path, '.')])
9
+ end
10
+
11
+ describe '.enable?' do
12
+ describe 'when cache is true and cache_path is exist' do
13
+ it 'returns true' do
14
+ WebFont::LocalCache.enable?.must_equal true
15
+ end
16
+ end
17
+
18
+ describe 'when cache is false and cache_path is exist' do
19
+ before { WebFont::LocalCache.cache = false }
20
+
21
+ it 'returns true' do
22
+ WebFont::LocalCache.enable?.must_equal false
23
+ end
24
+ end
25
+
26
+ describe 'when cache is true and cache_path is not exist' do
27
+ before { WebFont::LocalCache.cache_path = 'test/not_exist' }
28
+
29
+ it 'returns true' do
30
+ WebFont::LocalCache.enable?.must_equal false
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '.save' do
36
+ it 'saves font in local directory' do
37
+ font_name = 'suwannaphum.ttf'
38
+ WebFont::LocalCache.save("test/data/fonts/#{font_name}")
39
+
40
+ File.exist?("test/local_cache/#{font_name}").must_equal true
41
+ end
42
+ end
43
+
44
+ describe '.path' do
45
+ describe 'when font does not exist in local cache' do
46
+ it 'returns nil' do
47
+ path = WebFont::LocalCache.path('font-name.tff')
48
+
49
+ path.must_be_nil
50
+ end
51
+ end
52
+
53
+ describe 'when font exist in local cache' do
54
+ before { FileUtils.copy('test/data/fonts/suwannaphum.ttf', 'test/local_cache') }
55
+
56
+ it 'returns path' do
57
+ filename = 'suwannaphum.ttf'
58
+ path = WebFont::LocalCache.path(filename)
59
+
60
+ path.must_equal "test/local_cache/#{filename}"
61
+ end
62
+ end
63
+ end
64
+ end
Binary file
data/test/test_helper.rb CHANGED
@@ -3,4 +3,7 @@ require 'minitest/autorun'
3
3
  require 'pp'
4
4
 
5
5
  require 'web_font'
6
- WebFont::Data.path = File.join(WebFont.test_root, 'data', 'google')
6
+ WebFont::Index.path = File.join(WebFont.test_root, 'data', 'google')
7
+
8
+ WebFont::LocalCache.cache = true
9
+ WebFont::LocalCache.cache_path = './test/local_cache'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_font
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sophy Eung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-20 00:00:00.000000000 Z
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,15 +66,29 @@ files:
66
66
  - Rakefile
67
67
  - lib/web_font.rb
68
68
  - lib/web_font/command.rb
69
- - lib/web_font/data.rb
70
69
  - lib/web_font/downloader.rb
71
70
  - lib/web_font/finder.rb
71
+ - lib/web_font/index.rb
72
+ - lib/web_font/local_cache.rb
72
73
  - lib/web_font/version.rb
74
+ - test/data/fonts/Open-Sans-300.ttf
75
+ - test/data/fonts/Open-Sans-300italic.ttf
76
+ - test/data/fonts/Open-Sans-600.ttf
77
+ - test/data/fonts/Open-Sans-600italic.ttf
78
+ - test/data/fonts/Open-Sans-700.ttf
79
+ - test/data/fonts/Open-Sans-700italic.ttf
80
+ - test/data/fonts/Open-Sans-800.ttf
81
+ - test/data/fonts/Open-Sans-800italic.ttf
82
+ - test/data/fonts/Open-Sans-italic.ttf
83
+ - test/data/fonts/Open-Sans-regular.ttf
84
+ - test/data/fonts/suwannaphum.ttf
73
85
  - test/data/google/fonts.json
74
86
  - test/data/google/index.json
75
- - test/lib/web_font/data_test.rb
76
87
  - test/lib/web_font/downloader_test.rb
77
88
  - test/lib/web_font/finder_test.rb
89
+ - test/lib/web_font/index_test.rb
90
+ - test/lib/web_font/local_cache_test.rb
91
+ - test/local_cache/suwannaphum.ttf
78
92
  - test/test_helper.rb
79
93
  - web_font.gemspec
80
94
  homepage: https://github.com/ungsophy/web_font
@@ -102,9 +116,22 @@ signing_key:
102
116
  specification_version: 4
103
117
  summary: Download web fonts
104
118
  test_files:
119
+ - test/data/fonts/Open-Sans-300.ttf
120
+ - test/data/fonts/Open-Sans-300italic.ttf
121
+ - test/data/fonts/Open-Sans-600.ttf
122
+ - test/data/fonts/Open-Sans-600italic.ttf
123
+ - test/data/fonts/Open-Sans-700.ttf
124
+ - test/data/fonts/Open-Sans-700italic.ttf
125
+ - test/data/fonts/Open-Sans-800.ttf
126
+ - test/data/fonts/Open-Sans-800italic.ttf
127
+ - test/data/fonts/Open-Sans-italic.ttf
128
+ - test/data/fonts/Open-Sans-regular.ttf
129
+ - test/data/fonts/suwannaphum.ttf
105
130
  - test/data/google/fonts.json
106
131
  - test/data/google/index.json
107
- - test/lib/web_font/data_test.rb
108
132
  - test/lib/web_font/downloader_test.rb
109
133
  - test/lib/web_font/finder_test.rb
134
+ - test/lib/web_font/index_test.rb
135
+ - test/lib/web_font/local_cache_test.rb
136
+ - test/local_cache/suwannaphum.ttf
110
137
  - test/test_helper.rb