fontist 1.8.3 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b8f20509f7376c4f88906c9f5d95d02f965351433b2b9f47c46d7e9e5afbb1e
4
- data.tar.gz: e4c71f47525f2c82f0d098eca47629bc808bd1bbff7c83b39f4ede42fd507c05
3
+ metadata.gz: 7cd7962408633c39bb2cfff2ef8c3c0500842033f80ed7211474eefe98845327
4
+ data.tar.gz: 4630d28fbe5afad9865aeaebfa46e50215eb99cc8e2580466ae1fcb616117cfa
5
5
  SHA512:
6
- metadata.gz: 82f8dc79feec65cd9a1ec567f6168dd9ff06fb7ba4ac7d8fbc58e450dba52380ba98d1d9f559b102ab4c997321565e2ee7fe04ac1b34100b7ce3c66078367b20
7
- data.tar.gz: 2c80173b5683ed435c609f40bdfae52a0be258a1f491228fba93f2feedea1f28141461708b5c2a84385b5dde84af52792465c21dcf709dfd0f9a4f42d142cf57
6
+ metadata.gz: 57ac2451e5911694725ddd4f7f29bb8693e0be8e4397101f1f90c6a83ba353ea51fc7e2c9c0875e1bc0f4f17a466b9191d2c4017a47e971c9bb620bef0ea4a4c
7
+ data.tar.gz: 6aee6a31dd412af421191cb8cb5ca7793d5071bfcb0101666ef7d591abffcb98a7e9a3990978e7268d4e55fb1f0fa339711bffe801f272e08c133cd3c6783a9b
@@ -13,17 +13,17 @@ jobs:
13
13
  strategy:
14
14
  fail-fast: false
15
15
  matrix:
16
- ruby: [ '2.6', '2.5', '2.4' ]
16
+ ruby: [ '2.4', '2.5', '2.6', '2.7' ]
17
17
  os: [ ubuntu-latest, windows-latest, macos-latest ]
18
18
  experimental: [ false ]
19
19
  include:
20
- - ruby: '2.7'
20
+ - ruby: '3.0'
21
21
  os: 'ubuntu-latest'
22
22
  experimental: true
23
- - ruby: '2.7'
23
+ - ruby: '3.0'
24
24
  os: 'windows-latest'
25
25
  experimental: true
26
- - ruby: '2.7'
26
+ - ruby: '3.0'
27
27
  os: 'macos-latest'
28
28
  experimental: true
29
29
 
@@ -37,8 +37,8 @@ jobs:
37
37
  - uses: actions/cache@v1
38
38
  with:
39
39
  path: vendor/bundle
40
- key: bundle-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
41
- restore-keys: bundle-${{ matrix.os }}-${{ matrix.ruby }}
40
+ key: bundle-v2-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
41
+ restore-keys: bundle-v2-${{ matrix.os }}-${{ matrix.ruby }}
42
42
 
43
43
  - if: matrix.os == 'macos-latest'
44
44
  run: brew install lcdf-typetools
data/fontist.gemspec CHANGED
@@ -5,15 +5,15 @@ require "fontist/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fontist"
7
7
  spec.version = Fontist::VERSION
8
- spec.authors = ["Ribose Inc.", "Abu Nashir"]
9
- spec.email = ["operations@ribose.com", "abunashir@gmail.com"]
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com"]
10
10
 
11
- spec.summary = %q{A libarary find or download fonts}
12
- spec.description = %q{A libarary find or download fonts}
11
+ spec.summary = %q{Install openly-licensed fonts on Windows, Linux and Mac!}
12
+ spec.description = %q{Install openly-licensed fonts on Windows, Linux and Mac!}
13
13
  spec.homepage = "https://github.com/fontist/fontist"
14
14
  spec.license = "BSD-2-Clause"
15
15
 
16
- spec.post_install_message = "Please run `fontist update` to fetch formulas"
16
+ spec.post_install_message = "Please run `fontist update` to fetch formulas."
17
17
 
18
18
  spec.metadata["homepage_uri"] = spec.homepage
19
19
  spec.metadata["source_code_uri"] = "https://github.com/fontist/fontist"
@@ -28,20 +28,17 @@ Gem::Specification.new do |spec|
28
28
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
29
29
 
30
30
  spec.add_runtime_dependency "down", "~> 5.0"
31
- spec.add_runtime_dependency "libmspack", "~> 0.1.0"
32
- spec.add_runtime_dependency "rubyzip", "~> 2.3.0"
33
- spec.add_runtime_dependency "seven_zip_ruby", "~> 1.0"
34
- spec.add_runtime_dependency "ruby-ole", "~> 1.0"
35
31
  spec.add_runtime_dependency "thor", "~> 1.0.1"
