fontist 1.11.2 → 1.11.7

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: 13b78039fab8bac4324cc22dc75a21beac4dd1303853ed782cabf1e89b78617c
4
- data.tar.gz: d9ddc52af7fce3a9650b227170940c78e757266d27215add37cac136b8710548
3
+ metadata.gz: d3a779a1f127060501e1c69c59986bcd1a616ab699c5cff439cec4aafc27a0a2
4
+ data.tar.gz: cbcfe4d0a06ccfbcb309b2c59aac6a58ce09d804c6b23cec5970a6d67b697d43
5
5
  SHA512:
6
- metadata.gz: 8e88289ff2d6acac6c10599332227163d41ac6fcc7ea2f7acb6d2a4c5e62dec6ab814aecc2e807e08f5de4a3491abf69a88e9648d2ef8829dbd4885dfcd8954c
7
- data.tar.gz: 2b67bf621a77b9d9882af25329930e3900c8e852077822dd2582ece1b6528e1fc63ec8c9f7404b89505b8a3d17377e841e476c264e2a7b837dbdab35dfe2c243
6
+ metadata.gz: d17e2fa944c7ddfd142869d1db9df35fae4ae7aa58c6188290529d31be66b9043e300b0cff2e4cb13545fb1bbdc707820fa4c88f557c914cb59ad4b7a1fef46f
7
+ data.tar.gz: 98db0b18012107e2a39644d9c892a7ef5330543526da993f1b346300bba2bcefa02b2b17ff417a716f7e6f3e84d0b7589eda24d4b154366a290010bbe8f9ad0a
@@ -14,7 +14,7 @@ jobs:
14
14
  fail-fast: false
15
15
  matrix:
16
16
  ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0' ]
17
- os: [ ubuntu-latest, windows-latest, macos-latest ]
17
+ os: [ ubuntu-18.04, ubuntu-latest, windows-latest, macos-latest ]
18
18
  experimental: [ false ]
19
19
 
20
20
  steps:
@@ -33,7 +33,15 @@ jobs:
33
33
  env:
34
34
  TEST_ENV: CI
35
35
 
36
- - if: matrix.os != 'macos-latest'
36
+ - if: matrix.os == 'windows-latest' && matrix.ruby == '2.4'
37
+ run: curl -O https://curl.se/ca/cacert.pem
38
+
39
+ - if: matrix.os == 'windows-latest' && matrix.ruby == '2.4'
40
+ run: bundle exec rspec --tag ~dev
41
+ env:
42
+ SSL_CERT_FILE: cacert.pem
43
+
44
+ - if: matrix.os != 'macos-latest' || matrix.os == 'windows-latest' && matrix.ruby == '2.4'
37
45
  run: bundle exec rspec --tag ~dev
38
46
  env:
39
47
  TEST_ENV: CI
data/README.adoc CHANGED
@@ -685,8 +685,8 @@ one, please refer to its documentation.
685
685
  There is an ability to use private fonts via private Fontist repositories.
686
686
 
687
687
  A Fontist repository is a Git repo which contains YAML formula files. Formulas can be created
