fontist 1.6.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/release.yml +38 -0
  3. data/.github/workflows/rspec.yml +58 -0
  4. data/README.md +109 -32
  5. data/{bin → exe}/fontist +0 -0
  6. data/fontist.gemspec +4 -2
  7. data/lib/fontist.rb +10 -3
  8. data/lib/fontist/cli.rb +63 -42
  9. data/lib/fontist/errors.rb +14 -11
  10. data/lib/fontist/font.rb +25 -27
  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 +15 -30
  17. data/lib/fontist/import/files/collection_file.rb +6 -1
  18. data/lib/fontist/import/files/file_requirement.rb +17 -0
  19. data/lib/fontist/import/files/font_detector.rb +48 -0
  20. data/lib/fontist/import/formula_builder.rb +7 -3
  21. data/lib/fontist/import/google_check.rb +1 -1
  22. data/lib/fontist/import/google_import.rb +3 -4
  23. data/lib/fontist/import/otf/font_file.rb +17 -3
  24. data/lib/fontist/import/otfinfo_generate.rb +1 -1
  25. data/lib/fontist/import/recursive_extraction.rb +74 -13
  26. data/lib/fontist/index.rb +72 -0
  27. data/lib/fontist/index_formula.rb +30 -0
  28. data/lib/fontist/manifest/install.rb +6 -15
  29. data/lib/fontist/manifest/locations.rb +59 -4
  30. data/lib/fontist/system_font.rb +22 -49
  31. data/lib/fontist/system_index.rb +92 -0
  32. data/lib/fontist/utils.rb +1 -0
  33. data/lib/fontist/utils/dsl.rb +4 -0
  34. data/lib/fontist/utils/dsl/collection_font.rb +36 -0
  35. data/lib/fontist/utils/dsl/font.rb +2 -1
  36. data/lib/fontist/utils/exe_extractor.rb +6 -5
  37. data/lib/fontist/utils/zip_extractor.rb +20 -12
  38. data/lib/fontist/version.rb +1 -1
  39. metadata +45 -20
  40. data/.github/workflows/macosx.yml +0 -33
  41. data/.github/workflows/ubuntu.yml +0 -30
  42. data/.github/workflows/windows.yml +0 -32
  43. data/bin/check_google +0 -8
  44. data/bin/console +0 -11
  45. data/bin/convert_formulas +0 -8
  46. data/bin/generate_otfinfo +0 -8
  47. data/bin/import_google +0 -8
  48. data/bin/rspec +0 -29
  49. data/bin/setup +0 -7
  50. data/lib/fontist/font_formula.rb +0 -130
  51. data/lib/fontist/formula_template.rb +0 -108
  52. data/lib/fontist/formulas.rb +0 -56
  53. data/lib/fontist/manifest/common.rb +0 -60
  54. data/lib/fontist/registry.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 2dc209840287f224caec09be365402ca43e3605debfed69d01f3f89f12d27093
4
- data.tar.gz: 2ba6e5c3359cfa30afe30ecf96b4f11311e33c12dcce5053b7e37ea9c1750ce9
2
+ SHA1:
3
+ metadata.gz: 0d083618f330800ccb94e30d93fa8b5bf65d5e0a
4
+ data.tar.gz: 133e64a85156c8fa5dcfc284ef57b3047fdbec0e
5
5
  SHA512:
