fontist 1.5.0 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 398c687688ac621dd160d7245b073764e5203ec1993b4d0db185e9b1ba82ec78
4
- data.tar.gz: 20222086aaa6372fcab4c4f8726821bbeffc1808f939b498bfb369130da9218c
3
+ metadata.gz: a35bdc7e99674109bec5810eb8e57d91516ff93f7cf4aefbb608e0298a010f76
4
+ data.tar.gz: fc886de884ebc5309acb9dc6168fd6c2d7f460f11e05d9be8a1ffca8177e3b6f
5
5
  SHA512:
6
- metadata.gz: 60cae1ca82451a485a94ef95c9472dfe78e7dc8d30df79b3bcf44eb9c4861826ab6f59f8caf030008af2278bed8b2eb0a6ac061e8556c73949fb359b0bfc85c8
7
- data.tar.gz: b702b24e7da4f8ac71ad0fa347a50e73d09171954b986fc2c0cbf8cd206642aed6b770de7e32db4f86e2e409289d401cd9c7d09fe64f775769c38b03038b585e
6
+ metadata.gz: 05f4a699ac69711925ebf9f036be06e5f5c302b9fe3cec23974bc7892ff18a73115d2373694784ee11ac8c0620b5df215a50cb9c2f173a6448a1ceb0b688753b
7
+ data.tar.gz: a41c8f091f5783cb0f2d0beabc0d92e9059f78415f36593f9de6b18eb1175d4059a38cb60710dd5064f0a8280aaa6ab9a13e68190903ed7ebe011e8b9068d39c
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
3
  require "fontist"
5
4
  require "fontist/cli"
6
5
 
@@ -97,6 +97,7 @@ module Fontist
97
97
  desc "create-formula URL", "Create a new formula with fonts from URL"
98
98
  option :name, desc: "Example: Times New Roman"
99
99
  option :mirror, repeatable: true
100
+ option :subarchive, desc: "Subarchive to choose when there are several ones"
100
101
  def create_formula(url)
101
102
  require "fontist/import/create_formula"
102
103
  name = Fontist::Import::CreateFormula.new(url, options).call
@@ -8,9 +8,9 @@ require_relative "formula_builder"
8
8
  module Fontist
9
9
  module Import
10
10
  class CreateFormula
11
- FONT_PATTERN = /(\.ttf|\.otf)$/i.freeze
12
- FONT_COLLECTION_PATTERN = /\.ttc$/i.freeze
13
- LICENSE_PATTERN = /(OFL\.txt|UFL\.txt|LICENSE\.txt)$/i.freeze
11
+ FONT_PATTERN = /(\.ttf|\.otf)/i.freeze
12
+ FONT_COLLECTION_PATTERN = /\.ttc/i.freeze
13
+ LICENSE_PATTERN = /(OFL\.txt|UFL\.txt|LICENSE\.txt|COPYING)$/i.freeze
14
14
 
15
15
  def initialize(url, options = {})
16
16
  @url = url
@@ -42,7 +42,7 @@ module Fontist
42
42
  end
43
43
 
44
44
  def extractor(archive)
45
- RecursiveExtraction.new(archive)
45
+ RecursiveExtraction.new(archive, subarchive: @options[:subarchive])
46
46
  end
47
47
 
48
48
  def font_files(extractor)
@@ -89,7 +89,7 @@ module Fontist
89
89
  def download(url)
90
90
  Fontist::Utils::Downloader.download(url, progress_bar: true).path
91
91
  rescue Errors::InvalidResourceError
92
- Fontist.ui.say("WARN: a mirror is not found '#{url}'")
92
+ Fontist.ui.error("WARN: a mirror is not found '#{url}'")
93
93
  nil
94
94
  end
95
95
 
@@ -98,7 +98,7 @@ module Fontist
98
98
  return output.first if output.size == 1
99
99
 
100
100
  checksums = output.join(", ")
101
- Fontist.ui.say("WARN: SHA256 differs (#{checksums})")
101
+ Fontist.ui.error("WARN: SHA256 differs (#{checksums})")
102
102
  output
103
103
  end
104
104
 
@@ -147,7 +147,13 @@ module Fontist
147
147
  end
148
148
 
149
149
  def open_license
