fontist 1.7.1 → 1.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +38 -0
  3. data/.github/workflows/rspec.yml +58 -0
  4. data/README.md +123 -32
  5. data/{bin → exe}/fontist +0 -0
  6. data/fontist.gemspec +4 -2
  7. data/lib/fontist.rb +6 -3
  8. data/lib/fontist/cli.rb +66 -42
  9. data/lib/fontist/errors.rb +62 -12
  10. data/lib/fontist/font.rb +23 -37
  11. data/lib/fontist/font_installer.rb +114 -0
  12. data/lib/fontist/fontist_font.rb +3 -49
  13. data/lib/fontist/formula.rb +89 -63
  14. data/lib/fontist/formula_paths.rb +43 -0
  15. data/lib/fontist/helpers.rb +7 -0
  16. data/lib/fontist/import/create_formula.rb +3 -2
  17. data/lib/fontist/import/google/skiplist.yml +3 -0
  18. data/lib/fontist/import/google_check.rb +1 -1
  19. data/lib/fontist/import/google_import.rb +3 -4
  20. data/lib/fontist/import/otfinfo_generate.rb +1 -1
  21. data/lib/fontist/import/recursive_extraction.rb +6 -2
  22. data/lib/fontist/import/sil_import.rb +99 -0
  23. data/lib/fontist/index.rb +72 -0
  24. data/lib/fontist/index_formula.rb +30 -0
  25. data/lib/fontist/manifest/install.rb +4 -9
  26. data/lib/fontist/manifest/locations.rb +28 -20
  27. data/lib/fontist/system_font.rb +32 -91
  28. data/lib/fontist/system_index.rb +47 -5
  29. data/lib/fontist/utils.rb +1 -0
  30. data/lib/fontist/utils/cache.rb +11 -3
  31. data/lib/fontist/utils/exe_extractor.rb +1 -1
  32. data/lib/fontist/utils/locking.rb +17 -0
  33. data/lib/fontist/utils/zip_extractor.rb +1 -1
  34. data/lib/fontist/version.rb +1 -1
  35. metadata +43 -20
  36. data/.github/workflows/macosx.yml +0 -33
  37. data/.github/workflows/ubuntu.yml +0 -30
  38. data/.github/workflows/windows.yml +0 -32
  39. data/bin/check_google +0 -8
  40. data/bin/console +0 -11
  41. data/bin/convert_formulas +0 -8
  42. data/bin/generate_otfinfo +0 -8
  43. data/bin/import_google +0 -8
  44. data/bin/rspec +0 -29
  45. data/bin/setup +0 -7
  46. data/lib/fontist/font_formula.rb +0 -158
  47. data/lib/fontist/formula_template.rb +0 -122
  48. data/lib/fontist/formulas.rb +0 -56
  49. data/lib/fontist/registry.rb +0 -43
@@ -2,8 +2,18 @@ require "ttfunk"
2
2
 
3
3
  module Fontist
4
4
  class SystemIndex
5
+ include Utils::Locking
6
+
5
7
  attr_reader :font_paths
6
8
 
9
+ def self.find(font, style)
10
+ new(SystemFont.font_paths).find(font, style)
11
+ end
12
+
13
+ def self.rebuild
14
+ new(SystemFont.font_paths).rebuild
15
+ end
16
+
7
17
  def initialize(font_paths)
8
18
  @font_paths = font_paths
9
19
  end
@@ -17,6 +27,10 @@ module Fontist
17
27
  fonts.empty? ? nil : fonts
18
28
  end
19
29
 
30
+ def rebuild
31
+ build_system_index
32
+ end
33
+
20
34
  private
21
35
 
22
36
  def system_index
@@ -24,28 +38,56 @@ module Fontist
24
38
  end
25
39
 
26
40
  def build_system_index