36
32
  spec.add_runtime_dependency "git", "~> 1.0"
37
33
  spec.add_runtime_dependency "ttfunk", "~> 1.0"
34
+ spec.add_runtime_dependency "excavate", "~> 0.1"
38
35
 
39
36
  spec.add_development_dependency "extract_ttc", "~> 0.1"
40
37
  spec.add_development_dependency "pry"
41
38
  spec.add_development_dependency "bundler", "~> 2.0"
42
39
  spec.add_development_dependency "gem-release"
43
40
  spec.add_development_dependency "nokogiri", "~> 1.0"
44
- spec.add_development_dependency "rake", "~> 12.3.3"
41
+ spec.add_development_dependency "rake", "~> 13"
45
42
  spec.add_development_dependency "rspec", "~> 3.0"
46
43
  spec.add_development_dependency "rubocop", "0.75.0"
47
44
  spec.add_development_dependency "rubocop-rails"
data/lib/fontist.rb CHANGED
@@ -62,4 +62,8 @@ module Fontist
62
62
  def self.formula_index_path
63
63
  Fontist.formulas_repo_path.join("index.yml")
64
64
  end
65
+
66
+ def self.formula_filename_index_path
67
+ Fontist.formulas_repo_path.join("filename_index.yml")
68
+ end
65
69
  end
data/lib/fontist/cli.rb CHANGED
@@ -29,12 +29,14 @@ module Fontist
29
29
  desc "install FONT", "Install font"
30
30
  option :force, type: :boolean, aliases: :f,
31
31
  desc: "Install even if it's already installed in system"
32
- option :confirm_license, type: :boolean, desc: "Confirm license agreement"
32
+ option :accept_all_licenses, type: :boolean, aliases: "--confirm-license", desc: "Accept all license agreements"
33
+ option :hide_licenses, type: :boolean, desc: "Hide license texts"
33
34
  def install(font)
34
35
  Fontist::Font.install(
35
36
  font,
36
37
  force: options[:force],
37
- confirmation: options[:confirm_license] ? "yes" : "no"
38
+ confirmation: options[:accept_all_licenses] ? "yes" : "no",
39
+ hide_licenses: options[:hide_licenses]
38
40
  )
39
41
  success
40
42
  rescue Fontist::Errors::GeneralError => e
@@ -52,12 +54,11 @@ module Fontist
52
54
  end
53
55
  map remove: :uninstall
54
56
 
55
- desc "status [FONT]", "Show status of FONT or all fonts in fontist"
57
+ desc "status [FONT]", "Show paths of FONT or all fonts"
56
58
  def status(font = nil)
57
- formulas = Fontist::Font.status(font)
58
- return error("No font is installed.", STATUS_MISSING_FONT_ERROR) if formulas.empty?
59
+ paths = Fontist::Font.status(font)
60
+ return error("No font is installed.", STATUS_MISSING_FONT_ERROR) if paths.empty?
59
61
 
60
- print_formulas(formulas)
61
62
  success
62
63
  rescue Fontist::Errors::GeneralError => e
63
64
  handle_error(e)
@@ -90,11 +91,13 @@ module Fontist
90
91
  end
91
92
 
92
93
  desc "manifest-install MANIFEST", "Install fonts from MANIFEST (yaml)"
93
- option :confirm_license, type: :boolean, desc: "Confirm license agreement"
94
+ option :accept_all_licenses, type: :boolean, aliases: "--confirm-license", desc: "Accept all license agreements"
95
+ option :hide_licenses, type: :boolean, desc: "Hide license texts"
94
96
  def manifest_install(manifest)
95
97
  paths = Fontist::Manifest::Install.from_file(
96
98
  manifest,
97
- confirmation: options[:confirm_license] ? "yes" : "no"
99
+ confirmation: options[:accept_all_licenses] ? "yes" : "no",
100
+ hide_licenses: options[:hide_licenses]
98
101
  )
99
102
 
100
103
  print_yaml(paths)
@@ -155,20 +158,6 @@ module Fontist
155
158
  Fontist.ui.say(YAML.dump(object))
156
159
  end
157
160
 
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
161
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
173
162
  def print_list(formulas)
174
163
  formulas.each do |formula, fonts|
@@ -14,6 +14,7 @@ module Fontist
14
14
  class TamperedFileError < GeneralError; end
15
15
  class TimeoutError < GeneralError; end