6
- metadata.gz: b3e2a83f4c56ca2092954e9602827dcc6fe74ba4ba40d52f5e8ce6b0ca532cec67558fcf5a2e24775b13d263843ff2fab045f66838468a9d5fe0f087c3c08e23
7
- data.tar.gz: 5d8968907e2955e7657044ad60c6c8c66ffc0f90d4e06f219b4bde01ad43f949b8dfc24a3477a6eebd269535d14dd26b7222c841c1f2b216f9e5a9111c9c931d
6
+ metadata.gz: f5a33afe8b4157afadbaa8530e39de7a0b51222904101c396668e6e5d030fc51f6895f9f60478d9a32dc46af1bda7f1cef1aff0f27e2bc10bc3ae0e7b661d71f
7
+ data.tar.gz: 3b1d0e38e2b42cf5e24f568cec75a34666ff7b3a98b36b673969365a4ec87b4add38b5fe3dac79a16871596d19b9454eac9fd6ada0097764a26af364f7fd5fee
@@ -0,0 +1,38 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-18.04
11
+ steps:
12
+ - uses: actions/checkout@v1
13
+
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: '2.6'
17
+
18
+ - run: bundle config set path 'vendor/bundle'
19
+
20
+ - run: bundle install --jobs 4 --retry 3
21
+
22
+ - run: bundle exec rspec --tag ~dev
23
+ env:
24
+ TEST_ENV: CI
25
+
26
+ - name: Publish to rubygems.org
27
+ env:
28
+ RUBYGEMS_API_KEY: ${{secrets.FONTIST_CI_RUBYGEMS_API_KEY}}
29
+ run: |
30
+ gem install gem-release
31
+ touch ~/.gem/credentials
32
+ cat > ~/.gem/credentials << EOF
33
+ ---
34
+ :rubygems_api_key: ${RUBYGEMS_API_KEY}
35
+ EOF
36
+ chmod 0600 ~/.gem/credentials
37
+ git status
38
+ gem release
@@ -0,0 +1,58 @@
1
+ name: rspec
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+
8
+ jobs:
9
+ build:
10
+ name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
11
+ runs-on: ${{ matrix.os }}
12
+ continue-on-error: ${{ matrix.experimental }}
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ ruby: [ '2.6', '2.5', '2.4' ]
17
+ os: [ ubuntu-latest, windows-latest, macos-latest ]
18
+ experimental: [ false ]
19
+ include:
20
+ - ruby: '2.7'
21
+ os: 'ubuntu-latest'
22
+ experimental: true
23
+ - ruby: '2.7'
24
+ os: 'windows-latest'
25
+ experimental: true
26
+ - ruby: '2.7'
27
+ os: 'macos-latest'
28
+ experimental: true
29
+
30
+ steps:
31
+ - uses: actions/checkout@master
32
+
33
+ - uses: ruby/setup-ruby@v1
34
+ with:
35
+ ruby-version: ${{ matrix.ruby }}
36
+
37
+ - uses: actions/cache@v1
38
+ with:
39
+ path: vendor/bundle
40
+ key: bundle-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
41
+ restore-keys: bundle-${{ matrix.os }}-${{ matrix.ruby }}
42
+
43
+ - if: matrix.os == 'macos-latest'
44
+ run: brew install lcdf-typetools
45
+
46
+ - run: bundle config set path 'vendor/bundle'
47
+
48
+ - run: bundle install --jobs 4 --retry 3
49
+
50
+ - if: matrix.os == 'macos-latest'
51
+ run: bundle exec rspec
52
+ env:
53
+ TEST_ENV: CI
54
+
55
+ - if: matrix.os != 'macos-latest'
56
+ run: bundle exec rspec --tag ~dev
57
+ env:
58
+ TEST_ENV: CI
data/README.md CHANGED
@@ -44,7 +44,7 @@ can we find a font in your system.
44
44
 
45
45
  #### Finding a font
46
46
 
47
- The `Fontist::Fontist.find` interface can be used a find a font in your system.
47
+ The `Fontist::Font.find` interface can be used a find a font in your system.
48
48
  It will look into the operating system specific font directories, and also the
49
49
  fontist specific `~/.fontist` directory.
50
50
 
@@ -109,7 +109,7 @@ fonts in your system.
109
109
  #### Find formula fonts
110
110
 
111
111
  Normally, each font name can be associated with multiple styles or collection, for
112
- example the `Calibri` font might contains a `regular`, `bola` or `italic` styles
112
+ example the `Calibri` font might contains a `regular`, `bold` or `italic` styles
113
113
  fonts and if you want a interface that can return the complete list then this is
114
114
  your friend. You can use it as following:
115
115
 
