fontist 1.0.0 → 1.1.0
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/fontist.rb +0 -2
- data/lib/fontist/font_formula.rb +10 -3
- data/lib/fontist/formulas/cleartype_fonts.rb +1 -0
- data/lib/fontist/system.yml +1 -0
- data/lib/fontist/system_font.rb +2 -2
- data/lib/fontist/utils.rb +1 -0
- data/lib/fontist/utils/downloader.rb +72 -0
- data/lib/fontist/utils/dsl.rb +4 -0
- data/lib/fontist/version.rb +1 -1
- data/spec/fontist/system_font_spec.rb +5 -0
- data/spec/fontist/{downloader_spec.rb → utils/downloader_spec.rb} +3 -3
- metadata +4 -4
- data/lib/fontist/downloader.rb +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec6fb2284e060c8f43ac62c16a9777d25d20886ef2ff687eecdfb963980bb350
|
4
|
+
data.tar.gz: ddcba3ee0f0a7c75f23532d7809c7c40492583ba032b4ebbc204d0730f6af9a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bfc0b3cb5597ceca0474c95d47a26e993ccf91773b4a17b10f08c84ac2ec4dfed40d3a271b309c6b2f7c77cd14dca5978b88a274c7aba3ba3ee95b25afcea30
|
7
|
+
data.tar.gz: af007b2fda60f2f53bf2be5c107bf27ec423b9759f62c6827bdecc50ed62bf56a4f4f0969ec9d74f91631f92cad75c0564182424ef2b5754ead6c9335ae87ac1
|
data/lib/fontist.rb
CHANGED
data/lib/fontist/font_formula.rb
CHANGED
@@ -6,7 +6,7 @@ module Fontist
|
|
6
6
|
include Fontist::Utils::ExeExtractor
|
7
7
|
|
8
8
|
attr_accessor :license, :license_url, :license_required
|
9
|
-
attr_accessor :key, :homepage, :description, :temp_resource
|
9
|
+
attr_accessor :key, :homepage, :description, :options, :temp_resource
|
10
10
|
|
11
11
|
def font_list
|
12
12
|
@font_list ||= []
|
@@ -105,12 +105,19 @@ module Fontist
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def download_file(source)
|
108
|
-
downloaded_file = Fontist::Downloader.download(
|
109
|
-
source[:urls].sample,
|
108
|
+
downloaded_file = Fontist::Utils::Downloader.download(
|
109
|
+
source[:urls].sample,
|
110
|
+
sha: source[:sha256],
|
111
|
+
file_size: source[:file_size],
|
112
|
+
progress_bar: is_progress_bar_enabled
|
110
113
|
)
|
111
114
|
|
112
115
|
@downloaded = true
|
113
116
|
downloaded_file
|
114
117
|
end
|
118
|
+
|
119
|
+
def is_progress_bar_enabled
|
120
|
+
options.nil? ? false : options.fetch(:progress_bar, false)
|
121
|
+
end
|
115
122
|
end
|
116
123
|
end
|
data/lib/fontist/system.yml
CHANGED
data/lib/fontist/system_font.rb
CHANGED
@@ -29,8 +29,8 @@ module Fontist
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def lookup_using_font_name
|
32
|
-
font_names = map_name_to_valid_font_names
|
33
|
-
font_paths.grep(/#{font_names.join("|")}/i)
|
32
|
+
font_names = map_name_to_valid_font_names || []
|
33
|
+
font_paths.grep(/#{font_names.join("|")}/i) unless font_names.empty?
|
34
34
|
end
|
35
35
|
|
36
36
|
def fontist_fonts_path
|
data/lib/fontist/utils.rb
CHANGED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Utils
|
3
|
+
class Downloader
|
4
|
+
def initialize(file, file_size: nil, sha: nil, progress_bar: nil)
|
5
|
+
@file = file
|
6
|
+
@progress_bar = progress_bar
|
7
|
+
@sha = [sha].flatten.compact
|
8
|
+
@file_size = (file_size || default_file_size).to_i
|
9
|
+
end
|
10
|
+
|
11
|
+
def download
|
12
|
+
file = download_file
|
13
|
+
|
14
|
+
if !sha.empty? && !sha.include?(Digest::SHA256.file(file).to_s)
|
15
|
+
raise(Fontist::Errors::TemparedFileError.new(
|
16
|
+
"The downloaded file from #{@file} doesn't " \
|
17
|
+
"match with the expected sha256 checksum!"
|
18
|
+
))
|
19
|
+
end
|
20
|
+
|
21
|
+
file
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.download(file, options = {})
|
25
|
+
new(file, options).download
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :file, :sha, :file_size
|
31
|
+
|
32
|
+
def default_file_size
|
33
|
+
5 * byte_to_megabyte
|
34
|
+
end
|
35
|
+
|
36
|
+
def byte_to_megabyte
|
37
|
+
@byte_to_megabyte ||= 1024 * 1024
|
38
|
+
end
|
39
|
+
|
40
|
+
def download_path
|
41
|
+
options[:download_path] || Fontist.root_path.join("tmp")
|
42
|
+
end
|
43
|
+
|
44
|
+
def download_file
|
45
|
+
bar = ProgressBar.new(file_size / byte_to_megabyte)
|
46
|
+
|
47
|
+
Down.download(
|
48
|
+
@file,
|
49
|
+
progress_proc: -> (progress) {
|
50
|
+
bar.increment(progress / byte_to_megabyte) if @progress_bar === true
|
51
|
+
}
|
52
|
+
)
|
53
|
+
|
54
|
+
rescue Down::NotFound
|
55
|
+
raise(Fontist::Errors::InvalidResourceError.new("Invalid URL: #{@file}"))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class ProgressBar
|
60
|
+
def initialize(total)
|
61
|
+
@counter = 1
|
62
|
+
@total = total
|
63
|
+
end
|
64
|
+
|
65
|
+
def increment(progress)
|
66
|
+
complete = sprintf("%#.2f%%", ((@counter.to_f / @total.to_f) * 100))
|
67
|
+
print "\r\e[0KDownloads: #{@counter}MB/#{@total}MB (#{complete})"
|
68
|
+
@counter = progress
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/fontist/utils/dsl.rb
CHANGED
data/lib/fontist/version.rb
CHANGED
@@ -24,6 +24,11 @@ RSpec.describe Fontist::SystemFont do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
context "with invalid font" do
|
27
|
+
it "returns nil for partial-not match" do
|
28
|
+
name = "Deje"
|
29
|
+
expect(Fontist::SystemFont.find(name)).to be_nil
|
30
|
+
end
|
31
|
+
|
27
32
|
it "returns nill to the caller" do
|
28
33
|
name = "invalid-font.ttf"
|
29
34
|
invalid_font = Fontist::SystemFont.find(name, sources: [font_sources])
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
RSpec.describe Fontist::Downloader do
|
3
|
+
RSpec.describe Fontist::Utils::Downloader do
|
4
4
|
describe ".download" do
|
5
5
|
it "return the valid downloaded file" do
|
6
|
-
tempfile = Fontist::Downloader.download(
|
6
|
+
tempfile = Fontist::Utils::Downloader.download(
|
7
7
|
sample_file[:file],
|
8
8
|
sha: sample_file[:sha],
|
9
9
|
file_size: sample_file[:file_size],
|
@@ -15,7 +15,7 @@ RSpec.describe Fontist::Downloader do
|
|
15
15
|
|
16
16
|
it "raises an error for tempared file" do
|
17
17
|
expect{
|
18
|
-
Fontist::Downloader.download(
|
18
|
+
Fontist::Utils::Downloader.download(
|
19
19
|
sample_file[:file],
|
20
20
|
sha: sample_file[:sha] + "mm",
|
21
21
|
file_size: sample_file[:file_size]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fontist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: down
|
@@ -131,7 +131,6 @@ files:
|
|
131
131
|
- bin/setup
|
132
132
|
- fontist.gemspec
|
133
133
|
- lib/fontist.rb
|
134
|
-
- lib/fontist/downloader.rb
|
135
134
|
- lib/fontist/errors.rb
|
136
135
|
- lib/fontist/font.rb
|
137
136
|
- lib/fontist/font_formula.rb
|
@@ -157,12 +156,12 @@ files:
|
|
157
156
|
- lib/fontist/system.yml
|
158
157
|
- lib/fontist/system_font.rb
|
159
158
|
- lib/fontist/utils.rb
|
159
|
+
- lib/fontist/utils/downloader.rb
|
160
160
|
- lib/fontist/utils/dsl.rb
|
161
161
|
- lib/fontist/utils/exe_extractor.rb
|
162
162
|
- lib/fontist/utils/zip_extractor.rb
|
163
163
|
- lib/fontist/version.rb
|
164
164
|
- spec/fixtures/fonts/DejaVuSerif.ttf
|
165
|
-
- spec/fontist/downloader_spec.rb
|
166
165
|
- spec/fontist/font_formula_spec.rb
|
167
166
|
- spec/fontist/font_spec.rb
|
168
167
|
- spec/fontist/formula_spec.rb
|
@@ -184,6 +183,7 @@ files:
|
|
184
183
|
- spec/fontist/formulas/webding_font_spec.rb
|
185
184
|
- spec/fontist/registry_spec.rb
|
186
185
|
- spec/fontist/system_font_spec.rb
|
186
|
+
- spec/fontist/utils/downloader_spec.rb
|
187
187
|
- spec/fontist_spec.rb
|
188
188
|
- spec/spec_helper.rb
|
189
189
|
- spec/support/fontist_helper.rb
|
data/lib/fontist/downloader.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
class Downloader
|
3
|
-
def initialize(file, file_size: nil, sha: nil, progress: nil)
|
4
|
-
@file = file
|
5
|
-
@progress = progress
|
6
|
-
@sha = [sha].flatten.compact
|
7
|
-
@file_size = (file_size || default_file_size).to_i
|
8
|
-
end
|
9
|
-
|
10
|
-
def download
|
11
|
-
file = download_file
|
12
|
-
|
13
|
-
if !sha.empty? && !sha.include?(Digest::SHA256.file(file).to_s)
|
14
|
-
raise(Fontist::Errors::TemparedFileError.new(
|
15
|
-
"The downloaded file from #{@file} doesn't " \
|
16
|
-
"match with the expected sha256 checksum!"
|
17
|
-
))
|
18
|
-
end
|
19
|
-
|
20
|
-
file
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.download(file, options = {})
|
24
|
-
new(file, options).download
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
attr_reader :file, :sha, :file_size
|
30
|
-
|
31
|
-
def default_file_size
|
32
|
-
5 * byte_to_megabyte
|
33
|
-
end
|
34
|
-
|
35
|
-
def byte_to_megabyte
|
36
|
-
@byte_to_megabyte ||= 1024 * 1024
|
37
|
-
end
|
38
|
-
|
39
|
-
def download_path
|
40
|
-
options[:download_path] || Fontist.root_path.join("tmp")
|
41
|
-
end
|
42
|
-
|
43
|
-
def download_file
|
44
|
-
bar = ProgressBar.new(file_size / byte_to_megabyte)
|
45
|
-
|
46
|
-
Down.download(
|
47
|
-
@file,
|
48
|
-
progress_proc: -> (progress) {
|
49
|
-
bar.increment(progress / byte_to_megabyte) if @progress === true
|
50
|
-
}
|
51
|
-
)
|
52
|
-
|
53
|
-
rescue Down::NotFound
|
54
|
-
raise(Fontist::Errors::InvalidResourceError.new("Invalid URL: #{@file}"))
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class ProgressBar
|
59
|
-
def initialize(total)
|
60
|
-
@counter = 1
|
61
|
-
@total = total
|
62
|
-
end
|
63
|
-
|
64
|
-
def increment(progress)
|
65
|
-
complete = sprintf("%#.2f%%", ((@counter.to_f / @total.to_f) * 100))
|
66
|
-
print "\r\e[0KDownloads: #{@counter}MB/#{@total}MB (#{complete})"
|
67
|
-
@counter = progress
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|