16
16
  class UnknownFontTypeError < GeneralError; end
17
+ class UnknownArchiveError < GeneralError; end
17
18
 
18
19
  class FontError < GeneralError
19
20
  attr_reader :font, :style
data/lib/fontist/font.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require "fontist/font_installer"
2
+ require "fontist/font_path"
2
3
 
3
4
  module Fontist
4
5
  class Font
5
6
  def initialize(options = {})
6
7
  @name = options[:name]
7
8
  @confirmation = options[:confirmation] || "no"
9
+ @hide_licenses = options[:hide_licenses]
8
10
  @force = options[:force] || false
9
11
 
10
12
  check_or_create_fontist_path!
@@ -18,8 +20,8 @@ module Fontist
18
20
  new(name: name).find
19
21
  end
20
22
 
21
- def self.install(name, confirmation: "no", force: false)
22
- new(name: name, confirmation: confirmation, force: force).install
23
+ def self.install(name, options = {})
24
+ new(options.merge(name: name)).install
23
25
  end
24
26
 
25
27
  def self.uninstall(name)
@@ -47,9 +49,9 @@ module Fontist
47
49
  end
48
50
 
49
51
  def status
50
- return installed_statuses unless @name
52
+ return installed_paths unless @name
51
53
 
52
- font_status || downloadable_font || raise_non_supported_font
54
+ find_system_font || downloadable_font || raise_non_supported_font
53
55
  end
54
56
 
55
57
  def list
@@ -64,7 +66,7 @@ module Fontist
64
66
 
65
67
  private
66
68
 
67
- attr_reader :name, :confirmation
69
+ attr_reader :name
68
70
 
69
71
  def find_system_font
70
72
  paths = Fontist::SystemFont.find(name)
@@ -73,9 +75,14 @@ module Fontist
73
75
  return
74
76
  end
75
77
 
78
+ print_paths(paths)
79
+ end
80
+
81
+ def print_paths(paths)
76
82
  Fontist.ui.say("Fonts found at:")
77
83
  paths.each do |path|
78
- Fontist.ui.say("- #{path}")
84
+ font_path = FontPath.new(path)
85
+ Fontist.ui.say(font_path.to_s)
79
86
  end
80
87
  end
81
88
 
@@ -94,6 +101,10 @@ module Fontist
94
101
  @formula ||= Fontist::Formula.find(name)
95
102
  end
96
103
 
104
+ def formulas
105
+ @formulas ||= Fontist::Formula.find_many(name)
106
+ end
107
+
97
108
  def downloadable_font
98
109
  if formula
99
110
  raise Fontist::Errors::MissingFontError.new(name)
@@ -101,8 +112,10 @@ module Fontist
101
112
  end
102
113
 
103
114
  def download_font
104
- if formula
105
- check_and_confirm_required_license(formula)
115
+ return if formulas.empty?
116
+
117
+ formulas.flat_map do |formula|
118
+ confirmation = check_and_confirm_required_license(formula)
106
119
  paths = font_installer(formula).install(confirmation: confirmation)
107
120
 
108
121
  Fontist.ui.say("Fonts installed at:")
@@ -113,19 +126,24 @@ module Fontist
113
126
  end
114
127
 
115
128
  def check_and_confirm_required_license(formula)
116
- if formula.license_required && !confirmation.casecmp("yes").zero?
117
- @confirmation = show_license_and_ask_for_input(formula.license)
129
+ return @confirmation unless formula.license_required
118
130
 
119
- unless confirmation&.casecmp?("yes")
120
- raise Fontist::Errors::LicensingError.new(
121
- "Fontist will not download these fonts unless you accept the terms."
122
- )
123
- end
124
- end
131
+ show_license(formula.license) unless @hide_licenses
132
+ return @confirmation if @confirmation.casecmp?("yes")
133
+
134
+ confirmation = ask_for_agreement
135
+ return confirmation if confirmation&.casecmp?("yes")
136
+
137
+ raise Fontist::Errors::LicensingError.new(
138
+ "Fontist will not download these fonts unless you accept the terms."
139
+ )
125
140
  end
126
141
 
127
- def show_license_and_ask_for_input(license)
142
+ def show_license(license)
128
143
  Fontist.ui.say(license_agrement_message(license))