@@ -136,28 +136,29 @@ operation you would do in any ruby object.
136
136
 
137
137
  #### Locations
138
138
 
139
- Fontist lets find font locations from a YAML manifest of the following format:
139
+ Fontist lets find font locations from a manifest of the following format:
140
140
 
141
- ```yml
142
- Segoe UI:
143
- - Regular
144
- - Bold
145
- Roboto Mono:
146
- - Regular
141
+ ```ruby
142
+ {"Segoe UI"=>["Regular", "Bold"],
143
+ "Roboto Mono"=>["Regular"]}
147
144
  ```
148
145
 
149
- Calling the following code returns a nested hash with font paths.
146
+ Calling the following code returns a nested hash with font paths and names.
147
+ Font name is useful to choose a specific font in a font collection file (TTC).
150
148
 
151
149
  ```ruby
152
- Fontist::Manifest::Locations.call(manifest_path)
150
+ Fontist::Manifest::Locations.from_hash(manifest)
153
151
  ```
154
152
 
155
153
  ```ruby
156
- {"Segoe UI"=>
157
- {"Regular"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"],
158
- "Bold"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]},
159
- "Roboto Mono"=>
160
- {"Regular"=>[]}}
154
+ {"Segoe UI"=> {
155
+ "Regular"=>{"full_name"=>"Segoe UI",
156
+ "paths"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"]},
157
+ "Bold"=>{"full_name"=>"Segoe UI Bold",
158
+ "paths"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]}},
159
+ "Roboto Mono"=> {
160
+ "Regular"=>{"full_name"=>nil,
161
+ "paths"=>[]}}}
161
162
  ```
162
163
 
163
164
  #### Install
@@ -166,17 +167,41 @@ Fontist lets not only to get font locations but also to install fonts from the
166
167
  manifest:
167
168
 
168
169
  ```ruby
169
- Fontist::Manifest::Install.call(manifest, confirmation: "yes")
170
+ Fontist::Manifest::Install.from_hash(manifest, confirmation: "yes")
170
171
  ```
171
172
 
172
173
  It will install fonts and return their locations:
173
174
 
174
175
  ```ruby
175
- {"Segoe UI"=>
176
- {"Regular"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"],
177
- "Bold"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]},
178
- "Roboto Mono"=>
179
- {"Regular"=>["/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"]}}
176
+ {"Segoe UI"=> {
177
+ "Regular"=>{"full_name"=>"Segoe UI",
178
+ "paths"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"]},
179
+ "Bold"=>{"full_name"=>"Segoe UI Bold",
180
+ "paths"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]}},
181
+ "Roboto Mono"=> {
182
+ "Regular"=>{"full_name"=>"Roboto Mono Regular",
183
+ "paths"=>["/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"]}}}
184
+ ```
185
+
186
+ #### Support of YAML format
187
+
188
+ Both commands support a YAML file as an input with a `from_file` method. For
189
+ example, if there is a `manifest.yml` file containing:
190
+
191
+ ```yaml
192
+ Segoe UI:
193
+ - Regular
194
+ - Bold
195
+ Roboto Mono:
196
+ - Regular
197
+ ```
198
+
199
+ Then the following calls would return font names and paths, as from the
200
+ `from_hash` method (see [Locations](#locations) and [Install](#install)).
201
+
202
+ ```ruby
203
+ Fontist::Manifest::Locations.from_file("manifest.yml")
204
+ Fontist::Manifest::Install.from_file("manifest.yml", confirmation: "yes")
180
205
  ```
181
206
 
182
207
  ### CLI
@@ -191,7 +216,8 @@ All searches are case-insensitive for ease of use.
191
216
 
192
217
  The `install` command is similar to the `Font.install` call. It first checks
193
218
  whether this font is already installed, and if not, then installs the font and
194
- returns its paths. Font or formula could be specified as a name.
219
+ returns its paths. Only font name (not formula name, nor font filename) could
220
+ be used as a parameter.
195
221
 
196
222
  ```
197
223
  $ fontist install "segoe ui"
