fontist 1.5.1 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,10 @@ module Fontist
5
5
  download = @downloaded === true ? false : download
6
6
 
7
7
  exe_file = download_file(exe_file).path if download
8
+
9
+ Fontist.ui.say(%(Installing font "#{key}".))
8
10
  cab_file = decompressor.search(exe_file)
9
- cabbed_fonts = grep_fonts(cab_file.files, font_ext) || []
11
+ cabbed_fonts = grep_fonts(cab_file.files) || []
10
12
  fonts_paths = extract_cabbed_fonts_to_assets(cabbed_fonts)
11
13
 
12
14
  block_given? ? yield(fonts_paths) : fonts_paths
@@ -27,10 +29,10 @@ module Fontist
27
29
  )
28
30
  end
29
31
 
30
- def grep_fonts(file, font_ext)
32
+ def grep_fonts(file)
31
33
  Array.new.tap do |fonts|
32
34
  while file
33
- fonts.push(file) if file.filename.match(font_ext)
35
+ fonts.push(file) if font_file?(file.filename)
34
36
  file = file.next
35
37
  end
36
38
  end
@@ -39,7 +41,8 @@ module Fontist
39
41
  def extract_cabbed_fonts_to_assets(cabbed_fonts)
40
42
  Array.new.tap do |fonts|
41
43
  cabbed_fonts.each do |font|
42
- font_path = fonts_path.join(font.filename).to_s
44
+ target_filename = target_filename(font.filename)
45
+ font_path = fonts_path.join(target_filename).to_s
43
46
  decompressor.extract(font, font_path)
44
47
 
45
48
  fonts.push(font_path)
@@ -18,6 +18,10 @@ module Fontist
18
18
  def self.ask(message, options = {})
19
19
  new.ask(message, options)
20
20
  end
21
+
22
+ def self.print(message)
23
+ super
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -4,40 +4,49 @@ require "pathname"
4
4
  module Fontist
5
5
  module Utils
6
6
  module ZipExtractor
7
- # fonts_sub_dir is unused now, but formulas have this option
8
- # rubocop:disable Lint/UnusedMethodArgument
9
- def zip_extract(resource, download: true, fonts_sub_dir: "")
7
+ def zip_extract(resource, download: true, fonts_sub_dir: nil)
10
8
  zip_file = download_file(resource) if download
11
9
  zip_file ||= resource.urls.first
12
10
 
13
- fonts_paths = unzip_fonts(zip_file)
11
+ Fontist.ui.say(%(Installing font "#{key}".))
12
+ fonts_paths = unzip_fonts(zip_file, fonts_sub_dir)
14
13
  block_given? ? yield(fonts_paths) : fonts_paths
15
14
  end
16
- # rubocop:enable Lint/UnusedMethodArgument
17
15
 
18
16
  alias_method :unzip, :zip_extract
19
17
 
20
18
  private
21
19
 
22
20
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
23
- def unzip_fonts(file)
21
+ def unzip_fonts(file, subdir)
24
22
  Zip.on_exists_proc = true
25
23
 
26
24
  Array.new.tap do |fonts|
27
25
  Zip::File.open(file) do |zip_file|
28
- zip_file.glob("**/*.{ttf,ttc,otf}").each do |entry|
26
+ zip_file.each do |entry|
29
27
  if entry.name
30
- filename = Pathname.new(entry.name).basename
31
- font_path = fonts_path.join(filename.to_s)
32
- fonts.push(font_path.to_s)
28
+ filename = Pathname.new(entry.name).basename.to_s
29
+ if font_directory?(entry.name, subdir) && font_file?(filename)
30
+ target_filename = target_filename(filename)
31
+ font_path = fonts_path.join(target_filename)
32
+ fonts.push(font_path.to_s)
33
33
 
34
- entry.extract(font_path)
34
+ entry.extract(font_path)
35
+ end
35
36
  end
36
37
  end
37
38
  end
38
39
  end
39
40
  end
40
41
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
42
+
43
+ def font_directory?(path, subdir)
44
+ return true unless subdir
45
+
46
+ dirname = File.dirname(path)
47
+ normalized_pattern = subdir.chomp("/")
48
+ File.fnmatch?(normalized_pattern, dirname)
49
+ end
41
50
  end
42
51
  end
43
52
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.5.1".freeze
2
+ VERSION = "1.7.3".freeze
3
3
  end
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.5.1
4
+ version: 1.7.3
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-11-17 00:00:00.000000000 Z
12
+ date: 2020-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: down
@@ -109,6 +109,20 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '1.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: ttfunk
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.0'
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: extract_ttc
114
128
  requirement: !ruby/object:Gem::Requirement
@@ -284,6 +298,8 @@ files:
284
298
  - lib/fontist/import/extractors/seven_zip_extractor.rb
285
299
  - lib/fontist/import/extractors/zip_extractor.rb
286
300
  - lib/fontist/import/files/collection_file.rb
301
+ - lib/fontist/import/files/file_requirement.rb
302
+ - lib/fontist/import/files/font_detector.rb
287
303
  - lib/fontist/import/formula_builder.rb
288
304
  - lib/fontist/import/formula_serializer.rb
289
305
  - lib/fontist/import/google.rb
@@ -306,16 +322,17 @@ files:
306
322
  - lib/fontist/import/template_helper.rb
307
323
  - lib/fontist/import/text_helper.rb
308
324
  - lib/fontist/manifest.rb
309
- - lib/fontist/manifest/common.rb
310
325
  - lib/fontist/manifest/install.rb
311
326
  - lib/fontist/manifest/locations.rb
312
327
  - lib/fontist/registry.rb
313
328
  - lib/fontist/system.yml
314
329
  - lib/fontist/system_font.rb
330
+ - lib/fontist/system_index.rb
315
331
  - lib/fontist/utils.rb
316
332
  - lib/fontist/utils/cache.rb
317
333
  - lib/fontist/utils/downloader.rb
318
334
  - lib/fontist/utils/dsl.rb
335
+ - lib/fontist/utils/dsl/collection_font.rb
319
336
  - lib/fontist/utils/dsl/font.rb
320
337
  - lib/fontist/utils/exe_extractor.rb
321
338
  - lib/fontist/utils/msi_extractor.rb
@@ -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