41
+ lock(lock_path) do
42
+ do_build_system_index
43
+ end
44
+ end
45
+
46
+ def lock_path
47
+ Fontist.system_index_path.to_s + ".lock"
48
+ end
49
+
50
+ def do_build_system_index
27
51
  previous_index = load_system_index
28
52
  updated_index = detect_paths(font_paths, previous_index)
29
53
  updated_index.tap do |index|
30
- save_index(index)
54
+ save_index(index) if changed?(updated_index, previous_index)
31
55
  end
32
56
  end
33
57
 
58
+ def changed?(this, other)
59
+ this.map { |x| x[:path] }.uniq.sort != other.map { |x| x[:path] }.uniq.sort
60
+ end
61
+
34
62
  def load_system_index
35
63
  index = File.exist?(Fontist.system_index_path) ? YAML.load_file(Fontist.system_index_path) : []
36
- index.group_by { |x| x[:path] }
64
+
65
+ index.each do |item|
66
+ missing_keys = %i[path full_name family_name type] - item.keys
67
+ unless missing_keys.empty?
68
+ raise(Errors::FontIndexCorrupted, <<~MSG.chomp)
69
+ Font index is corrupted.
70
+ Item #{item.inspect} misses required attributes: #{missing_keys.join(', ')}.
71
+ You can remove the index file (#{Fontist.system_index_path}) and try again.
72
+ MSG
73
+ end
74
+ end
75
+
76
+ index
37
77
  end
38
78
 
39
- def detect_paths(paths, indexed)
79
+ def detect_paths(paths, index)
80
+ by_path = index.group_by { |x| x[:path] }
81
+
40
82
  paths.flat_map do |path|
41
- next indexed[path] if indexed[path]
83
+ next by_path[path] if by_path[path]
42
84
 
43
85
  detect_fonts(path)
44
86
  end
45
87
  end
46
88
 
47
89
  def detect_fonts(path)
48
- case File.extname(path).delete_prefix(".").downcase
90
+ case File.extname(path).gsub(/^\./, "").downcase
49
91
  when "ttf", "otf"
50
92
  detect_file_font(path)
51
93
  when "ttc"
@@ -1,4 +1,5 @@
1
1
  require "fontist/utils/ui"
2
+ require "fontist/utils/locking"
2
3
  require "fontist/utils/system"
3
4
  require "fontist/utils/dsl"
4
5
  require "fontist/utils/dsl/font"
@@ -1,6 +1,8 @@
1
1
  module Fontist
2
2
  module Utils
3
3
  class Cache
4
+ include Locking
5
+
4
6
  def fetch(key, bar: nil)
5
7
  map = load_cache
6
8
  if cache_exist?(map[key])
@@ -48,13 +50,19 @@ module Fontist
48
50
  def save_cache(generated_file, key)
49
51
  path = move_to_downloads(generated_file)
50
52
 
51
- map = load_cache
52
- map[key] = path
53
- File.write(cache_map_path, YAML.dump(map))
53
+ lock(lock_path) do
54
+ map = load_cache
55
+ map[key] = path
56
+ File.write(cache_map_path, YAML.dump(map))
57
+ end
54
58
 
55
59
  path
56
60
  end
57
61
 
62
+ def lock_path
63
+ cache_map_path.to_s + ".lock"
64
+ end
65
+
58
66
  def move_to_downloads(source)
59
67
  create_downloads_directory
60
68
  path = generate_file_path(source)
@@ -6,7 +6,7 @@ module Fontist
6
6
 
7
7
  exe_file = download_file(exe_file).path if download
8
8
 
9
- Fontist.ui.say(%(Installing font "#{key}".))
9
+ Fontist.ui.say(%(Installing font "#{formula.key}".))
10
10
  cab_file = decompressor.search(exe_file)
11
11
  cabbed_fonts = grep_fonts(cab_file.files) || []
12
12
  fonts_paths = extract_cabbed_fonts_to_assets(cabbed_fonts)
@@ -0,0 +1,17 @@
1
+ module Fontist
2
+ module Utils
3
+ module Locking
4
+ def lock(lock_path)
5
+ File.dirname(lock_path).tap do |dir|
6
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
7
+ end
8
+
9
+ f = File.open(lock_path, File::CREAT)
10
+ f.flock(File::LOCK_EX)
11
+ yield
12
+ ensure
13
+ f.flock(File::LOCK_UN)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -8,7 +8,7 @@ module Fontist
8
8
  zip_file = download_file(resource) if download
9
9
  zip_file ||= resource.urls.first
10
10
 
11
- Fontist.ui.say(%(Installing font "#{key}".))
11
+ Fontist.ui.say(%(Installing font "#{formula.key}".))
12
12
  fonts_paths = unzip_fonts(zip_file, fonts_sub_dir)
13
13
  block_given? ? yield(fonts_paths) : fonts_paths
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.7.1".freeze
2
+ VERSION = "1.8.3".freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  - Abu Nashir
9
- autorequire:
10
- bindir: bin
9
+ autorequire:
10
+ bindir: exe
11
11
  cert_chain: []
12
- date: 2020-12-05 00:00:00.000000000 Z
12
+ date: 2021-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: down
@@ -165,6 +165,34 @@ dependencies:
165
165
  - - "~>"
166
166
  - !ruby/object:Gem::Version
167
167
  version: '2.0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: gem-release
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ - !ruby/object:Gem::Dependency
183
+ name: nokogiri
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '1.0'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - "~>"
194
+ - !ruby/object:Gem::Version
195
+ version: '1.0'
168
196
  - !ruby/object:Gem::Dependency
169
197
  name: rake
170
198
  requirement: !ruby/object:Gem::Requirement
@@ -259,9 +287,8 @@ extensions: []
259
287
  extra_rdoc_files: []
260
288
  files:
261
289
  - ".github/workflows/check_google.yml"
262
- - ".github/workflows/macosx.yml"
263
- - ".github/workflows/ubuntu.yml"
264
- - ".github/workflows/windows.yml"
290
+ - ".github/workflows/release.yml"
291
+ - ".github/workflows/rspec.yml"
265
292
  - ".gitignore"
266
293
  - ".hound.yml"
267
294
  - ".rspec"
@@ -270,24 +297,17 @@ files:
270
297
  - LICENSE.txt
271
298
  - README.md
272
299
  - Rakefile
273
- - bin/check_google
274
- - bin/console
275
- - bin/convert_formulas
276
- - bin/fontist
277
- - bin/generate_otfinfo
278
- - bin/import_google
279
- - bin/rspec
280
- - bin/setup
300
+ - exe/fontist
281
301
  - fontist.gemspec
282
302
  - lib/fontist.rb
283
303
  - lib/fontist/cli.rb
284
304
  - lib/fontist/errors.rb
285
305
  - lib/fontist/font.rb
286
- - lib/fontist/font_formula.rb
306
+ - lib/fontist/font_installer.rb
287
307
  - lib/fontist/fontist_font.rb
288
308
  - lib/fontist/formula.rb
289
- - lib/fontist/formula_template.rb
290
- - lib/fontist/formulas.rb
309
+ - lib/fontist/formula_paths.rb
310
+ - lib/fontist/helpers.rb
291
311
  - lib/fontist/import.rb
292
312
  - lib/fontist/import/convert_formulas.rb
293
313
  - lib/fontist/import/create_formula.rb
@@ -319,12 +339,14 @@ files:
319
339
  - lib/fontist/import/otfinfo/template.erb
320
340
  - lib/fontist/import/otfinfo_generate.rb
321
341
  - lib/fontist/import/recursive_extraction.rb
342
+ - lib/fontist/import/sil_import.rb
322
343
  - lib/fontist/import/template_helper.rb
323
344
  - lib/fontist/import/text_helper.rb
345
+ - lib/fontist/index.rb
346
+ - lib/fontist/index_formula.rb
324
347
  - lib/fontist/manifest.rb
325
348
  - lib/fontist/manifest/install.rb
326
349
  - lib/fontist/manifest/locations.rb
327
- - lib/fontist/registry.rb
328
350
  - lib/fontist/system.yml
329
351
  - lib/fontist/system_font.rb
330
352
  - lib/fontist/system_index.rb
@@ -335,6 +357,7 @@ files:
335
357
  - lib/fontist/utils/dsl/collection_font.rb
336
358
  - lib/fontist/utils/dsl/font.rb
337
359
  - lib/fontist/utils/exe_extractor.rb
360
+ - lib/fontist/utils/locking.rb
338
361
  - lib/fontist/utils/msi_extractor.rb
339
362
  - lib/fontist/utils/seven_zip_extractor.rb
340
363
  - lib/fontist/utils/system.rb
@@ -364,7 +387,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
364
387
  version: '0'
365
388
  requirements: []
366
389
  rubygems_version: 3.0.3
367
- signing_key:
390
+ signing_key:
368
391
  specification_version: 4
369
392
  summary: A libarary find or download fonts
370
393
  test_files: []
@@ -1,33 +0,0 @@
1
- name: macos
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- pull_request:
9
- branches:
10
- - master
11
-
12
- jobs:
13
- build:
14
- runs-on: macos-latest
15
-
16
- steps:
17
- - uses: actions/checkout@v2
18
-
19
- - uses: actions/setup-ruby@v1
20
- with:
21
- ruby-version: 2.6
22
-
23
- - name: Install otfinfo
24
- run: brew install lcdf-typetools
25
-
26
- - name: Install bundler
27
- run: gem install bundler
28
-
29
- - name: Setup
30
- run: bin/setup
31
-
32
- - name: Run tests
33
- run: TEST_ENV=CI bin/rspec
@@ -1,30 +0,0 @@
1
- name: ubuntu
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- pull_request:
9
- branches:
10
- - master
11
-
12
- jobs:
13
- build:
14
- runs-on: ubuntu-latest
15
-
16
- steps:
17
- - uses: actions/checkout@v2
18
-
19
- - uses: actions/setup-ruby@v1
20
- with:
21
- ruby-version: 2.6
22
-
23
- - name: Install bundler
24
- run: gem install bundler
25
-
26
- - name: Setup
27
- run: bin/setup
28
-
29
- - name: Run tests
30
- run: TEST_ENV=CI bin/rspec --tag ~dev
@@ -1,32 +0,0 @@
1
- name: windows
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- pull_request:
9
- branches:
10
- - master
11
-
12
- jobs:
13
- build:
14
- runs-on: windows-latest
15
-
16
- steps:
17
- - uses: actions/checkout@v2
18
-
19
- - uses: actions/setup-ruby@v1
20
- with:
21
- ruby-version: 2.6
22
- architecture: "x64"
23
-
24
- - name: Setup
25
- shell: pwsh
26
- run: |
27
- gem install bundler
28
- bundle config --local path vendor/bundle
29
- bundle install --jobs 4 --retry 3
30
-
31
- - name: Run tests
32
- run: bundle exec rspec --tag ~skip_in_windows --tag ~dev
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "fontist"
6
- require "fontist/import/google_check"
7
-
8
- Fontist::Import::GoogleCheck.new.call
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "fontist"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- require "pry"
11
- Pry.start
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "fontist"
6
- require "fontist/import/convert_formulas"
7
-
8
- Fontist::Import::ConvertFormulas.new.call
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "fontist"
6
- require "fontist/import/otfinfo_generate"
7
-
8
- Fontist::Import::OtfinfoGenerate.new(ARGV[0]).call
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "fontist"
6
- require "fontist/import/google_import"
7
-
8
- Fontist::Import::GoogleImport.new.call