@@ -223,7 +249,7 @@ Prints installed font paths grouped by formula and font.
223
249
 
224
250
  ```
225
251
  $ fontist status "segoe ui"
226
- Fontist::Formulas::SegoeUIFont
252
+ segoe_ui
227
253
  Segoe UI
228
254
  Regular (/Users/user/.fontist/fonts/SEGOEUI.TTF)
229
255
  Bold (/Users/user/.fontist/fonts/SEGOEUIB.TTF)
@@ -237,7 +263,7 @@ Lists installation status of fonts supported by Fontist.
237
263
 
238
264
  ```
239
265
  $ fontist list "segoe ui"
240
- Fontist::Formulas::SegoeUIFont
266
+ segoe_ui
241
267
  Segoe UI
242
268
  Regular (installed)
243
269
  Bold (installed)
@@ -247,7 +273,7 @@ Fontist::Formulas::SegoeUIFont
247
273
 
248
274
  ```
249
275
  $ fontist list "roboto mono"
250
- Fontist::Formulas::RobotoMonoFont
276
+ google/roboto_mono
251
277
  Roboto Mono
252
278
  Regular (uninstalled)
253
279
  Italic (uninstalled)
@@ -274,11 +300,17 @@ $ fontist manifest-locations manifest.yml
274
300
  ---
275
301
  Segoe UI:
276
302
  Regular:
277
- - "/Users/user/.fontist/fonts/SEGOEUI.TTF"
303
+ full_name: Segoe UI
304
+ paths:
305
+ - "/Users/user/.fontist/fonts/SEGOEUI.TTF"
278
306
  Bold:
279
- - "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
307
+ full_name: Segoe UI Bold
308
+ paths:
309
+ - "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
280
310
  Roboto Mono:
281
- Regular: []
311
+ Regular:
312
+ full_name:
313
+ paths: []
282
314
  ```
283
315
 
284
316
  Since Segoe UI is installed, but Roboto Mono is not.
@@ -292,12 +324,18 @@ $ fontist manifest-install --confirm-license manifest.yml
292
324
  ---
293
325
  Segoe UI:
294
326
  Regular:
295
- - "/Users/user/.fontist/fonts/SEGOEUI.TTF"
327
+ full_name: Segoe UI
328
+ paths:
329
+ - "/Users/user/.fontist/fonts/SEGOEUI.TTF"
296
330
  Bold:
297
- - "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
331
+ full_name: Segoe UI Bold
332
+ paths:
333
+ - "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
298
334
  Roboto Mono:
299
335
  Regular:
300
- - "/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"
336
+ full_name: Roboto Mono Regular
337
+ paths:
338
+ - "/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"
301
339
  ```
302
340
 
303
341
  #### Help
@@ -308,6 +346,15 @@ List of all commands could be seen by:
308
346
  fontist help
309
347
  ```
310
348
 
349
+ ### Configuration
350
+
351
+ By default Fontist uses the `~/.fontist` directory to store fonts and its
352
+ files. It could be changed with the `FONTIST_PATH` environment variable.
353
+
354
+ ```sh
355
+ FONTIST_PATH=~/.fontist_new fontist update
356
+ ```
357
+
311
358
  ## Development
312
359
 
313
360
  We are following Sandi Metz's Rules for this gem, you can read the
@@ -348,8 +395,22 @@ archive:
348
395
  ```sh
349
396
  fontist create-formula https://www.latofonts.com/download/lato2ofl-zip/
350
397
  cp lato.yml ~/.fontist/formulas/Formulas/
398
+ ```
399
+
400
+ A formula index should be rebuild, when a new formula is generated or an
401
+ existing one changed:
402
+
403
+ ```sh
404
+ fontist rebuild-index
405
+ ```
406
+
407
+ Then, both the formula and the updated index should be commited and pushed to
408
+ the formula repository:
409
+
410
+ ```sh
351
411
  cd ~/.fontist/formulas
352
412
  git add Formulas/lato.yml
413
+ git add index.yml
353
414
  git commit -m "Add Lato formula"
354
415
  ```
