fontist 1.8.4 → 1.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fontist.rb +4 -0
- data/lib/fontist/cli.rb +3 -18
- data/lib/fontist/font.rb +11 -28
- data/lib/fontist/font_path.rb +29 -0
- data/lib/fontist/formula.rb +4 -4
- data/lib/fontist/index.rb +4 -65
- data/lib/fontist/indexes/base_index.rb +82 -0
- data/lib/fontist/indexes/filename_index.rb +19 -0
- data/lib/fontist/indexes/font_index.rb +21 -0
- data/lib/fontist/indexes/index_formula.rb +36 -0
- data/lib/fontist/version.rb +1 -1
- metadata +9 -5
- data/lib/fontist/index_formula.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b392969d430a5af69c38a73069d5a98cf90a6ef1c246f8cca215a7cd4c1202c
|
4
|
+
data.tar.gz: 97ca59729bf50acefa0bfe5ab23b82050eed8fd6ba4782a6d814a77e44939b4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5911d154187149d2d8ebc81e776b7c4b12e0a8eddf4f2540f3914b41fd29c582a29287b5ed1d3d7cccbe696aeb40908f5039bf350c281e315ac08fffe76e110
|
7
|
+
data.tar.gz: 49a7e53eff6d6b750248141a608cb3e92c03c19130f75f4ff8806c7e55ca0d478cec376ed9eaa273dedff3e05b31057892c0c47367a48f1a3eadd5599ecaf968
|
data/lib/fontist.rb
CHANGED
data/lib/fontist/cli.rb
CHANGED
@@ -52,12 +52,11 @@ module Fontist
|
|
52
52
|
end
|
53
53
|
map remove: :uninstall
|
54
54
|
|
55
|
-
desc "status [FONT]", "Show
|
55
|
+
desc "status [FONT]", "Show paths of FONT or all fonts"
|
56
56
|
def status(font = nil)
|
57
|
-
|
58
|
-
return error("No font is installed.", STATUS_MISSING_FONT_ERROR) if
|
57
|
+
paths = Fontist::Font.status(font)
|
58
|
+
return error("No font is installed.", STATUS_MISSING_FONT_ERROR) if paths.empty?
|
59
59
|
|
60
|
-
print_formulas(formulas)
|
61
60
|
success
|
62
61
|
rescue Fontist::Errors::GeneralError => e
|
63
62
|
handle_error(e)
|
@@ -155,20 +154,6 @@ module Fontist
|
|
155
154
|
Fontist.ui.say(YAML.dump(object))
|
156
155
|
end
|
157
156
|
|
158
|
-
def print_formulas(formulas)
|
159
|
-
formulas.each do |formula, fonts|
|
160
|
-
Fontist.ui.success(formula.key)
|
161
|
-
|
162
|
-
fonts.each do |font, styles|
|
163
|
-
Fontist.ui.success(" #{font.name}")
|
164
|
-
|
165
|
-
styles.each do |style, path|
|
166
|
-
Fontist.ui.success(" #{style.type} (#{path})")
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
157
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
173
158
|
def print_list(formulas)
|
174
159
|
formulas.each do |formula, fonts|
|
data/lib/fontist/font.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "fontist/font_installer"
|
2
|
+
require "fontist/font_path"
|
2
3
|
|
3
4
|
module Fontist
|
4
5
|
class Font
|
@@ -47,9 +48,9 @@ module Fontist
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def status
|
50
|
-
return
|
51
|
+
return installed_paths unless @name
|
51
52
|
|
52
|
-
|
53
|
+
find_system_font || downloadable_font || raise_non_supported_font
|
53
54
|
end
|
54
55
|
|
55
56
|
def list
|
@@ -73,9 +74,14 @@ module Fontist
|
|
73
74
|
return
|
74
75
|
end
|
75
76
|
|
77
|
+
print_paths(paths)
|
78
|
+
end
|
79
|
+
|
80
|
+
def print_paths(paths)
|
76
81
|
Fontist.ui.say("Fonts found at:")
|
77
82
|
paths.each do |path|
|
78
|
-
|
83
|
+
font_path = FontPath.new(path)
|
84
|
+
Fontist.ui.say(font_path.to_s)
|
79
85
|
end
|
80
86
|
end
|
81
87
|
|
@@ -161,37 +167,14 @@ module Fontist
|
|
161
167
|
Fontist::FontistFont.find(name)
|
162
168
|
end
|
163
169
|
|
164
|
-
def
|
165
|
-
|
170
|
+
def installed_paths
|
171
|
+
print_paths(SystemFont.font_paths)
|
166
172
|
end
|
167
173
|
|
168
174
|
def all_formulas
|
169
175
|
Fontist::Formula.all
|
170
176
|
end
|
171
177
|
|
172
|
-
def font_status
|
173
|
-
return unless formula
|
174
|
-
|
175
|
-
statuses = installed_styles([formula])
|
176
|
-
statuses.empty? ? nil : statuses
|
177
|
-
end
|
178
|
-
|
179
|
-
def installed_styles(formulas)
|
180
|
-
filter_blank(formulas) do |formula|
|
181
|
-
filter_blank(formula.fonts) do |font|
|
182
|
-
filter_blank(font.styles) do |style|
|
183
|
-
path(style)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def filter_blank(elements)
|
190
|
-
elements.map { |e| [e, yield(e)] }
|
191
|
-
.to_h
|
192
|
-
.reject { |_k, v| v.nil? || v.empty? }
|
193
|
-
end
|
194
|
-
|
195
178
|
def path(style)
|
196
179
|
font_paths.detect do |path|
|
197
180
|
File.basename(path) == style.font
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "fontist/indexes/filename_index"
|
2
|
+
|
3
|
+
module Fontist
|
4
|
+
class FontPath
|
5
|
+
def initialize(path)
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
[].tap do |s|
|
11
|
+
s << "-"
|
12
|
+
s << @path
|
13
|
+
s << "(from #{formulas.join(' or ')} formula)" if formulas.any?
|
14
|
+
end.join(" ")
|
15
|
+
end
|
16
|
+
|
17
|
+
def formulas
|
18
|
+
@formulas ||= if fontist_font?
|
19
|
+
Indexes::FilenameIndex.from_yaml.load_index_formulas(File.basename(@path)).map(&:name)
|
20
|
+
else
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def fontist_font?
|
26
|
+
@path.start_with?(Fontist.fonts_path.to_s)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/fontist/formula.rb
CHANGED
@@ -21,11 +21,11 @@ module Fontist
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.find(font_name)
|
24
|
-
|
24
|
+
Indexes::FontIndex.from_yaml.load_formulas(font_name).first
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.find_fonts(font_name)
|
28
|
-
formulas =
|
28
|
+
formulas = Indexes::FontIndex.from_yaml.load_formulas(font_name)
|
29
29
|
|
30
30
|
formulas.map do |formula|
|
31
31
|
formula.fonts.select do |f|
|
@@ -35,7 +35,7 @@ module Fontist
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.find_styles(font_name, style_name)
|
38
|
-
formulas =
|
38
|
+
formulas = Indexes::FontIndex.from_yaml.load_formulas(font_name)
|
39
39
|
|
40
40
|
formulas.map do |formula|
|
41
41
|
formula.fonts.map do |f|
|
@@ -57,7 +57,7 @@ module Fontist
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def to_index_formula
|
60
|
-
IndexFormula.new(path)
|
60
|
+
Indexes::IndexFormula.new(path)
|
61
61
|
end
|
62
62
|
|
63
63
|
def path
|
data/lib/fontist/index.rb
CHANGED
@@ -1,72 +1,11 @@
|
|
1
|
-
require_relative "
|
1
|
+
require_relative "indexes/font_index"
|
2
|
+
require_relative "indexes/filename_index"
|
2
3
|
|
3
4
|
module Fontist
|
4
5
|
class Index
|
5
|
-
def self.from_yaml
|
6
|
-
unless File.exist?(Fontist.formula_index_path)
|
7
|
-
raise Errors::FormulaIndexNotFoundError.new("Please fetch index with `fontist update`.")
|
8
|
-
end
|
9
|
-
|
10
|
-
data = YAML.load_file(Fontist.formula_index_path)
|
11
|
-
new(data)
|
12
|
-
end
|
13
|
-
|
14
6
|
def self.rebuild
|
15
|
-
|
16
|
-
|
17
|
-
index.to_yaml
|
18
|
-
end
|
19
|
-
|
20
|
-
def initialize(data = {})
|
21
|
-
@index = {}
|
22
|
-
|
23
|
-
data.each_pair do |font, paths|
|
24
|
-
paths.each do |path|
|
25
|
-
add_index_formula(font, IndexFormula.new(path))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def build
|
31
|
-
Formula.all.each do |formula|
|
32
|
-
add_formula(formula)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def add_formula(formula)
|
37
|
-
formula.fonts.each do |font|
|
38
|
-
add_index_formula(font.name, formula.to_index_formula)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def add_index_formula(font_raw, index_formula)
|
43
|
-
font = normalize_font(font_raw)
|
44
|
-
@index[font] ||= []
|
45
|
-
@index[font] << index_formula unless @index[font].include?(index_formula)
|
46
|
-
end
|
47
|
-
|
48
|
-
def load_formulas(font)
|
49
|
-
index_formulas(font).map(&:to_full)
|
50
|
-
end
|
51
|
-
|
52
|
-
def to_yaml
|
53
|
-
File.write(Fontist.formula_index_path, YAML.dump(to_h))
|
54
|
-
end
|
55
|
-
|
56
|
-
def to_h
|
57
|
-
@index.map do |font, index_formulas|
|
58
|
-
[font, index_formulas.map(&:to_s)]
|
59
|
-
end.to_h
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def index_formulas(font)
|
65
|
-
@index[normalize_font(font)] || []
|
66
|
-
end
|
67
|
-
|
68
|
-
def normalize_font(font)
|
69
|
-
font.downcase
|
7
|
+
Fontist::Indexes::FontIndex.rebuild
|
8
|
+
Fontist::Indexes::FilenameIndex.rebuild
|
70
9
|
end
|
71
10
|
end
|
72
11
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require_relative "index_formula"
|
2
|
+
|
3
|
+
module Fontist
|
4
|
+
module Indexes
|
5
|
+
class BaseIndex
|
6
|
+
def self.from_yaml
|
7
|
+
@from_yaml ||= begin
|
8
|
+
unless File.exist?(path)
|
9
|
+
raise Errors::FormulaIndexNotFoundError.new("Please fetch `#{path}` index with `fontist update`.")
|
10
|
+
end
|
11
|
+
|
12
|
+
data = YAML.load_file(path)
|
13
|
+
new(data)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.path
|
18
|
+
raise NotImplementedError, "Please define path of an index"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.rebuild
|
22
|
+
index = new
|
23
|
+
index.build
|
24
|
+
index.to_yaml
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(data = {})
|
28
|
+
@index = {}
|
29
|
+
|
30
|
+
data.each_pair do |key, paths|
|
31
|
+
paths.each do |path|
|
32
|
+
add_index_formula(key, IndexFormula.new(path))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def build
|
38
|
+
Formula.all.each do |formula|
|
39
|
+
add_formula(formula)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_formula(_formula)
|
44
|
+
raise NotImplementedError, "Please define how to add formula to an index, use #add_index_formula"
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_index_formula(key_raw, index_formula)
|
48
|
+
key = normalize_key(key_raw)
|
49
|
+
@index[key] ||= []
|
50
|
+
@index[key] << index_formula unless @index[key].include?(index_formula)
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_formulas(key)
|
54
|
+
index_formulas(key).map(&:to_full)
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_index_formulas(key)
|
58
|
+
index_formulas(key)
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_yaml
|
62
|
+
File.write(self.class.path, YAML.dump(to_h))
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_h
|
66
|
+
@index.map do |key, index_formulas|
|
67
|
+
[key, index_formulas.map(&:to_s)]
|
68
|
+
end.to_h
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def index_formulas(key)
|
74
|
+
@index[normalize_key(key)] || []
|
75
|
+
end
|
76
|
+
|
77
|
+
def normalize_key(key)
|
78
|
+
key
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "base_index"
|
2
|
+
|
3
|
+
module Fontist
|
4
|
+
module Indexes
|
5
|
+
class FilenameIndex < BaseIndex
|
6
|
+
def self.path
|
7
|
+
Fontist.formula_filename_index_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_formula(formula)
|
11
|
+
formula.fonts.each do |font|
|
12
|
+
font.styles.each do |style|
|
13
|
+
add_index_formula(style.font, formula.to_index_formula)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "base_index"
|
2
|
+
|
3
|
+
module Fontist
|
4
|
+
module Indexes
|
5
|
+
class FontIndex < BaseIndex
|
6
|
+
def self.path
|
7
|
+
Fontist.formula_index_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_formula(formula)
|
11
|
+
formula.fonts.each do |font|
|
12
|
+
add_index_formula(font.name, formula.to_index_formula)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def normalize_key(key)
|
17
|
+
key.downcase
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Fontist
|
2
|
+
module Indexes
|
3
|
+
class IndexFormula
|
4
|
+
def initialize(path)
|
5
|
+
@path = path
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
normalized.sub(/\.yml$/, "")
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
normalized
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_full
|
17
|
+
Formula.new_from_file(full_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(other)
|
21
|
+
to_s == other.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def normalized
|
27
|
+
escaped = Regexp.escape(Fontist.formulas_path.to_s + "/")
|
28
|
+
@path.sub(Regexp.new("^" + escaped), "")
|
29
|
+
end
|
30
|
+
|
31
|
+
def full_path
|
32
|
+
Fontist.formulas_path.join(normalized).to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/fontist/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fontist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: arr-pm
|
@@ -316,6 +316,7 @@ files:
|
|
316
316
|
- lib/fontist/errors.rb
|
317
317
|
- lib/fontist/font.rb
|
318
318
|
- lib/fontist/font_installer.rb
|
319
|
+
- lib/fontist/font_path.rb
|
319
320
|
- lib/fontist/fontist_font.rb
|
320
321
|
- lib/fontist/formula.rb
|
321
322
|
- lib/fontist/formula_paths.rb
|
@@ -359,7 +360,10 @@ files:
|
|
359
360
|
- lib/fontist/import/template_helper.rb
|
360
361
|
- lib/fontist/import/text_helper.rb
|
361
362
|
- lib/fontist/index.rb
|
362
|
-
- lib/fontist/
|
363
|
+
- lib/fontist/indexes/base_index.rb
|
364
|
+
- lib/fontist/indexes/filename_index.rb
|
365
|
+
- lib/fontist/indexes/font_index.rb
|
366
|
+
- lib/fontist/indexes/index_formula.rb
|
363
367
|
- lib/fontist/manifest.rb
|
364
368
|
- lib/fontist/manifest/install.rb
|
365
369
|
- lib/fontist/manifest/locations.rb
|
@@ -408,7 +412,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
408
412
|
version: '0'
|
409
413
|
requirements: []
|
410
414
|
rubygems_version: 3.0.3
|
411
|
-
signing_key:
|
415
|
+
signing_key:
|
412
416
|
specification_version: 4
|
413
417
|
summary: Install openly-licensed fonts on Windows, Linux and Mac!
|
414
418
|
test_files: []
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
class IndexFormula
|
3
|
-
def initialize(path)
|
4
|
-
@path = path
|
5
|
-
end
|
6
|
-
|
7
|
-
def to_s
|
8
|
-
normalized
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_full
|
12
|
-
Formula.new_from_file(full_path)
|
13
|
-
end
|
14
|
-
|
15
|
-
def ==(other)
|
16
|
-
to_s == other.to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def normalized
|
22
|
-
escaped = Regexp.escape(Fontist.formulas_path.to_s + "/")
|
23
|
-
@path.sub(Regexp.new("^" + escaped), "")
|
24
|
-
end
|
25
|
-
|
26
|
-
def full_path
|
27
|
-
Fontist.formulas_path.join(normalized).to_s
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|