688
- manually (see https://github.com/fontist/formulas/tree/master/Formulas)[examples],
689
- or #auto-generate-a-formula[auto-generated from an archive].
688
+ manually (see https://github.com/fontist/formulas/tree/master/Formulas[examples]),
689
+ or xref:Authoring Fontist formulas[auto-generated from an archive].
690
690
 
691
691
  A repository can be either a HTTPS or SSH Git repo. In case of SSH, a
692
692
  corresponding SSH key should be setup with `ssh-agent` in order to access this
data/fontist.gemspec CHANGED
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency "nokogiri", "~> 1.0"
41
41
  spec.add_development_dependency "rake", "~> 13"
42
42
  spec.add_development_dependency "rspec", "~> 3.0"
43
+ spec.add_development_dependency "rspec-benchmark", "~> 0.6"
43
44
  spec.add_development_dependency "rubocop", "1.5.2"
44
45
  spec.add_development_dependency "rubocop-rails"
45
46
  spec.add_development_dependency "rubocop-performance"
data/lib/fontist/font.rb CHANGED
@@ -62,7 +62,7 @@ module Fontist
62
62
  end
63
63
 
64
64
  def all
65
- Fontist::Formula.all.map(&:fonts).flatten
65
+ all_formulas.map(&:fonts).flatten
66
66
  end
67
67
 
68
68
  private
@@ -99,11 +99,17 @@ module Fontist
99
99
  end
100
100
 
101
101
  def formula
102
- @formula ||= Fontist::Formula.find(name)
102
+ @formula ||= formulas.first
103
103
  end
104
104
 
105
105
  def formulas
106
106
  @formulas ||= Fontist::Formula.find_many(name)
107
+ .select { |f| supported_formula?(f) }
108
+ end
109
+
110
+ def supported_formula?(formula)
111
+ formula.platforms.nil? ||
112
+ formula.platforms.include?(Fontist::Utils::System.user_os.to_s)
107
113
  end
108
114
 
109
115
  def downloadable_font
@@ -190,7 +196,7 @@ module Fontist
190
196
  end
191
197
 
192
198
  def all_formulas
193
- Fontist::Formula.all
199
+ Fontist::Formula.all.select { |f| supported_formula?(f) }
194
200
  end
195
201
 
196
202
  def path(style)
@@ -54,16 +54,30 @@ module Fontist
54
54
  end
55
55
 
56
56
  def download_file(source)
57
- request = source.urls.first
58
- url = request.respond_to?(:url) ? request.url : request
59
- Fontist.ui.say(%(Downloading font "#{@formula.key}" from #{url}))
57
+ errors = []
58
+ source.urls.each do |request|
59
+ url = request.respond_to?(:url) ? request.url : request
60
+ Fontist.ui.say(%(Downloading font "#{@formula.key}" from #{url}))
60
61
 
62
+ result = try_download_file(request, source)
63
+ return result unless result.is_a?(Errors::InvalidResourceError)
64
+
65
+ errors << result
66
+ end
67
+
68
+ raise Errors::InvalidResourceError, errors.join(" ")
69
+ end
70
+
71
+ def try_download_file(request, source)
61
72
  Fontist::Utils::Downloader.download(
62
73
  request,
63
74
  sha: source.sha256,
64
75
  file_size: source.file_size,
65
76
  progress_bar: !@no_progress
66
77
  )
78
+ rescue Errors::InvalidResourceError => e
79
+ Fontist.ui.say(e.message)
80
+ e
67
81
  end
68
82
 
69
83
  def font_file?(path)
@@ -91,6 +91,10 @@ module Fontist
91
91
  @data["requires_license_agreement"] ? true : false
92
92
  end
93
93
 
94
+ def platforms
95
+ @data["platforms"]
96
+ end
97
+
94
98
  def extract
95
99
  Helpers.parse_to_object(@data["extract"])
96
100
  end
@@ -4,7 +4,7 @@ module Fontist
4
4
  module Import
5
5
  class RecursiveExtraction
6
6
  LICENSE_PATTERN =
7
- /(ofl\.txt|ufl\.txt|licenses?\.txt|license|copying)$/i.freeze
7
+ /(ofl\.txt|ufl\.txt|licenses?\.txt|license(\.md)?|copying)$/i.freeze
8
8
 
9
9
  def initialize(archive, subarchive: nil, subdir: nil)
10
10
  @archive = archive
@@ -70,6 +70,8 @@ module Fontist
70
70
 
71
71
  def extract_data(archive)
72
72
  Excavate::Archive.new(path(archive)).files(recursive_packages: true) do |path|
73
+ next unless File.file?(path)
74
+
73
75
  match_license(path)
74
76
  match_font(path) if font_directory?(path)
75
77
  end
data/lib/fontist/repo.rb CHANGED
@@ -15,8 +15,20 @@ module Fontist
15
15
  raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
16
16
  end
17
17
 
18
- Git.open(path).pull
18
+ git = Git.open(path)
19
+ git.pull("origin", git.current_branch)
20
+
19
21
  Index.rebuild
22
+ rescue Git::GitExecuteError => e
23
+ raise Errors::RepoCouldNotBeUpdatedError.new(<<~MSG.chomp)
24
+ Formulas repo '#{name}' could not be updated.
25
+ Please consider reinitializing it with:
26
+ fontist remove #{name}
27
+ fontist setup #{name} REPO_URL
28
+
29
+ Git error:
30
+ #{e.message}
31
+ MSG
20
32
  end
21
33
 
22
34
  def remove(name)
@@ -12,12 +12,20 @@ module Fontist
12
12
  end
13
13
 
14
14
  def self.system_font_paths
15
+ @system_font_paths ||= load_system_font_paths
16
+ end
17
+
18
+ def self.load_system_font_paths
15
19
  config_path = Fontist.system_file_path
16
20
  os = Fontist::Utils::System.user_os.to_s
17
21
  templates = YAML.load_file(config_path)["system"][os]["paths"]
18
22
  patterns = expand_paths(templates)
19
23
 
20
- Dir.glob(patterns)
24
+ Dir.glob(patterns, File::FNM_CASEFOLD)
25
+ end
26
+
27
+ def self.reset_system_font_paths_cache
28
+ @system_font_paths = nil
21
29
  end
22
30
 
23
31
  def self.expand_paths(paths)
@@ -37,35 +37,39 @@ module Fontist
37
37
  LANGUAGE_MAC_ENGLISH = 0
38
38
  LANGUAGE_MS_ENGLISH_AMERICAN = 0x409
39
39
 
40
- attr_reader :font_paths
41
-
42
40
  def self.system_index
43
- if Fontist.preferred_family?
44
- new(Fontist.system_preferred_family_index_path,
45
- SystemFont.font_paths,
46
- PreferredFamily.new)
47
- else
48
- new(Fontist.system_index_path,
49
- SystemFont.font_paths,
50
- DefaultFamily.new)
51
- end
41
+ path = if Fontist.preferred_family?
42
+ Fontist.system_preferred_family_index_path
43
+ else
44
+ Fontist.system_index_path
45
+ end
46
+
47
+ @system_index ||= {}
48
+ @system_index[Fontist.preferred_family?] ||= {}
49
+ @system_index[Fontist.preferred_family?][path] ||=
50
+ new(path, -> { SystemFont.font_paths }, family)
52
51
  end
53
52
 
54
53
  def self.fontist_index
55
- if Fontist.preferred_family?
56
- new(Fontist.fontist_preferred_family_index_path,
57
- SystemFont.fontist_font_paths,
58
- PreferredFamily.new)
59
- else
60
- new(Fontist.fontist_index_path,
61
- SystemFont.fontist_font_paths,
62
- DefaultFamily.new)
63
- end
54
+ path = if Fontist.preferred_family?
55
+ Fontist.fontist_preferred_family_index_path
56
+ else
57
+ Fontist.fontist_index_path
58
+ end
59
+
60
+ @fontist_index ||= {}
61
+ @fontist_index[Fontist.preferred_family?] ||= {}
62
+ @fontist_index[Fontist.preferred_family?][path] ||=
63
+ new(path, -> { SystemFont.fontist_font_paths }, family)
64
64
  end
65
65
 
66
- def initialize(index_path, font_paths, family)
66
+ def self.family
67
+ Fontist.preferred_family? ? PreferredFamily.new : DefaultFamily.new
68
+ end
69
+
70
+ def initialize(index_path, font_paths_fetcher, family)
67
71
  @index_path = index_path
68
- @font_paths = font_paths
72
+ @font_paths_fetcher = font_paths_fetcher
69
73
  @family = family
70
74
  end
71
75
 
@@ -85,7 +89,18 @@ module Fontist
85
89
  private
86
90
 
87
91
  def index
88
- @index ||= build_index
92
+ return @index unless index_changed?
93
+
94
+ @index = build_index
95
+ end
96
+
97
+ def index_changed?
98
+ @index.nil? ||
99
+ @index.map { |x| x[:path] }.uniq.sort != font_paths.sort
100
+ end
101
+
102
+ def font_paths
103
+ @font_paths_fetcher.call
89
104
  end
90
105
 
91
106
  def build_index
@@ -30,7 +30,14 @@ module Fontist
30
30
  depth: 1)
31
31
  end
32
32
 
33
- git = Git.open(Fontist.formulas_repo_path)
33
+ git = if Dir.exist?(Fontist.formulas_repo_path.join(".git"))
34
+ Git.open(Fontist.formulas_repo_path)
35
+ else
36
+ Git.init(Fontist.formulas_repo_path.to_s).tap do |g|
37
+ g.add_remote("origin", Fontist.formulas_repo_url)
38
+ end
39
+ end
40
+
34
41
  return git.pull("origin", @branch) if git.current_branch == @branch
35
42
 
36
43
  git.config("remote.origin.fetch",
@@ -41,36 +48,11 @@ module Fontist
41
48
  end
42
49
 
43
50
  def update_private_repos
44
- private_repos.each do |path|
45
- update_repo(path)
51
+ Repo.list.each do |name|
52
+ Repo.update(name)
46
53
  end
47
54
  end
48
55
 
49
- def update_repo(path)
50
- Git.open(path).pull
51
- rescue Git::GitExecuteError => e
52
- name = repo_name(path)
53
- raise Errors::RepoCouldNotBeUpdatedError.new(<<~MSG.chomp)
54
- Formulas repo '#{name}' could not be updated.
55
- Please consider reinitializing it with:
56
- fontist remove #{name}
57
- fontist setup #{name} REPO_URL
58
-
59
- Git error:
60
- #{e.message}
61
- MSG
62
- end
63
-
64
- def private_repos
65
- Dir.glob(Fontist.private_formulas_path.join("*")).select do |path|
66
- File.directory?(path)
67
- end
68
- end
69
-
70
- def repo_name(path)
71
- File.basename(path)
72
- end
73
-
74
56
  def rebuild_index
75
57
  Index.rebuild
76
58
  end
@@ -15,7 +15,7 @@ module Fontist
15
15
  @file = file
16
16
  @sha = [sha].flatten.compact
17
17
  @file_size = file_size.to_i if file_size
18
- @progress_bar = set_progress_bar(progress_bar)
18
+ @progress_bar = progress_bar
19
19
  @cache = Cache.new
20
20
  end
21
21
 
@@ -54,35 +54,48 @@ module Fontist
54
54
  options[:download_path] || Fontist.root_path.join("tmp")
55
55
  end
56
56
 
57
- def set_progress_bar(progress_bar)
58
- if progress_bar
57
+ def download_file
58
+ tries = tries ? tries + 1 : 1
59
+ do_download_file
60
+ rescue Down::Error => e
61
+ retry if tries < 3
62
+
63
+ raise Fontist::Errors::InvalidResourceError,
64
+ "Invalid URL: #{@file}. Error: #{e.inspect}."
65
+ end
66
+
67
+ def do_download_file
68
+ progress_bar = create_progress_bar
69
+ file = do_download_file_with_progress_bar(progress_bar)
70
+ progress_bar.finish
71
+ file
72
+ end
73
+
74
+ def create_progress_bar
75
+ if @progress_bar
59
76
  ProgressBar.new(@file_size)
60
77
  else
61
78
  NullProgressBar.new(@file_size)
62
79
  end
63
80
  end
64
81
 
65
- def download_file
66
- file = Down.download(
82
+ # rubocop:disable Metrics/MethodLength
83
+ def do_download_file_with_progress_bar(progress_bar)
84
+ Down.download(
67
85
  url,
68
86
  open_timeout: 10,
69
87
  read_timeout: 10,
70
88
  max_redirects: 10,
71
89
  headers: headers,
72
90
  content_length_proc: ->(content_length) {
73
- @progress_bar.total = content_length if content_length
91
+ progress_bar.total = content_length if content_length
74
92
  },
75
93
  progress_proc: -> (progress) {
76
- @progress_bar.increment(progress)
94
+ progress_bar.increment(progress)
77
95
  }
78
96
  )
79
-
80
- @progress_bar.finish
81
-
82
- file
83
- rescue Down::NotFound
84
- raise(Fontist::Errors::InvalidResourceError.new("Invalid URL: #{@file}"))
85
97
  end
98
+ # rubocop:enable Metrics/MethodLength
86
99
 
87
100
  def url
88
101
  @file.respond_to?(:url) ? @file.url : @file
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.11.2".freeze
2
+ VERSION = "1.11.7".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.2
4
+ version: 1.11.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-11 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: '3.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rspec-benchmark
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.6'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.6'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: rubocop
183
197
  requirement: !ruby/object:Gem::Requirement