355
416
 
@@ -373,6 +434,22 @@ git commit -m "Google Fonts update"
373
434
  git push
374
435
  ```
375
436
 
437
+ ### Releasing
438
+
439
+ Releasing is done automatically with GitHub Action. Just bump and tag with `gem-release`.
440
+
441
+ For a patch release (0.0.x) use:
442
+
443
+ ```sh
444
+ gem bump --version patch --tag --push
445
+ ```
446
+
447
+ For a minor release (0.x.0) use:
448
+
449
+ ```sh
450
+ gem bump --version minor --tag --push
451
+ ```
452
+
376
453
  ## Contributing
377
454
 
378
455
  First, thank you for contributing! We love pull requests from everyone. By
File without changes
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.require_paths = ["lib"]
23
23
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
- f.match(%r{^(test|spec|features)/})
24
+ f.match(%r{^(bin|test|spec|features)/})
25
25
  end
26
- spec.bindir = "bin"
26
+ spec.bindir = "exe"
27
27
  spec.executables = ["fontist"]
28
28
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
29
29
 
@@ -34,10 +34,12 @@ Gem::Specification.new do |spec|
34
34
  spec.add_runtime_dependency "ruby-ole", "~> 1.0"
35
35
  spec.add_runtime_dependency "thor", "~> 1.0.1"
36
36
  spec.add_runtime_dependency "git", "~> 1.0"
37
+ spec.add_runtime_dependency "ttfunk", "~> 1.0"
37
38
 
38
39
  spec.add_development_dependency "extract_ttc", "~> 0.1"
39
40
  spec.add_development_dependency "pry"
40
41
  spec.add_development_dependency "bundler", "~> 2.0"
42
+ spec.add_development_dependency "gem-release"
41
43
  spec.add_development_dependency "rake", "~> 12.3.3"
42
44
  spec.add_development_dependency "rspec", "~> 3.0"
43
45
  spec.add_development_dependency "rubocop", "0.75.0"
@@ -8,12 +8,11 @@ require "fontist/errors"
8
8
  require "fontist/version"
9
9
 
10
10
  require "fontist/font"
11
- require "fontist/registry"
12
- require "fontist/formulas"
13
11
  require "fontist/formula"
14
12
  require "fontist/system_font"
15
13
  require "fontist/fontist_font"
16
14
  require "fontist/manifest"
15
+ require "fontist/helpers"
17
16
 
18
17
  module Fontist
19
18
  def self.ui
@@ -29,7 +28,7 @@ module Fontist
29
28
  end
30
29
 
31
30
  def self.fontist_path
32
- Pathname.new(Dir.home).join(".fontist")
31
+ Pathname.new(ENV["FONTIST_PATH"] || File.join(Dir.home, ".fontist"))
33
32
  end
34
33
 
35
34
  def self.fonts_path
@@ -55,4 +54,12 @@ module Fontist
55
54
  def self.system_file_path
56
55
  Fontist.lib_path.join("fontist", "system.yml")
57
56
  end
57
+
58
+ def self.system_index_path
59
+ Fontist.fontist_path.join("system_index.yml")
60
+ end
61
+
62
+ def self.formula_index_path
63
+ Fontist.formulas_repo_path.join("index.yml")
64
+ end
58
65
  end
@@ -3,20 +3,40 @@ require "thor"
3
3
  module Fontist
4
4
  class CLI < Thor
5
5
  STATUS_SUCCESS = 0
6
- STATUS_ERROR = 1
6
+ STATUS_UNKNOWN_ERROR = 1
7
+ STATUS_NON_SUPPORTED_FONT_ERROR = 2
8
+ STATUS_MISSING_FONT_ERROR = 3
9
+ STATUS_LICENSING_ERROR = 4
10
+ STATUS_MANIFEST_COULD_NOT_BE_FOUND_ERROR = 5
11
+ STATUS_MANIFEST_COULD_NOT_BE_READ_ERROR = 6
12
+
13
+ ERROR_TO_STATUS = {
14
+ Fontist::Errors::NonSupportedFontError => [STATUS_NON_SUPPORTED_FONT_ERROR],
15
+ Fontist::Errors::MissingFontError => [STATUS_MISSING_FONT_ERROR],
16
+ Fontist::Errors::LicensingError => [STATUS_LICENSING_ERROR],
17
+ Fontist::Errors::ManifestCouldNotBeFoundError => [STATUS_MANIFEST_COULD_NOT_BE_FOUND_ERROR,
18
+ "Manifest could not be found."],
19
+ Fontist::Errors::ManifestCouldNotBeReadError => [STATUS_MANIFEST_COULD_NOT_BE_READ_ERROR,
20
+ "Manifest could not be read."],
21
+ }.freeze
7
22
 
8
23
  def self.exit_on_failure?
9
24
  false
10
25
  end
11
26
 
12
- desc "install FONT", "Install font by font or formula"
27
+ desc "install FONT", "Install font"
13
28
  option :force, type: :boolean, aliases: :f,
14
29
  desc: "Install even if it's already installed in system"
30
+ option :confirm_license, type: :boolean, desc: "Confirm license agreement"
15
31
  def install(font)
16
- Fontist::Font.install(font, force: options[:force])
17
- STATUS_SUCCESS
18
- rescue Fontist::Errors::NonSupportedFontError
19
- could_not_find_font(font)
32
+ Fontist::Font.install(
33
+ font,
34
+ force: options[:force],
35
+ confirmation: options[:confirm_license] ? "yes" : "no"
36
+ )
37
+ success
38
+ rescue Fontist::Errors::GeneralError => e
39
+ handle_error(e)
20
40
  end
21
41
 
22
42
  desc "uninstall/remove FONT", "Uninstall font by font or formula"
@@ -24,26 +44,21 @@ module Fontist
24
44
  fonts_paths = Fontist::Font.uninstall(font)
25
45
  Fontist.ui.success("These fonts are removed:")
26
46
  Fontist.ui.success(fonts_paths.join("\n"))
27
- STATUS_SUCCESS
28
- rescue Fontist::Errors::MissingFontError => e
29
- Fontist.ui.error(e.message)
30
- STATUS_ERROR
31
- rescue Fontist::Errors::NonSupportedFontError
32
- could_not_find_font(font)
47
+ success
48
+ rescue Fontist::Errors::GeneralError => e
49
+ handle_error(e)
33
50
  end
34
51
  map remove: :uninstall
35
52
 
36
53
  desc "status [FONT]", "Show status of FONT or all fonts in fontist"
37
54
  def status(font = nil)
38
55
  formulas = Fontist::Font.status(font)
39
- return error("No font is installed.") if formulas.empty?
56
+ return error("No font is installed.", STATUS_MISSING_FONT_ERROR) if formulas.empty?
40
57
 
41
58
  print_formulas(formulas)
42
59
  success
43
- rescue Fontist::Errors::MissingFontError => e
44
- error(e.message)
45
- rescue Fontist::Errors::NonSupportedFontError
46
- could_not_find_font(font)
60
+ rescue Fontist::Errors::GeneralError => e
61
+ handle_error(e)
47
62
  end
48
63
 
49
64
  desc "list [FONT]", "List installation status of FONT or fonts in fontist"
@@ -51,53 +66,61 @@ module Fontist
51
66
  formulas = Fontist::Font.list(font)
52
67
  print_list(formulas)
53
68
  success
54
- rescue Fontist::Errors::NonSupportedFontError
55
- could_not_find_font(font)
69
+ rescue Fontist::Errors::GeneralError => e
70
+ handle_error(e)
56
71
  end
57
72
 
58
73
  desc "update", "Update formulas"
59
74
  def update
60
- Formulas.fetch_formulas
75
+ Formula.update_formulas_repo
61
76
  Fontist.ui.say("Formulas have been successfully updated")
62
- STATUS_SUCCESS
77
+ success
63
78
  end
64
79
 
65
80
  desc "manifest-locations MANIFEST",
66
81
  "Get locations of fonts from MANIFEST (yaml)"
67
82
  def manifest_locations(manifest)
68
- paths = Fontist::Manifest::Locations.call(manifest)
83
+ paths = Fontist::Manifest::Locations.from_file(manifest)
69
84
  print_yaml(paths)
70
85
  success
71
- rescue Fontist::Errors::ManifestCouldNotBeFoundError
72
- error("Manifest could not be found.")
73
- rescue Fontist::Errors::ManifestCouldNotBeReadError
74
- error("Manifest could not be read.")
86
+ rescue Fontist::Errors::GeneralError => e
87
+ handle_error(e)
75
88
  end
76
89
 
77
90
  desc "manifest-install MANIFEST", "Install fonts from MANIFEST (yaml)"
78
91
  option :confirm_license, type: :boolean, desc: "Confirm license agreement"
79
92
  def manifest_install(manifest)
80
- paths = Fontist::Manifest::Install.call(
93
+ paths = Fontist::Manifest::Install.from_file(
81
94
  manifest,
82
95
  confirmation: options[:confirm_license] ? "yes" : "no"
83
96
  )
84
97
 
85
98
  print_yaml(paths)
86
99
  success
87
- rescue Fontist::Errors::ManifestCouldNotBeFoundError
88
- error("Manifest could not be found.")
89
- rescue Fontist::Errors::ManifestCouldNotBeReadError
90
- error("Manifest could not be read.")
100
+ rescue Fontist::Errors::GeneralError => e
101
+ handle_error(e)
91
102
  end
92
103
 
93
104
  desc "create-formula URL", "Create a new formula with fonts from URL"
94
105
  option :name, desc: "Example: Times New Roman"
95
106
  option :mirror, repeatable: true
96
107
  option :subarchive, desc: "Subarchive to choose when there are several ones"
108
+ option :subdir, desc: "Subdirectory to take fonts from"
97
109
  def create_formula(url)
98
110
  require "fontist/import/create_formula"
99
111
  name = Fontist::Import::CreateFormula.new(url, options).call
100
112
  Fontist.ui.say("#{name} formula has been successfully created")
113
+ success
114
+ end
115
+
116
+ desc "rebuild-index", "Rebuild formula index (used by formulas maintainers)"
117
+ long_desc <<-LONGDESC
118
+ This index is pre-built and served with formulas, so there is no need
119
+ update it unless something changes in the formulas repo.
120
+ LONGDESC
121
+ def rebuild_index
122
+ Fontist::Index.rebuild
123
+ Fontist.ui.say("Formula index has been rebuilt.")
101
124
  STATUS_SUCCESS
102
125
  end
103
126
 
@@ -107,18 +130,16 @@ module Fontist
107
130
  STATUS_SUCCESS
108
131
  end
109
132
 
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.")
133
+ def handle_error(exception)
134
+ status, message = ERROR_TO_STATUS[exception.class]
135
+ raise exception unless status
136
+
137
+ error(message || exception.message, status)
117
138
  end
118
139
 
119
- def error(message)
140
+ def error(message, status)
120
141
  Fontist.ui.error(message)
121
- STATUS_ERROR
142
+ status
122
143
  end
123
144
 
124
145
  def print_yaml(object)
@@ -127,7 +148,7 @@ module Fontist
127
148
 
128
149
  def print_formulas(formulas)
129
150
  formulas.each do |formula, fonts|
130
- Fontist.ui.success(formula.installer)
151
+ Fontist.ui.success(formula.key)
131
152
 
132
153
  fonts.each do |font, styles|
133
154
  Fontist.ui.success(" #{font.name}")
@@ -142,7 +163,7 @@ module Fontist
142
163
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
143
164
  def print_list(formulas)
144
165
  formulas.each do |formula, fonts|
145
- Fontist.ui.say(formula.installer)
166
+ Fontist.ui.say(formula.key)
146
167
 
147
168
  fonts.each do |font, styles|
148
169
  Fontist.ui.say(" #{font.name}")