fontist 1.8.13 → 1.9.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: a094865cc9cb315ad328f795c59934f06663e8c43ff2931a0644da7aef7d8c7d
4
- data.tar.gz: 170ee4d526e74992ee56593fb5fb715c400fe07c2ade9307faebcdcd8e32e47c
3
+ metadata.gz: 46371ff826db31f7fc1c4e5fefca2d6f237f0a874a896dbca6c4c2dbcb937255
4
+ data.tar.gz: dc6a20cb42ce6649791e256a4d6cb8376c29d196c795e2e1869279caa1df8b5a
5
5
  SHA512:
6
- metadata.gz: 52ec33b7a2000ec5af4ae65165c0b0cdd22f1b0389b6c3ec89ed3a135ca3e55ac810a71cf9ce4621ae2398dcb77ed1dd2c8a45b077a2bfb8a1afc4a5d4d5efab
7
- data.tar.gz: 30635f72fb0d39f2ecb0657b36ee89f6a48647e8f23ec896f8837323e76eb7964d3feeda3cf899f6d698e06681e815000e132c6c4a556695f340d59a351db214
6
+ metadata.gz: 7ac9af8e04948c40b1b1fc488f6eeffebd7e598050d59224557f271b1deb328c639a67d153bad08b1a82e3869dda13525647db87e1b04269c0cf5e0b8c0ae295
7
+ data.tar.gz: 680fbde53bf5482ae3e36a720b6e6482cac5a62c29efa1b9962b18c1d51d7e7cafd2ce154c2c484cdfd6211002b413f1df45b909341df1d6ac864585aa590450
@@ -2,7 +2,7 @@ name: metanorma
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
5
+ branches: [ main ]
6
6
  pull_request:
7
7
 
8
8
  jobs:
@@ -13,7 +13,7 @@ jobs:
13
13
  strategy:
14
14
  fail-fast: false
15
15
  matrix:
16
- ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0' ]
16
+ ruby: [ '2.5', '2.6', '2.7', '3.0' ]
17
17
  os: [ ubuntu-latest, windows-latest, macos-latest ]
18
18
  experimental: [ true ]
19
19
  steps:
@@ -2,7 +2,7 @@ name: rspec
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
5
+ branches: [ main ]
6
6
  pull_request:
7
7
 
8
8
  jobs:
data/README.md CHANGED
@@ -399,6 +399,57 @@ bin/rspec
399
399
  All formulas are kept in the [formulas][fontist-formulas] repository. If you'd
400
400
  like to add a new one or change any existing, please refer to its documentation.
401
401
 