144
+ end
145
+
146
+ def ask_for_agreement
129
147
  Fontist.ui.ask(
130
148
  "\nDo you accept all presented font licenses, and want Fontist " \
131
149
  "to download these fonts for you? => TYPE 'Yes' or 'No':"
@@ -161,37 +179,14 @@ module Fontist
161
179
  Fontist::FontistFont.find(name)
162
180
  end
163
181
 
164
- def installed_statuses
165
- installed_styles(all_formulas)
182
+ def installed_paths
183
+ print_paths(SystemFont.font_paths)
166
184
  end
167
185
 
168
186
  def all_formulas
169
187
  Fontist::Formula.all
170
188
  end
171
189
 
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
190
  def path(style)
196
191
  font_paths.detect do |path|
197
192
  File.basename(path) == style.font
@@ -1,12 +1,8 @@
1
1
  require "fontist/utils"
2
+ require "excavate"
2
3
 
3
4
  module Fontist
4
5
  class FontInstaller
5
- include Utils::ZipExtractor
6
- include Utils::ExeExtractor
7
- include Utils::MsiExtractor
8
- include Utils::SevenZipExtractor
9
-
10
6
  def initialize(formula)
11
7
  @formula = formula
12
8
  end
@@ -16,7 +12,6 @@ module Fontist
16
12
  raise(Fontist::Errors::LicensingError)
17
13
  end
18
14
 
19
- reinitialize
20
15
  install_font
21
16
  end
22
17
 
@@ -24,10 +19,6 @@ module Fontist
24
19
 
25
20
  attr_reader :formula
26
21
 
27
- def reinitialize
28
- @downloaded = false
29
- end
30
-
31
22
  def install_font
32
23
  fonts_paths = run_in_temp_dir { extract }
33
24
  fonts_paths.empty? ? nil : fonts_paths
@@ -46,47 +37,39 @@ module Fontist
46
37
  end
47
38
 
48
39
  def extract
49
- resource = @formula.resources.first
50
-
51
- [@formula.extract].flatten.each do |operation|
52
- resource = extract_by_operation(operation, resource)
53
- end
54
-
55
- fonts_paths = resource
40
+ archive = download_file(@formula.resources.first)
56
41
 
57
- fonts_paths
42
+ install_fonts_from_archive(archive)
58
43
  end
59
44
 
60
- def extract_by_operation(operation, resource)
61
- method = "#{operation.format}_extract"
62
- if operation.options
63
- send(method, resource, **operation.options.to_h)
64
- else
65
- send(method, resource)
66
- end
67
- end
45
+ def install_fonts_from_archive(archive)
46
+ Fontist.ui.say(%(Installing font "#{@formula.key}".))
68
47
 
69
- def fonts_path
70
- Fontist.fonts_path
48
+ Array.new.tap do |fonts_paths|
49
+ Excavate::Archive.new(archive.path).files(recursive_packages: true) do |path|
50
+ fonts_paths << install_font_file(path) if font_file?(path)
51
+ end
52
+ end
71
53
  end
72
54
 
73
55
  def download_file(source)
74
56
  url = source.urls.first
75
57
  Fontist.ui.say(%(Downloading font "#{@formula.key}" from #{url}))
76
58
 
77
- downloaded_file = Fontist::Utils::Downloader.download(
59
+ Fontist::Utils::Downloader.download(
78
60
  url,
79
61
  sha: source.sha256,
80
62
  file_size: source.file_size,
81
63
  progress_bar: true
82
64
  )
65
+ end
83
66
 
84
- @downloaded = true
85
- downloaded_file
67
+ def font_file?(path)
68
+ source_file?(path) && font_directory?(path)
86
69
  end
87
70
 
88
- def font_file?(filename)
89
- source_files.include?(filename)
71
+ def source_file?(path)
72
+ source_files.include?(File.basename(path))
90
73
  end
91
74
 
92
75
  def source_files
@@ -97,6 +80,27 @@ module Fontist
97
80
  end
98
81
  end
99
82
 
83
+ def font_directory?(path)
84
+ return true unless subdirectory_pattern
85
+
86
+ File.fnmatch?(subdirectory_pattern, File.dirname(path))
87
+ end
88
+
89
+ def subdirectory_pattern
90
+ @subdirectory_pattern ||= "*" + subdirectories.first.chomp("/") unless subdirectories.empty?
91
+ end
92
+
93
+ def subdirectories
94
+ @subdirectories ||= [@formula.extract].flatten.map(&:options).compact.map(&:fonts_sub_dir).compact
95
+ end
96
+
97
+ def install_font_file(source)
98
+ target = Fontist.fonts_path.join(target_filename(File.basename(source))).to_s
99
+ FileUtils.mv(source, target)
100
+
101
+ target
102
+ end
103
+
100
104
  def target_filename(source_filename)
101
105
  target_filenames[source_filename]
102
106
  end