150
- return unless @license_text
150
+ unless @license_text
151
+ Fontist.ui.error("WARN: please add license manually")
152
+ return
153
+ end
154
+
155
+ Fontist.ui.error("WARN: ensure it's an open license, otherwise change \
156
+ to 'requires_license_agreement'")
151
157
 
152
158
  TextHelper.cleanup(@license_text)
153
159
  end
@@ -4,3 +4,5 @@
4
4
  - Overpass Mono
5
5
  - Lato
6
6
  - Open Sans
7
+ - Work Sans
8
+ - Fira Code
@@ -77,7 +77,9 @@ module Fontist
77
77
  def read
78
78
  text = REQUIREMENTS[:otfinfo].call(@path)
79
79
 
80
- text.split("\n")
80
+ text
81
+ .encode("UTF-8", invalid: :replace, replace: "")
82
+ .split("\n")
81
83
  .select { |x| x.include?(":") }
82
84
  .map { |x| x.split(":", 2) }
83
85
  .map { |x| x.map { |y| Fontist::Import::TextHelper.cleanup(y) } }
@@ -4,11 +4,12 @@ require_relative "extractors"
4
4
  module Fontist
5
5
  module Import
6
6
  class RecursiveExtraction
7
- BOTH_FONTS_PATTERN = "**/*.{ttf,otf,ttc}".freeze
7
+ BOTH_FONTS_PATTERN = "**/*.{ttf,otf,ttc}*".freeze
8
8
  ARCHIVE_EXTENSIONS = %w[zip msi exe cab].freeze
9
9
 
10
- def initialize(archive)
10
+ def initialize(archive, subarchive: nil)
11
11
  @archive = archive
12
+ @subarchive = subarchive
12
13
  @operations = []
13
14
  end
14
15
 
@@ -57,6 +58,8 @@ module Fontist
57
58
 
58
59
  def operate_on_archive(archive)
59
60
  extractor = choose_extractor(archive)
61
+ Fontist.ui.say("Extracting #{archive} with #{extractor.class.name}")
62
+
60
63
  save_operation(extractor)
61
64
  extractor.extract
62
65
  end
@@ -87,9 +90,33 @@ module Fontist
87
90
  end
88
91
 
89
92
  def find_archive(path)
90
- Dir.children(path)
91
- .map { |file_name| File.join(path, file_name) }
92
- .max_by { |file_path| [file_type(file_path), File.size(file_path)] }
93
+ paths = Dir.children(path).map { |file| File.join(path, file) }
94
+ by_subarchive(paths) || by_size(paths)
95
+ end
96
+
97
+ def by_subarchive(paths)
98
+ return unless @subarchive
99
+
100
+ path_found = paths.detect do |path|
101
+ @subarchive == File.basename(path)
102
+ end
103
+
104
+ return unless path_found
105
+
106
+ save_operation_subarchive(path_found)
107
+
108
+ path_found
109
+ end
110
+
111
+ def save_operation_subarchive(path)
112
+ @operations.last[:options] ||= {}
113
+ @operations.last[:options][:subarchive] = File.basename(path)
114
+ end
115
+
116
+ def by_size(paths)
117
+ paths.max_by do |path|
118
+ [file_type(path), File.size(path)]
119
+ end
93
120
  end
94
121
 
95
122
  def file_type(file_path)
@@ -6,7 +6,7 @@ module Fontist
6
6
  return downloaded_path(map[key]) if cache_exist?(map[key])
7
7
 
8
8
  generated_file = yield
9
- path = save_cache(generated_file, key, map)
9
+ path = save_cache(generated_file, key)
10
10
 
11
11
  downloaded_path(path)
12
12
  end
@@ -29,10 +29,13 @@ module Fontist
29
29
  path && File.exist?(Fontist.downloads_path.join(path))
30
30
  end
31
31
 
32
- def save_cache(generated_file, key, map)
32
+ def save_cache(generated_file, key)
33
33
  path = move_to_downloads(generated_file)
34
+
35
+ map = load_cache
34
36
  map[key] = path
35
37
  File.write(cache_map_path, YAML.dump(map))
38
+
36
39
  path
37
40
  end
38
41
 
@@ -12,10 +12,10 @@ module Fontist
12
12
  block_given? ? yield(fonts_paths) : fonts_paths
13
13
  end
14
14
 
15
- def exe_extract(source)
15
+ def exe_extract(source, subarchive: nil)
16
16
  cab_file = decompressor.search(download_file(source).path)
17
- fonts_paths = build_cab_file_hash(cab_file.files)
18
- block_given? ? yield(fonts_paths) : fonts_paths
17
+ subarchive_path = extract_subarchive(cab_file.files, subarchive)
18
+ block_given? ? yield(subarchive_path) : subarchive_path
19
19
  end
20
20
 
21
21
  private
@@ -47,10 +47,11 @@ module Fontist
47
47
  end
48
48
  end
49
49
 
50
- def build_cab_file_hash(file)
50
+ def extract_subarchive(file, subarchive = nil)
51
51
  while file
52
52
  filename = file.filename
53
- if filename.include?("cab") || filename.include?("msi")
53
+
54
+ if subarchive_found?(filename, subarchive)
54
55
  file_path = File.join(Dir.mktmpdir, filename)
55
56
  decompressor.extract(file, file_path)
56
57
 
@@ -60,6 +61,12 @@ module Fontist
60
61
  file = file.next
61
62
  end
62
63
  end
64
+
65
+ def subarchive_found?(filename, subarchive)
66
+ return subarchive == filename if subarchive
67
+
68
+ filename.include?("cab") || filename.include?("msi")
69
+ end
63
70
  end
64
71
  end
65
72
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.5.0".freeze
2
+ VERSION = "1.5.1".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.0
4
+ version: 1.5.1
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-10 00:00:00.000000000 Z
12
+ date: 2020-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: down