fontist 1.20.0 → 1.21.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.
- checksums.yaml +4 -4
- data/.github/workflows/test-and-release.yml +2 -1
- data/README.adoc +1 -1
- data/exe/fontist +1 -2
- data/lib/fontist/cli/thor_ext.rb +79 -0
- data/lib/fontist/cli.rb +2 -0
- data/lib/fontist/config.rb +2 -1
- data/lib/fontist/font.rb +5 -0
- data/lib/fontist/font_installer.rb +22 -51
- data/lib/fontist/formula.rb +6 -0
- data/lib/fontist/helpers.rb +2 -0
- data/lib/fontist/import/create_formula.rb +77 -35
- data/lib/fontist/import/formula_builder.rb +63 -81
- data/lib/fontist/import/google/api.rb +25 -0
- data/lib/fontist/import/google/create_google_formula.rb +89 -0
- data/lib/fontist/import/google_import.rb +63 -32
- data/lib/fontist/import/recursive_extraction.rb +0 -16
- data/lib/fontist/manifest/locations.rb +2 -0
- data/lib/fontist/resources/archive_resource.rb +55 -0
- data/lib/fontist/resources/google_resource.rb +64 -0
- data/lib/fontist/style_version.rb +4 -0
- data/lib/fontist/utils/cache.rb +16 -0
- data/lib/fontist/utils/downloader.rb +9 -2
- data/lib/fontist/utils/ui.rb +10 -2
- data/lib/fontist/version.rb +1 -1
- data/lib/fontist.rb +5 -1
- metadata +8 -6
- data/lib/fontist/import/google/new_fonts_fetcher.rb +0 -146
- data/lib/fontist/import/google/skiplist.yml +0 -12
- data/lib/fontist/import/google_check.rb +0 -27
@@ -1,146 +0,0 @@
|
|
1
|
-
require_relative "../google"
|
2
|
-
require_relative "../otf_parser"
|
3
|
-
|
4
|
-
module Fontist
|
5
|
-
module Import
|
6
|
-
module Google
|
7
|
-
class NewFontsFetcher
|
8
|
-
REPO_PATH = Fontist.fontist_path.join("google", "fonts")
|
9
|
-
REPO_URL = "https://github.com/google/fonts.git".freeze
|
10
|
-
SKIPLIST_PATH = File.expand_path("skiplist.yml", __dir__)
|
11
|
-
|
12
|
-
def initialize(logging: false, limit: nil)
|
13
|
-
@logging = logging
|
14
|
-
@limit = limit
|
15
|
-
end
|
16
|
-
|
17
|
-
def call
|
18
|
-
update_repo
|
19
|
-
fetch_new_paths
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def update_repo
|
25
|
-
if Dir.exist?(REPO_PATH)
|
26
|
-
`cd #{REPO_PATH} && git pull`
|
27
|
-
else
|
28
|
-
FileUtils.mkdir_p(File.dirname(REPO_PATH))
|
29
|
-
`git clone --depth 1 #{REPO_URL} #{REPO_PATH}`
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def fetch_new_paths
|
34
|
-
new_paths = []
|
35
|
-
|
36
|
-
fetch_fonts_paths.each do |path|
|
37
|
-
new = log_font(path) do
|
38
|
-
new?(path)
|
39
|
-
end
|
40
|
-
|
41
|
-
next unless new
|
42
|
-
|
43
|
-
new_paths << path
|
44
|
-
return new_paths if @limit && new_paths.size >= @limit
|
45
|
-
end
|
46
|
-
|
47
|
-
new_paths
|
48
|
-
end
|
49
|
-
|
50
|
-
def fetch_fonts_paths
|
51
|
-
Dir[File.join(REPO_PATH, "apache", "*"),
|
52
|
-
File.join(REPO_PATH, "ofl", "*"),
|
53
|
-
File.join(REPO_PATH, "ufl", "*")].sort
|
54
|
-
end
|
55
|
-
|
56
|
-
def log_font(path)
|
57
|
-
return yield unless @logging
|
58
|
-
|
59
|
-
print "#{path}, "
|
60
|
-
new = yield
|
61
|
-
puts(new ? "new" : "skipped")
|
62
|
-
new
|
63
|
-
end
|
64
|
-
|
65
|
-
def new?(path)
|
66
|
-
metadata_name = Google.metadata_name(path)
|
67
|
-
return unless metadata_name
|
68
|
-
return if in_skiplist?(metadata_name)
|
69
|
-
return if up_to_date?(metadata_name, path)
|
70
|
-
return unless downloadable?(metadata_name)
|
71
|
-
|
72
|
-
true
|
73
|
-
end
|
74
|
-
|
75
|
-
def in_skiplist?(name)
|
76
|
-
@skiplist ||= YAML.safe_load(File.open(SKIPLIST_PATH))
|
77
|
-
@skiplist.include?(name)
|
78
|
-
end
|
79
|
-
|
80
|
-
def up_to_date?(metadata_name, path)
|
81
|
-
formula = formula(metadata_name)
|
82
|
-
return false unless formula
|
83
|
-
|
84
|
-
repo_digest_up_to_date?(formula, path) ||
|
85
|
-
fonts_up_to_date?(formula, path)
|
86
|
-
end
|
87
|
-
|
88
|
-
def repo_digest_up_to_date?(formula, path)
|
89
|
-
return unless formula.digest
|
90
|
-
|
91
|
-
formula.digest == Google.digest(path)
|
92
|
-
end
|
93
|
-
|
94
|
-
def fonts_up_to_date?(formula, path)
|
95
|
-
styles = formula_styles(formula)
|
96
|
-
repo_fonts(path).all? do |font|
|
97
|
-
style = styles.find { |s| s.font == repo_to_archive_name(font) }
|
98
|
-
return false unless style
|
99
|
-
|
100
|
-
otfinfo_version(font) == style.version
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def formula_styles(formula)
|
105
|
-
formula.fonts.map(&:styles).flatten
|
106
|
-
end
|
107
|
-
|
108
|
-
def repo_fonts(path)
|
109
|
-
Dir.glob(File.join(path, "*.{ttf,otf}"))
|
110
|
-
end
|
111
|
-
|
112
|
-
def repo_to_archive_name(font_path)
|
113
|
-
File.basename(font_path)
|
114
|
-
.sub("[wght]", "-VariableFont_wght")
|
115
|
-
.sub("[opsz]", "-Regular-VariableFont_opsz")
|
116
|
-
end
|
117
|
-
|
118
|
-
def formula(font_name)
|
119
|
-
path = Fontist::Import::Google.formula_path(font_name)
|
120
|
-
Formula.new_from_file(path) if File.exist?(path)
|
121
|
-
end
|
122
|
-
|
123
|
-
def otfinfo_version(path)
|
124
|
-
info = OtfParser.new(path).call
|
125
|
-
Fontist::Import::Google.style_version(info["Version"])
|
126
|
-
end
|
127
|
-
|
128
|
-
def downloadable?(name)
|
129
|
-
retries ||= 0
|
130
|
-
retries += 1
|
131
|
-
Down.open("https://fonts.google.com/download?family=#{name}")
|
132
|
-
true
|
133
|
-
rescue Down::NotFound
|
134
|
-
false
|
135
|
-
rescue Down::ClientError => e
|
136
|
-
raise unless e.message == "403 Forbidden"
|
137
|
-
|
138
|
-
false
|
139
|
-
rescue Down::TimeoutError
|
140
|
-
retry unless retries >= 3
|
141
|
-
false
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require_relative "google/new_fonts_fetcher"
|
2
|
-
|
3
|
-
module Fontist
|
4
|
-
module Import
|
5
|
-
class GoogleCheck
|
6
|
-
def call
|
7
|
-
fonts = new_fonts
|
8
|
-
indicate(fonts)
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def new_fonts
|
14
|
-
Fontist::Import::Google::NewFontsFetcher.new(logging: true).call
|
15
|
-
end
|
16
|
-
|
17
|
-
def indicate(new_paths)
|
18
|
-
return if new_paths.empty?
|
19
|
-
|
20
|
-
puts "New fonts are available in:"
|
21
|
-
new_paths.each do |path|
|
22
|
-
puts path
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|