402
+ ### Privare repos
403
+
404
+ There is an ability to use private fonts via private fontist repo. Fontist repo
405
+ is a git repo which contains YAML formula files. Formulas can be created
406
+ manually (see [examples](https://github.com/fontist/formulas/tree/master/Formulas)),
407
+ or [auto-generated from an archive](#auto-generate-a-formula).
408
+
409
+ A corresponding SSH key should be setup with ssh-agent in order to access this private repo.
410
+
411
+ Private fontist repo can be set up with:
412
+
413
+ ```sh
414
+ fontist repo setup NAME URL
415
+ ```
416
+
417
+ E.g.
418
+
419
+ ```sh
420
+ fontist repo setup acme https://example.com/acme/formulas.git
421
+ ```
422
+
423
+ Later, to fetch changes the following command can be used:
424
+
425
+ ```sh
426
+ fontist repo update acme
427
+ ```
428
+
429
+ If there is a need to avoid using these formulas, the repo can be removed with:
430
+
431
+ ```sh
432
+ fontist repo remove acme
433
+ ```
434
+
435
+ ### Private formulas
436
+
437
+ Authorization of private archives in private formulas can be implemented with
438
+ headers. Here is an example which works with Github releases:
439
+
440
+ ```yaml
441
+ resources:
442
+ fonts.zip:
443
+ urls:
444
+ - url: https://example.com/repos/acme/formulas/releases/assets/38777461
445
+ headers:
446
+ Accept: application/octet-stream
447
+ Authorization: token ghp_1234567890abcdefghi
448
+ ```
449
+
450
+ A token can be obtained on [this page](https://github.com/settings/tokens).
451
+ It should have at least the `repo` scope.
452
+
402
453
  ### Auto-generate a formula
403
454
 
404
455
  A formula could be generated from a fonts archive. Just specify a URL to the
@@ -409,20 +460,21 @@ fontist create-formula https://www.latofonts.com/download/lato2ofl-zip/
409
460
  cp lato.yml ~/.fontist/formulas/Formulas/
410
461
  ```
411
462
 
463
+ Though indexes are auto-generated now, maintainers should rebuild indexes
464
+ in the main repo for backward compatibility with fontist prior to 1.9.x versions.
412
465
  A formula index should be rebuild, when a new formula is generated or an
413
466
  existing one changed:
414
467
 
415
468
  ```sh
416
- fontist rebuild-index
469
+ fontist rebuild-index --main-repo
417
470
  ```
418
471
 
419
- Then, both the formula and the updated index should be commited and pushed to
472
+ Then, both the formula and the updated indexes should be commited and pushed to
420
473
  the formula repository:
421
474
 
422
475
  ```sh
423
476
  cd ~/.fontist/formulas
424
- git add Formulas/lato.yml
425
- git add index.yml
477
+ git add Formulas/lato.yml index.yml filename_index.yml
426
478
  git commit -m "Add Lato formula"
427
479
  ```
428
480
 
@@ -441,7 +493,7 @@ repository [formulas][fontist-formulas]:
441
493
 
442
494
  ```
443
495
  cd ~/.fontist/formulas
444
- git add Formulas/google
496
+ git add Formulas/google index.yml filename_index.yml
445
497
  git commit -m "Google Fonts update"
446
498
  git push
447
499
  ```
@@ -454,8 +506,7 @@ can be updated with:
454
506
  ```sh
455
507
  fontist import-sil
456
508
  cd ~/.fontist/formulas
457
- git add Formulas/sil
458
- git add index.yml
509
+ git add Formulas/sil index.yml filename_index.yml
459
510
  git commit -m "SIL fonts update"
460
511
  git push
461
512
  ```
data/fontist.gemspec CHANGED
@@ -40,7 +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 "rubocop", "0.75.0"
43
+ spec.add_development_dependency "rubocop", "1.5.2"
44
44
  spec.add_development_dependency "rubocop-rails"
45
45
  spec.add_development_dependency "rubocop-performance"
46
46
  spec.add_development_dependency "ruby-protocol-buffers", "~> 1.0"
data/lib/fontist.rb CHANGED
@@ -7,6 +7,7 @@ require "singleton"
7
7
  require "fontist/errors"
8
8
  require "fontist/version"
9
9
 
10
+ require "fontist/repo"
10
11
  require "fontist/font"
11
12
  require "fontist/formula"
12
13
  require "fontist/system_font"
@@ -28,7 +29,11 @@ module Fontist
28
29
  end
29
30
 
30
31
  def self.fontist_path
31
- Pathname.new(ENV["FONTIST_PATH"] || File.join(Dir.home, ".fontist"))
32
+ Pathname.new(ENV["FONTIST_PATH"] || default_fontist_path)
33
+ end
34
+
35
+ def self.default_fontist_path
36
+ Pathname.new(File.join(Dir.home, ".fontist"))
32
37
  end
33
38
 
34
39
  def self.fonts_path
@@ -47,6 +52,10 @@ module Fontist
47
52
  Fontist.formulas_repo_path.join("Formulas")
48
53
  end
49
54
 
55
+ def self.private_formulas_path
56
+ Fontist.formulas_path.join("private")
57
+ end
58
+
50
59
  def self.downloads_path
51
60
  Fontist.fontist_path.join("downloads")
52
61
  end
@@ -60,10 +69,23 @@ module Fontist
60
69
  end
61
70
 
62
71
  def self.formula_index_path
63
- Fontist.formulas_repo_path.join("index.yml")
72
+ @formula_index_path || Fontist.formula_index_dir.join("formula_index.yml")
73
+ end
74
+
75
+ def self.formula_index_path=(path)
76
+ @formula_index_path = path
64
77
  end
65
78
 
66
79
  def self.formula_filename_index_path
67
- Fontist.formulas_repo_path.join("filename_index.yml")
80
+ @formula_filename_index_path ||
81
+ Fontist.formula_index_dir.join("filename_index.yml")
82
+ end
83
+
84
+ def self.formula_filename_index_path=(path)
85
+ @formula_filename_index_path = path
86
+ end
87
+
88
+ def self.formula_index_dir
89
+ Fontist.fontist_path
68
90
  end
69
91
  end
data/lib/fontist/cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "thor"
2
+ require "fontist/repo_cli"
2
3
 
3
4
  module Fontist
4
5
  class CLI < Thor
@@ -10,6 +11,8 @@ module Fontist
10
11
  STATUS_MANIFEST_COULD_NOT_BE_FOUND_ERROR = 5
11
12
  STATUS_MANIFEST_COULD_NOT_BE_READ_ERROR = 6
12
13
  STATUS_FONT_INDEX_CORRUPTED = 7
14
+ STATUS_REPO_NOT_FOUND = 8
15
+ STATUS_MAIN_REPO_NOT_FOUND = 9
13
16
 
14
17
  ERROR_TO_STATUS = {
15
18
  Fontist::Errors::UnsupportedFontError => [STATUS_NON_SUPPORTED_FONT_ERROR],
@@ -20,6 +23,8 @@ module Fontist
20
23
  Fontist::Errors::ManifestCouldNotBeReadError => [STATUS_MANIFEST_COULD_NOT_BE_READ_ERROR,
21
24
  "Manifest could not be read."],
22
25
  Fontist::Errors::FontIndexCorrupted => [STATUS_FONT_INDEX_CORRUPTED],
26
+ Fontist::Errors::RepoNotFoundError => [STATUS_REPO_NOT_FOUND],
27
+ Fontist::Errors::MainRepoNotFoundError => [STATUS_MAIN_REPO_NOT_FOUND],
23
28
  }.freeze
24
29
 
25
30
  def self.exit_on_failure?
@@ -123,11 +128,21 @@ module Fontist
123
128
 
124
129
  desc "rebuild-index", "Rebuild formula index (used by formulas maintainers)"
125
130
  long_desc <<-LONGDESC
126
- This index is pre-built and served with formulas, so there is no need
127
- update it unless something changes in the formulas repo.
131
+ Index should be rebuilt when any formula changes.
132
+
133
+ It is done automatically when formulas are updated, or private formulas
134
+ are set up.
128
135
  LONGDESC
136
+ option :main_repo, type: :boolean,
137
+ desc: "Updates indexes in the main repo (for backward " \
138
+ "compatibility with versions prior to 1.9)"
129
139
  def rebuild_index
130
- Fontist::Index.rebuild
140
+ if options[:main_repo]
141
+ Fontist::Index.rebuild_for_main_repo
142
+ else
143
+ Fontist::Index.rebuild
144
+ end
145
+
131
146
  Fontist.ui.say("Formula index has been rebuilt.")
132
147
  STATUS_SUCCESS
133
148
  end
@@ -138,6 +153,9 @@ module Fontist
138
153
  Fontist::Import::SilImport.new.call
139
154
  end
140
155
 
156
+ desc "repo SUBCOMMAND ...ARGS", "Manage custom repositories"
157
+ subcommand "repo", Fontist::RepoCLI
158
+
141
159
  private
142
160
 
143
161
  def success
@@ -3,17 +3,35 @@ module Fontist
3
3
  class GeneralError < StandardError; end
4
4
 
5
5
  class BinaryCallError < GeneralError; end
6
+
6
7
  class FontIndexCorrupted < GeneralError; end
8
+
7
9
  class FontNotFoundError < GeneralError; end
10
+
11
+ # for backward compatibility with metanorma,
12
+ # it depends on this exception to automatically download formulas
8
13
  class FormulaIndexNotFoundError < GeneralError; end
14
+
15
+ class MainRepoNotFoundError < FormulaIndexNotFoundError; end
16
+
9
17
  class InvalidResourceError < GeneralError; end
18
+
10
19
  class LicensingError < GeneralError; end
20
+
11
21
  class ManifestCouldNotBeFoundError < GeneralError; end
22
+
12
23
  class ManifestCouldNotBeReadError < GeneralError; end
24
+
13
25
  class MissingAttributeError < GeneralError; end
26
+
27
+ class RepoNotFoundError < GeneralError; end
28
+
14
29
  class TamperedFileError < GeneralError; end
30
+
15
31
  class TimeoutError < GeneralError; end
32
+
16
33
  class UnknownFontTypeError < GeneralError; end
34
+
17
35
  class UnknownArchiveError < GeneralError; end
18
36
 
19
37
  class FontError < GeneralError
data/lib/fontist/font.rb CHANGED
@@ -203,9 +203,9 @@ module Fontist
203
203
  end
204
204
 
205
205
  def font_list
206
- return unless formula
206
+ return if formulas.empty?
207
207
 
208
- list_styles([formula])
208
+ list_styles(formulas)
209
209
  end
210
210
 
211
211
  def list_styles(formulas)
@@ -54,11 +54,12 @@ module Fontist
54
54
  end
55
55
 
56
56
  def download_file(source)
57
- url = source.urls.first
57
+ request = source.urls.first
58
+ url = request.respond_to?(:url) ? request.url : request
58
59
  Fontist.ui.say(%(Downloading font "#{@formula.key}" from #{url}))
59
60
 
60
61
  Fontist::Utils::Downloader.download(
61
- url,
62
+ request,
62
63
  sha: source.sha256,
63
64
  file_size: source.file_size,
64
65
  progress_bar: !@no_progress
@@ -5,6 +5,9 @@ require "git"
5
5
  module Fontist
6
6
  class Formula
7
7
  def self.update_formulas_repo
8
+ dir = File.dirname(Fontist.formulas_repo_path)
9
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
10
+
8
11
  if Dir.exist?(Fontist.formulas_repo_path)
9
12
  Git.open(Fontist.formulas_repo_path).pull
10
13
  else
@@ -12,6 +15,8 @@ module Fontist
12
15
  Fontist.formulas_repo_path,
13
16
  depth: 1)
14
17
  end
18
+
19
+ Index.rebuild
15
20
  end
16
21
 
17
22
  def self.all
data/lib/fontist/index.rb CHANGED
@@ -3,9 +3,37 @@ require_relative "indexes/filename_index"
3
3
 
4
4
  module Fontist
5
5
  class Index
6
+ def self.rebuild_for_main_repo
7
+ unless Dir.exist?(Fontist.private_formulas_path)
8
+ return do_rebuild_for_main_repo_with
9
+ end
10
+
11
+ Dir.mktmpdir do |dir|
12
+ tmp_private_path = File.join(dir, "private")
13
+ FileUtils.mv(Fontist.private_formulas_path, tmp_private_path)
14
+
15
+ do_rebuild_for_main_repo_with
16
+
17
+ FileUtils.mv(tmp_private_path, Fontist.private_formulas_path)
18
+ end
19
+ end
20
+
21
+ def self.do_rebuild_for_main_repo_with
22
+ Fontist.formula_index_path = Fontist.formulas_repo_path.join("index.yml")
23
+ Fontist.formula_filename_index_path =
24
+ Fontist.formulas_repo_path.join("filename_index.yml")
25
+
26
+ rebuild
27
+
28
+ Fontist.formula_index_path = nil
29
+ Fontist.formula_filename_index_path = nil
30
+ end
31
+
6
32
  def self.rebuild
7
33
  Fontist::Indexes::FontIndex.rebuild
8
34
  Fontist::Indexes::FilenameIndex.rebuild
35
+
36
+ reset_cache
9
37
  end
10
38
 
11
39
  def self.reset_cache
@@ -5,10 +5,14 @@ module Fontist
5
5
  class BaseIndex
6
6
  def self.from_yaml
7
7
  @from_yaml ||= begin
8
- unless File.exist?(path)
9
- raise Errors::FormulaIndexNotFoundError.new("Please fetch `#{path}` index with `fontist update`.")
8
+ unless Dir.exist?(Fontist.formulas_repo_path)
9
+ raise Errors::MainRepoNotFoundError.new(
10
+ "Please fetch formulas with `fontist update`.",
11
+ )
10
12
  end
11
13
 
14
+ rebuild unless File.exist?(path)
15
+
12
16
  data = YAML.load_file(path)
13
17
  new(data)
14
18
  end
@@ -63,6 +67,8 @@ module Fontist
63
67
  end
64
68
 
65
69
  def to_yaml
70
+ dir = File.dirname(self.class.path)
71
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
66
72
  File.write(self.class.path, YAML.dump(to_h))
67
73
  end
68
74
 
@@ -0,0 +1,54 @@
1
+ require "git"
2
+
3
+ module Fontist
4
+ class Repo
5
+ class << self
6
+ def setup(name, url)
7
+ ensure_private_formulas_path_exists
8
+ fetch_repo(name, url)
9
+ Index.rebuild
10
+ end
11
+
12
+ def update(name)
13
+ path = repo_path(name)
14
+ unless Dir.exist?(path)
15
+ raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
16
+ end
17
+
18
+ Git.open(path).pull
19
+ Index.rebuild
20
+ end
21
+
22
+ def remove(name)
23
+ path = repo_path(name)
24
+ unless Dir.exist?(path)
25
+ raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
26
+ end
27
+
28
+ FileUtils.rm_r(path)
29
+ Index.rebuild
30
+ end
31
+
32
+ private
33
+
34
+ def ensure_private_formulas_path_exists
35
+ Fontist.private_formulas_path.tap do |path|
36
+ FileUtils.mkdir_p(path) unless Dir.exist?(path)
37
+ end
38
+ end
39
+
40
+ def fetch_repo(name, url)
41
+ path = repo_path(name)
42
+ if Dir.exist?(path)
43
+ Git.open(path).pull
44
+ else
45
+ Git.clone(url, path, depth: 1)
46
+ end
47
+ end
48
+
49
+ def repo_path(name)
50
+ Fontist.private_formulas_path.join(name)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,42 @@
1
+ module Fontist
2
+ class RepoCLI < Thor
3
+ desc "setup NAME URL",
4
+ "Setup a custom fontist repo named NAME for the repository at URL"
5
+ def setup(name, url)
6
+ Repo.setup(name, url)
7
+ Fontist.ui.success(
8
+ "Fontist repo '#{name}' from '#{url}' has been successfully set up.",
9
+ )
10
+ CLI::STATUS_SUCCESS
11
+ end
12
+
13
+ desc "update NAME", "Update formulas in a fontist repo named NAME"
14
+ def update(name)
15
+ Repo.update(name)
16
+ Fontist.ui.success(
17
+ "Fontist repo '#{name}' has been successfully updated.",
18
+ )
19
+ CLI::STATUS_SUCCESS
20
+ rescue Errors::RepoNotFoundError
21
+ handle_repo_not_found(name)
22
+ end
23
+
24
+ desc "remove NAME", "Remove fontist repo named NAME"
25
+ def remove(name)
26
+ Repo.remove(name)
27
+ Fontist.ui.success(
28
+ "Fontist repo '#{name}' has been successfully removed.",
29
+ )
30
+ CLI::STATUS_SUCCESS
31
+ rescue Errors::RepoNotFoundError
32
+ handle_repo_not_found(name)
33
+ end
34
+
35
+ private
36
+
37
+ def handle_repo_not_found(name)
38
+ Fontist.ui.error("Fontist repo '#{name}' is not found.")
39
+ CLI::STATUS_REPO_NOT_FOUND
40
+ end
41
+ end
42
+ end
@@ -20,7 +20,7 @@ module Fontist
20
20
  end
21
21
 
22
22
  def download
23
- file = @cache.fetch(@file) do
23
+ file = @cache.fetch(url) do
24
24
  download_file
25
25
  end
26
26
 
@@ -56,9 +56,10 @@ module Fontist
56
56
 
57
57
  def download_file
58
58
  file = Down.download(
59
- @file,
59
+ url,
60
60
  open_timeout: 10,
61
61
  read_timeout: 10,
62
+ headers: headers,
62
63
  content_length_proc: ->(content_length) {
63
64
  @progress_bar.total = content_length if content_length
64
65
  },
@@ -73,6 +74,17 @@ module Fontist
73
74
  rescue Down::NotFound
74
75
  raise(Fontist::Errors::InvalidResourceError.new("Invalid URL: #{@file}"))
75
76
  end
77
+
78
+ def url
79
+ @file.respond_to?(:url) ? @file.url : @file
80
+ end
81
+
82
+ def headers
83
+ @file.respond_to?(:headers) &&
84
+ @file.headers &&
85
+ @file.headers.to_h.map { |k, v| [k.to_s, v] }.to_h || # rubocop:disable Style/HashTransformKeys, Metrics/LineLength
86
+ {}
87
+ end
76
88
  end
77
89
 
78
90
  class ProgressBar
@@ -11,6 +11,7 @@ module Fontist
11
11
  yield
12
12
  ensure
13
13
  f.flock(File::LOCK_UN)
14
+ f.close
14
15
  end
15
16
  end
16
17
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.8.13".freeze
2
+ VERSION = "1.9.0".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.8.13
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-13 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - '='
186
186
  - !ruby/object:Gem::Version
187
- version: 0.75.0
187
+ version: 1.5.2
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - '='
193
193
  - !ruby/object:Gem::Version
194
- version: 0.75.0
194
+ version: 1.5.2
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: rubocop-rails
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -302,6 +302,8 @@ files:
302
302
  - lib/fontist/manifest.rb
303
303
  - lib/fontist/manifest/install.rb
304
304
  - lib/fontist/manifest/locations.rb
305
+ - lib/fontist/repo.rb
306
+ - lib/fontist/repo_cli.rb
305
307
  - lib/fontist/system.yml
306
308
  - lib/fontist/system_font.rb
307
309
  - lib/fontist/system_index.rb
@@ -337,8 +339,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
337
339
  - !ruby/object:Gem::Version
338
340
  version: '0'
339
341
  requirements: []
340
- rubygems_version: 3.0.3
341
- signing_key:
342
+ rubygems_version: 3.0.3.1
343
+ signing_key:
342
344
  specification_version: 4
343
345
  summary: Install openly-licensed fonts on Windows, Linux and Mac!
344
346
  test_files: []