fontist 1.5.1 → 1.6.0

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: a35bdc7e99674109bec5810eb8e57d91516ff93f7cf4aefbb608e0298a010f76
4
- data.tar.gz: fc886de884ebc5309acb9dc6168fd6c2d7f460f11e05d9be8a1ffca8177e3b6f
3
+ metadata.gz: 2dc209840287f224caec09be365402ca43e3605debfed69d01f3f89f12d27093
4
+ data.tar.gz: 2ba6e5c3359cfa30afe30ecf96b4f11311e33c12dcce5053b7e37ea9c1750ce9
5
5
  SHA512:
6
- metadata.gz: 05f4a699ac69711925ebf9f036be06e5f5c302b9fe3cec23974bc7892ff18a73115d2373694784ee11ac8c0620b5df215a50cb9c2f173a6448a1ceb0b688753b
7
- data.tar.gz: a41c8f091f5783cb0f2d0beabc0d92e9059f78415f36593f9de6b18eb1175d4059a38cb60710dd5064f0a8280aaa6ab9a13e68190903ed7ebe011e8b9068d39c
6
+ metadata.gz: b3e2a83f4c56ca2092954e9602827dcc6fe74ba4ba40d52f5e8ce6b0ca532cec67558fcf5a2e24775b13d263843ff2fab045f66838468a9d5fe0f087c3c08e23
7
+ data.tar.gz: 5d8968907e2955e7657044ad60c6c8c66ffc0f90d4e06f219b4bde01ad43f949b8dfc24a3477a6eebd269535d14dd26b7222c841c1f2b216f9e5a9111c9c931d
@@ -13,13 +13,10 @@ module Fontist
13
13
  option :force, type: :boolean, aliases: :f,
14
14
  desc: "Install even if it's already installed in system"
15
15
  def install(font)
16
- fonts_paths = Fontist::Font.install(font, force: options[:force])
17
- Fontist.ui.success("These fonts are found or installed:")
18
- Fontist.ui.success(fonts_paths.join("\n"))
16
+ Fontist::Font.install(font, force: options[:force])
19
17
  STATUS_SUCCESS
20
18
  rescue Fontist::Errors::NonSupportedFontError
21
- Fontist.ui.error("Could not find font '#{font}'.")
22
- STATUS_ERROR
19
+ could_not_find_font(font)
23
20
  end
24
21
 
25
22
  desc "uninstall/remove FONT", "Uninstall font by font or formula"
@@ -32,8 +29,7 @@ module Fontist
32
29
  Fontist.ui.error(e.message)
33
30
  STATUS_ERROR
34
31
  rescue Fontist::Errors::NonSupportedFontError
35
- Fontist.ui.error("Could not find font '#{font}'.")
36
- STATUS_ERROR
32
+ could_not_find_font(font)
37
33
  end
38
34
  map remove: :uninstall
39
35
 
@@ -47,7 +43,7 @@ module Fontist
47
43
  rescue Fontist::Errors::MissingFontError => e
48
44
  error(e.message)
49
45
  rescue Fontist::Errors::NonSupportedFontError
50
- error("Could not find font '#{font}'.")
46
+ could_not_find_font(font)
51
47
  end
52
48
 
53
49
  desc "list [FONT]", "List installation status of FONT or fonts in fontist"
@@ -56,7 +52,7 @@ module Fontist
56
52
  print_list(formulas)
57
53
  success
58
54
  rescue Fontist::Errors::NonSupportedFontError
59
- error("Could not find font '#{font}'.")
55
+ could_not_find_font(font)
60
56
  end
61
57
 
62
58
  desc "update", "Update formulas"
@@ -111,6 +107,15 @@ module Fontist
111
107
  STATUS_SUCCESS
112
108
  end
113
109
 
110
+ def could_not_find_font(font)
111
+ error("Font '#{font}' not found locally nor available in the Fontist " \
112
+ "formula repository.\n" \
113
+ "Perhaps it is available at the latest Fontist formula " \
114
+ "repository.\n" \
115
+ "You can update the formula repository using the command " \
116
+ "`fontist update` and try again.")
117
+ end
118
+
114
119
  def error(message)
115
120
  Fontist.ui.error(message)
116
121
  STATUS_ERROR
