fontist 1.6.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/release.yml +38 -0
- data/.github/workflows/rspec.yml +58 -0
- data/README.md +109 -32
- data/{bin → exe}/fontist +0 -0
- data/fontist.gemspec +4 -2
- data/lib/fontist.rb +10 -3
- data/lib/fontist/cli.rb +63 -42
- data/lib/fontist/errors.rb +14 -11
- data/lib/fontist/font.rb +25 -27
- data/lib/fontist/font_installer.rb +114 -0
- data/lib/fontist/fontist_font.rb +3 -49
- data/lib/fontist/formula.rb +89 -63
- data/lib/fontist/formula_paths.rb +43 -0
- data/lib/fontist/helpers.rb +7 -0
- data/lib/fontist/import/create_formula.rb +15 -30
- data/lib/fontist/import/files/collection_file.rb +6 -1
- data/lib/fontist/import/files/file_requirement.rb +17 -0
- data/lib/fontist/import/files/font_detector.rb +48 -0
- data/lib/fontist/import/formula_builder.rb +7 -3
- data/lib/fontist/import/google_check.rb +1 -1
- data/lib/fontist/import/google_import.rb +3 -4
- data/lib/fontist/import/otf/font_file.rb +17 -3
- data/lib/fontist/import/otfinfo_generate.rb +1 -1
- data/lib/fontist/import/recursive_extraction.rb +74 -13
- data/lib/fontist/index.rb +72 -0
- data/lib/fontist/index_formula.rb +30 -0
- data/lib/fontist/manifest/install.rb +6 -15
- data/lib/fontist/manifest/locations.rb +59 -4
- data/lib/fontist/system_font.rb +22 -49
- data/lib/fontist/system_index.rb +92 -0
- data/lib/fontist/utils.rb +1 -0
- data/lib/fontist/utils/dsl.rb +4 -0
- data/lib/fontist/utils/dsl/collection_font.rb +36 -0
- data/lib/fontist/utils/dsl/font.rb +2 -1
- data/lib/fontist/utils/exe_extractor.rb +6 -5
- data/lib/fontist/utils/zip_extractor.rb +20 -12
- data/lib/fontist/version.rb +1 -1
- metadata +45 -20
- data/.github/workflows/macosx.yml +0 -33
- data/.github/workflows/ubuntu.yml +0 -30
- data/.github/workflows/windows.yml +0 -32
- data/bin/check_google +0 -8
- data/bin/console +0 -11
- data/bin/convert_formulas +0 -8
- data/bin/generate_otfinfo +0 -8
- data/bin/import_google +0 -8
- data/bin/rspec +0 -29
- data/bin/setup +0 -7
- data/lib/fontist/font_formula.rb +0 -130
- data/lib/fontist/formula_template.rb +0 -108
- data/lib/fontist/formulas.rb +0 -56
- data/lib/fontist/manifest/common.rb +0 -60
- data/lib/fontist/registry.rb +0 -43
@@ -1,108 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
class FormulaTemplate
|
3
|
-
def self.create_formula_class(formula)
|
4
|
-
Class.new(FontFormula) do |klass|
|
5
|
-
first_font = (formula.fonts || formula.font_collections.first.fonts).first
|
6
|
-
cleanname = first_font.name.gsub(/ /, "")
|
7
|
-
resource_name = formula.resources.to_h.keys.first
|
8
|
-
font_filename = first_font.styles.first.font
|
9
|
-
|
10
|
-
key formula.key&.to_sym || formula.name.gsub(/ /, "_").downcase.to_sym
|
11
|
-
display_progress_bar formula.display_progress_bar if formula.display_progress_bar
|
12
|
-
desc formula.description
|
13
|
-
homepage formula.homepage
|
14
|
-
|
15
|
-
formula.resources.to_h.each do |filename, options|
|
16
|
-
resource filename do
|
17
|
-
urls options.urls
|
18
|
-
sha256 options.sha256
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
if formula.font_collections
|
23
|
-
formula.font_collections.each do |collection|
|
24
|
-
provides_font_collection do
|
25
|
-
filename collection.filename
|
26
|
-
|
27
|
-
collection.fonts.each do |font|
|
28
|
-
styles = font.styles.map { |s| [s.type, s.full_name] }.to_h
|
29
|
-
provides_font font.name, extract_styles_from_collection: styles
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
if formula.fonts
|
36
|
-
formula.fonts.each do |font|
|
37
|
-
provides_font(
|
38
|
-
font.name,
|
39
|
-
match_styles_from_file: font.styles.map do |style|
|
40
|
-
{
|
41
|
-
family_name: style.family_name,
|
42
|
-
style: style.type,
|
43
|
-
full_name: style.full_name,
|
44
|
-
post_script_name: style.post_script_name,
|
45
|
-
version: style.version,
|
46
|
-
description: style.description,
|
47
|
-
filename: style.font,
|
48
|
-
copyright: style.copyright,
|
49
|
-
}
|
50
|
-
end
|
51
|
-
)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
klass.define_method :extract do
|
56
|
-
resource = resource(resource_name)
|
57
|
-
|
58
|
-
[formula.extract].flatten.each do |operation|
|
59
|
-
method = "#{operation.format}_extract"
|
60
|
-
resource = if operation.options
|
61
|
-
send(method, resource, **operation.options.to_h)
|
62
|
-
else
|
63
|
-
send(method, resource)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
if formula.fonts
|
68
|
-
formula.fonts.each do |font|
|
69
|
-
match_fonts(resource, font.name)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
if formula.font_collections
|
74
|
-
formula.font_collections.each do |collection|
|
75
|
-
collection.fonts.each do |font|
|
76
|
-
match_fonts(resource, font.name)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
klass.define_method :install do
|
83
|
-
case platform
|
84
|
-
when :macos
|
85
|
-
install_matched_fonts "$HOME/Library/Fonts/#{cleanname}"
|
86
|
-
when :linux
|
87
|
-
install_matched_fonts "/usr/share/fonts/truetype/#{cleanname.downcase}"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
test do
|
92
|
-
case platform
|
93
|
-
when :macos
|
94
|
-
assert_predicate "$HOME/Library/Fonts/#{cleanname}/#{font_filename}", :exist?
|
95
|
-
when :linux
|
96
|
-
assert_predicate "/usr/share/fonts/truetype/#{cleanname.downcase}/#{font_filename}", :exist?
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
copyright formula.copyright
|
101
|
-
license_url formula.license_url
|
102
|
-
|
103
|
-
open_license formula.open_license if formula.open_license
|
104
|
-
requires_license_agreement formula.requires_license_agreement if formula.requires_license_agreement
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
data/lib/fontist/formulas.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require "git"
|
2
|
-
require "fontist/utils"
|
3
|
-
require "fontist/font_formula"
|
4
|
-
require "fontist/formula_template"
|
5
|
-
|
6
|
-
module Fontist
|
7
|
-
module Formulas
|
8
|
-
def self.register_formulas
|
9
|
-
load_formulas
|
10
|
-
update_registry
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.fetch_formulas
|
14
|
-
if Dir.exist?(Fontist.formulas_repo_path)
|
15
|
-
Git.open(Fontist.formulas_repo_path).pull
|
16
|
-
else
|
17
|
-
Git.clone(Fontist.formulas_repo_url,
|
18
|
-
Fontist.formulas_repo_path,
|
19
|
-
depth: 1)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.load_formulas
|
24
|
-
Dir[Fontist.formulas_path.join("**/*.yml").to_s].sort.each do |file|
|
25
|
-
create_formula_class(file)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.create_formula_class(file)
|
30
|
-
formula = parse_to_object(YAML.load_file(file))
|
31
|
-
class_name = name_to_classname(formula.name)
|
32
|
-
return if Formulas.const_defined?(class_name)
|
33
|
-
|
34
|
-
klass = FormulaTemplate.create_formula_class(formula)
|
35
|
-
Formulas.const_set(class_name, klass)
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.parse_to_object(hash)
|
39
|
-
JSON.parse(hash.to_json, object_class: OpenStruct)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.update_registry
|
43
|
-
Formulas.constants.select do |constant|
|
44
|
-
if Formulas.const_get(constant).is_a?(Class)
|
45
|
-
klass = "Fontist::Formulas::#{constant}"
|
46
|
-
Fontist::Registry.register(Object.const_get(klass))
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.name_to_classname(name)
|
52
|
-
cleanname = name.gsub(/ /, "").sub(/\S/, &:upcase)
|
53
|
-
"#{cleanname}Font"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
module Manifest
|
3
|
-
class Common
|
4
|
-
def initialize(manifest)
|
5
|
-
@manifest = manifest
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.call(manifest)
|
9
|
-
new(manifest).call
|
10
|
-
end
|
11
|
-
|
12
|
-
def call
|
13
|
-
font_names.zip(font_paths).to_h
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def font_names
|
19
|
-
fonts.keys
|
20
|
-
end
|
21
|
-
|
22
|
-
def fonts
|
23
|
-
@fonts ||= begin
|
24
|
-
unless File.exist?(@manifest)
|
25
|
-
raise Fontist::Errors::ManifestCouldNotBeFoundError
|
26
|
-
end
|
27
|
-
|
28
|
-
fonts = YAML.load_file(@manifest)
|
29
|
-
unless fonts.is_a?(Hash)
|
30
|
-
raise Fontist::Errors::ManifestCouldNotBeReadError
|
31
|
-
end
|
32
|
-
|
33
|
-
fonts
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def font_paths
|
38
|
-
fonts.map do |font, styles|
|
39
|
-
styles_to_ary = [styles].flatten
|
40
|
-
style_paths_map(font, styles_to_ary)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def style_paths_map(font, names)
|
45
|
-
paths = style_paths(font, names)
|
46
|
-
names.zip(paths).to_h
|
47
|
-
end
|
48
|
-
|
49
|
-
def style_paths(font, names)
|
50
|
-
names.map do |style|
|
51
|
-
file_paths(font, style)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def file_paths(_font, _style)
|
56
|
-
raise NotImplementedError.new("Implement #file_paths in child class")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/fontist/registry.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
module Fontist
|
2
|
-
class Registry
|
3
|
-
include Singleton
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@formulas ||= {}
|
7
|
-
end
|
8
|
-
|
9
|
-
def formulas
|
10
|
-
parse_to_object(@formulas)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.formulas
|
14
|
-
instance.formulas
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.register(formula, key = nil)
|
18
|
-
key ||= formula.instance.key || formula.to_s
|
19
|
-
instance.register(formula, key)
|
20
|
-
end
|
21
|
-
|
22
|
-
def register(formula, key)
|
23
|
-
@formulas[key] = build_formula_data(formula)
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def build_formula_data(formula)
|
29
|
-
{
|
30
|
-
installer: formula,
|
31
|
-
fonts: formula.instance.fonts,
|
32
|
-
license: formula.instance.license,
|
33
|
-
homepage: formula.instance.homepage ,
|
34
|
-
description: formula.instance.description,
|
35
|
-
license_required: formula.instance.license_required,
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
def parse_to_object(data)
|
40
|
-
JSON.parse(data.to_json, object_class: OpenStruct)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|