@@ -81,7 +81,16 @@ module Fontist
81
81
  attr_reader :name, :confirmation
82
82
 
83
83
  def find_system_font
84
- Fontist::SystemFont.find(name)
84
+ paths = Fontist::SystemFont.find(name)
85
+ unless paths
86
+ Fontist.ui.say(%(Font "#{name}" not found locally.))
87
+ return
88
+ end
89
+
90
+ Fontist.ui.say("Fonts found at:")
91
+ paths.each do |path|
92
+ Fontist.ui.say("- #{path}")
93
+ end
85
94
  end
86
95
 
87
96
  def check_or_create_fontist_path!
@@ -113,7 +122,13 @@ module Fontist
113
122
  def download_font
114
123
  if formula
115
124
  check_and_confirm_required_license(formula)
116
- font_installer(formula).fetch_font(name, confirmation: confirmation)
125
+ paths = font_installer(formula).fetch_font(name,
126
+ confirmation: confirmation)
127
+
128
+ Fontist.ui.say("Fonts installed at:")
129
+ paths.each do |path|
130
+ Fontist.ui.say("- #{path}")
131
+ end
117
132
  end
118
133
  end
119
134
 
@@ -232,6 +247,5 @@ module Fontist
232
247
  def installed(style)
233
248
  path(style) ? true : false
234
249
  end
235
-
236
250
  end
237
251
  end
@@ -109,8 +109,11 @@ module Fontist
109
109
  end
110
110
 
111
111
  def download_file(source)
112
+ url = source[:urls].first
113
+ Fontist.ui.say(%(Downloading font "#{key}" from #{url}))
114
+
112
115
  downloaded_file = Fontist::Utils::Downloader.download(
113
- source[:urls].first,
116
+ url,
114
117
  sha: source[:sha256],
115
118
  file_size: source[:file_size],
116
119
  progress_bar: is_progress_bar_enabled
@@ -121,7 +124,7 @@ module Fontist
121
124
  end
122
125
 
123
126
  def is_progress_bar_enabled
124
- options.nil? ? false : options.fetch(:progress_bar, false)
127
+ options.nil? ? true : options.fetch(:progress_bar, true)
125
128
  end
126
129
  end
127
130
  end
@@ -1,14 +1,18 @@
1
1
  module Fontist
2
2
  module Utils
3
3
  class Cache
4
- def fetch(key)
4
+ def fetch(key, bar: nil)
5
5
  map = load_cache
6
- return downloaded_path(map[key]) if cache_exist?(map[key])
6
+ if cache_exist?(map[key])
7
+ print_bar(bar, map[key]) if bar
8
+
9
+ return downloaded_file(map[key])
10
+ end
7
11
 
8
12
  generated_file = yield
9
13
  path = save_cache(generated_file, key)
10
14
 
11
- downloaded_path(path)
15
+ downloaded_file(path)
12
16
  end
13
17
 
14
18
  private
@@ -21,12 +25,24 @@ module Fontist
21
25
  cache_map_path.exist? ? YAML.load_file(cache_map_path) : {}
22
26
  end
23
27
 
24
- def downloaded_path(path)
25
- File.new(Fontist.downloads_path.join(path))
28
+ def downloaded_file(path)
29
+ File.new(downloaded_path(path))
26
30
  end
27
31
 
28
32
  def cache_exist?(path)
29
- path && File.exist?(Fontist.downloads_path.join(path))
33
+ path && File.exist?(downloaded_path(path))
34
+ end
35
+
36
+ def downloaded_path(path)
37
+ Fontist.downloads_path.join(path)
38
+ end
39
+
40
+ def print_bar(bar, path)
41
+ File.size(downloaded_path(path)).tap do |size|
42
+ bar.total = size
43
+ bar.increment(size)
44
+ bar.finish("cache")
45
+ end
30
46
  end
31
47
 
32
48
  def save_cache(generated_file, key)
@@ -7,13 +7,15 @@ module Fontist
7
7
  # TODO: If the first mirror fails, try the second one
8
8
  @file = file
9
9
  @sha = [sha].flatten.compact
10
- @progress_bar = set_progress_bar(progress_bar)
11
10
  @file_size = (file_size || default_file_size).to_i
11
+ @progress_bar = set_progress_bar(progress_bar)
12
12
  @cache = Cache.new
13
13
  end
14
14
 
15
15
  def download
16
- file = @cache.fetch(@file) { download_file }
16
+ file = @cache.fetch(@file, bar: @progress_bar) do
17
+ download_file
18
+ end
17
19
 
18
20
  if !sha.empty? && !sha.include?(Digest::SHA256.file(file).to_s)
19
21
  raise(Fontist::Errors::TamperedFileError.new(
@@ -46,25 +48,27 @@ module Fontist
46
48
  end
47
49
 
48
50
  def set_progress_bar(progress_bar)
49
- ENV.fetch("TEST_ENV", "") === "CI" ? false : progress_bar
51
+ if ENV.fetch("TEST_ENV", "") === "CI" || progress_bar
52
+ ProgressBar.new(@file_size)
53
+ else
54
+ NullProgressBar.new
55
+ end
50
56
  end
51
57
 
52
58
  def download_file
53
- bar = ProgressBar.new(file_size / byte_to_megabyte)
54
-
55
59
  file = Down.download(
56
60
  @file,
57
61
  open_timeout: 10,
58
62
  read_timeout: 10,
59
63
  content_length_proc: ->(content_length) {
60
- bar.total = content_length / byte_to_megabyte if content_length
64
+ @progress_bar.total = content_length if content_length
61
65
  },
62
66
  progress_proc: -> (progress) {
63
- bar.increment(progress / byte_to_megabyte) if @progress_bar === true
67
+ @progress_bar.increment(progress)
64
68
  }
65
69
  )
66
70
 
67
- puts if @progress_bar === true
71
+ @progress_bar.finish
68
72
 
69
73
  file
70
74
  rescue Down::NotFound
@@ -72,6 +76,20 @@ module Fontist
72
76
  end
73
77
  end
74
78
 
79
+ class NullProgressBar
80
+ def total=(_)
81
+ # do nothing
82
+ end
83
+
84
+ def increment(_)
85
+ # do nothing
86
+ end
87
+
88
+ def finish(_ = nil)
89
+ # do nothing
90
+ end
91
+ end
92
+
75
93
  class ProgressBar
76
94
  def initialize(total)
77
95
  @counter = 1
@@ -83,9 +101,35 @@ module Fontist
83
101
  end
84
102
 
85
103
  def increment(progress)
86
- complete = sprintf("%#.2f%%", ((@counter.to_f / @total.to_f) * 100))
87
- print "\r\e[0KDownloads: #{@counter}MB/#{@total}MB (#{complete})"
88
104
  @counter = progress
105
+ Fontist.ui.print "\r\e[0KDownloads: #{counter_mb}MB/#{total_mb}MB " \
106
+ "(#{completeness})"
107
+ end
108
+
109
+ def finish(message = nil)
110
+ if message
111
+ Fontist.ui.print " (#{message})\n"
112
+ else
113
+ Fontist.ui.print "\n"
114
+ end
115
+ end
116
+
117
+ private
118
+
119
+ def completeness
120
+ sprintf("%#.2f%%", (@counter.fdiv(@total) * 100)) # rubocop:disable Style/FormatStringToken, Metrics/LineLength
121
+ end
122
+
123
+ def counter_mb
124
+ @counter / byte_to_megabyte
125
+ end
126
+
127
+ def total_mb
128
+ @total / byte_to_megabyte
129
+ end
130
+
131
+ def byte_to_megabyte
132
+ @byte_to_megabyte ||= 1024 * 1024
89
133
  end
90
134
  end
91
135
  end
@@ -5,6 +5,8 @@ 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
11
  cabbed_fonts = grep_fonts(cab_file.files, font_ext) || []
10
12
  fonts_paths = extract_cabbed_fonts_to_assets(cabbed_fonts)
@@ -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
@@ -10,6 +10,7 @@ module Fontist
10
10
  zip_file = download_file(resource) if download
11
11
  zip_file ||= resource.urls.first
12
12
 
13
+ Fontist.ui.say(%(Installing font "#{key}".))
13
14
  fonts_paths = unzip_fonts(zip_file)
14
15
  block_given? ? yield(fonts_paths) : fonts_paths
15
16
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.5.1".freeze
2
+ VERSION = "1.6.0".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.6.0
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-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: down