fontist 1.7.3 → 1.8.1
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 +5 -5
- data/.github/workflows/release.yml +38 -0
- data/.github/workflows/rspec.yml +58 -0
- data/README.md +34 -4
- data/{bin → exe}/fontist +0 -0
- data/fontist.gemspec +3 -2
- data/lib/fontist.rb +5 -2
- data/lib/fontist/cli.rb +53 -38
- data/lib/fontist/errors.rb +14 -12
- data/lib/fontist/font.rb +25 -27
- data/lib/fontist/font_installer.rb +114 -0
- data/lib/fontist/fontist_font.rb +3 -49
- data/lib/fontist/formula.rb +101 -35
- data/lib/fontist/formula_paths.rb +43 -0
- data/lib/fontist/helpers.rb +7 -0
- data/lib/fontist/import/google_check.rb +1 -1
- data/lib/fontist/import/google_import.rb +3 -4
- data/lib/fontist/import/otfinfo_generate.rb +1 -1
- data/lib/fontist/import/recursive_extraction.rb +5 -1
- data/lib/fontist/index.rb +72 -0
- data/lib/fontist/index_formula.rb +30 -0
- data/lib/fontist/manifest/install.rb +4 -5
- data/lib/fontist/manifest/locations.rb +9 -1
- data/lib/fontist/system_font.rb +2 -29
- data/lib/fontist/system_index.rb +1 -1
- data/lib/fontist/utils/exe_extractor.rb +1 -1
- data/lib/fontist/utils/zip_extractor.rb +1 -1
- data/lib/fontist/version.rb +1 -1
- metadata +27 -19
- data/.github/workflows/macosx.yml +0 -33
- data/.github/workflows/ubuntu.yml +0 -30
- data/.github/workflows/windows.yml +0 -32
- data/bin/check_google +0 -8
- data/bin/console +0 -11
- data/bin/convert_formulas +0 -8
- data/bin/generate_otfinfo +0 -8
- data/bin/import_google +0 -8
- data/bin/rspec +0 -29
- data/bin/setup +0 -7
- data/lib/fontist/font_formula.rb +0 -169
- data/lib/fontist/formula_template.rb +0 -122
- data/lib/fontist/formulas.rb +0 -56
- data/lib/fontist/registry.rb +0 -43
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 0d083618f330800ccb94e30d93fa8b5bf65d5e0a
         | 
| 4 | 
            +
              data.tar.gz: 133e64a85156c8fa5dcfc284ef57b3047fdbec0e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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:: | 
| 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 |  | 
| @@ -249,7 +249,7 @@ Prints installed font paths grouped by formula and font. | |
| 249 249 |  | 
| 250 250 | 
             
            ```
         | 
| 251 251 | 
             
            $ fontist status "segoe ui"
         | 
| 252 | 
            -
             | 
| 252 | 
            +
            segoe_ui
         | 
| 253 253 | 
             
             Segoe UI
         | 
| 254 254 | 
             
              Regular (/Users/user/.fontist/fonts/SEGOEUI.TTF)
         | 
| 255 255 | 
             
              Bold (/Users/user/.fontist/fonts/SEGOEUIB.TTF)
         | 
| @@ -263,7 +263,7 @@ Lists installation status of fonts supported by Fontist. | |
| 263 263 |  | 
| 264 264 | 
             
            ```
         | 
| 265 265 | 
             
            $ fontist list "segoe ui"
         | 
| 266 | 
            -
             | 
| 266 | 
            +
            segoe_ui
         | 
| 267 267 | 
             
             Segoe UI
         | 
| 268 268 | 
             
              Regular (installed)
         | 
| 269 269 | 
             
              Bold (installed)
         | 
| @@ -273,7 +273,7 @@ Fontist::Formulas::SegoeUIFont | |
| 273 273 |  | 
| 274 274 | 
             
            ```
         | 
| 275 275 | 
             
            $ fontist list "roboto mono"
         | 
| 276 | 
            -
             | 
| 276 | 
            +
            google/roboto_mono
         | 
| 277 277 | 
             
             Roboto Mono
         | 
| 278 278 | 
             
              Regular (uninstalled)
         | 
| 279 279 | 
             
              Italic (uninstalled)
         | 
| @@ -395,8 +395,22 @@ archive: | |
| 395 395 | 
             
            ```sh
         | 
| 396 396 | 
             
            fontist create-formula https://www.latofonts.com/download/lato2ofl-zip/
         | 
| 397 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
         | 
| 398 411 | 
             
            cd ~/.fontist/formulas
         | 
| 399 412 | 
             
            git add Formulas/lato.yml
         | 
| 413 | 
            +
            git add index.yml
         | 
| 400 414 | 
             
            git commit -m "Add Lato formula"
         | 
| 401 415 | 
             
            ```
         | 
| 402 416 |  | 
| @@ -420,6 +434,22 @@ git commit -m "Google Fonts update" | |
| 420 434 | 
             
            git push
         | 
| 421 435 | 
             
            ```
         | 
| 422 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 | 
            +
             | 
| 423 453 | 
             
            ## Contributing
         | 
| 424 454 |  | 
| 425 455 | 
             
            First, thank you for contributing! We love pull requests from everyone. By
         | 
    
        data/{bin → exe}/fontist
    RENAMED
    
    | 
            File without changes
         | 
    
        data/fontist.gemspec
    CHANGED
    
    | @@ -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        = " | 
| 26 | 
            +
              spec.bindir        = "exe"
         | 
| 27 27 | 
             
              spec.executables   = ["fontist"]
         | 
| 28 28 | 
             
              spec.test_files    = `git ls-files -- {spec}/*`.split("\n")
         | 
| 29 29 |  | 
| @@ -39,6 +39,7 @@ Gem::Specification.new do |spec| | |
| 39 39 | 
             
              spec.add_development_dependency "extract_ttc", "~> 0.1"
         | 
| 40 40 | 
             
              spec.add_development_dependency "pry"
         | 
| 41 41 | 
             
              spec.add_development_dependency "bundler", "~> 2.0"
         | 
| 42 | 
            +
              spec.add_development_dependency "gem-release"
         | 
| 42 43 | 
             
              spec.add_development_dependency "rake", "~> 12.3.3"
         | 
| 43 44 | 
             
              spec.add_development_dependency "rspec", "~> 3.0"
         | 
| 44 45 | 
             
              spec.add_development_dependency "rubocop", "0.75.0"
         | 
    
        data/lib/fontist.rb
    CHANGED
    
    | @@ -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
         | 
| @@ -59,4 +58,8 @@ module Fontist | |
| 59 58 | 
             
              def self.system_index_path
         | 
| 60 59 | 
             
                Fontist.fontist_path.join("system_index.yml")
         | 
| 61 60 | 
             
              end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              def self.formula_index_path
         | 
| 63 | 
            +
                Fontist.formulas_repo_path.join("index.yml")
         | 
| 64 | 
            +
              end
         | 
| 62 65 | 
             
            end
         | 
    
        data/lib/fontist/cli.rb
    CHANGED
    
    | @@ -3,7 +3,22 @@ require "thor" | |
| 3 3 | 
             
            module Fontist
         | 
| 4 4 | 
             
              class CLI < Thor
         | 
| 5 5 | 
             
                STATUS_SUCCESS = 0
         | 
| 6 | 
            -
                 | 
| 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
         | 
| @@ -19,9 +34,9 @@ module Fontist | |
| 19 34 | 
             
                    force: options[:force],
         | 
| 20 35 | 
             
                    confirmation: options[:confirm_license] ? "yes" : "no"
         | 
| 21 36 | 
             
                  )
         | 
| 22 | 
            -
                   | 
| 23 | 
            -
                rescue Fontist::Errors:: | 
| 24 | 
            -
                   | 
| 37 | 
            +
                  success
         | 
| 38 | 
            +
                rescue Fontist::Errors::GeneralError => e
         | 
| 39 | 
            +
                  handle_error(e)
         | 
| 25 40 | 
             
                end
         | 
| 26 41 |  | 
| 27 42 | 
             
                desc "uninstall/remove FONT", "Uninstall font by font or formula"
         | 
| @@ -29,26 +44,21 @@ module Fontist | |
| 29 44 | 
             
                  fonts_paths = Fontist::Font.uninstall(font)
         | 
| 30 45 | 
             
                  Fontist.ui.success("These fonts are removed:")
         | 
| 31 46 | 
             
                  Fontist.ui.success(fonts_paths.join("\n"))
         | 
| 32 | 
            -
                   | 
| 33 | 
            -
                rescue Fontist::Errors:: | 
| 34 | 
            -
                   | 
| 35 | 
            -
                  STATUS_ERROR
         | 
| 36 | 
            -
                rescue Fontist::Errors::NonSupportedFontError
         | 
| 37 | 
            -
                  could_not_find_font(font)
         | 
| 47 | 
            +
                  success
         | 
| 48 | 
            +
                rescue Fontist::Errors::GeneralError => e
         | 
| 49 | 
            +
                  handle_error(e)
         | 
| 38 50 | 
             
                end
         | 
| 39 51 | 
             
                map remove: :uninstall
         | 
| 40 52 |  | 
| 41 53 | 
             
                desc "status [FONT]", "Show status of FONT or all fonts in fontist"
         | 
| 42 54 | 
             
                def status(font = nil)
         | 
| 43 55 | 
             
                  formulas = Fontist::Font.status(font)
         | 
| 44 | 
            -
                  return error("No font is installed.") if formulas.empty?
         | 
| 56 | 
            +
                  return error("No font is installed.", STATUS_MISSING_FONT_ERROR) if formulas.empty?
         | 
| 45 57 |  | 
| 46 58 | 
             
                  print_formulas(formulas)
         | 
| 47 59 | 
             
                  success
         | 
| 48 | 
            -
                rescue Fontist::Errors:: | 
| 49 | 
            -
                   | 
| 50 | 
            -
                rescue Fontist::Errors::NonSupportedFontError
         | 
| 51 | 
            -
                  could_not_find_font(font)
         | 
| 60 | 
            +
                rescue Fontist::Errors::GeneralError => e
         | 
| 61 | 
            +
                  handle_error(e)
         | 
| 52 62 | 
             
                end
         | 
| 53 63 |  | 
| 54 64 | 
             
                desc "list [FONT]", "List installation status of FONT or fonts in fontist"
         | 
| @@ -56,15 +66,15 @@ module Fontist | |
| 56 66 | 
             
                  formulas = Fontist::Font.list(font)
         | 
| 57 67 | 
             
                  print_list(formulas)
         | 
| 58 68 | 
             
                  success
         | 
| 59 | 
            -
                rescue Fontist::Errors:: | 
| 60 | 
            -
                   | 
| 69 | 
            +
                rescue Fontist::Errors::GeneralError => e
         | 
| 70 | 
            +
                  handle_error(e)
         | 
| 61 71 | 
             
                end
         | 
| 62 72 |  | 
| 63 73 | 
             
                desc "update", "Update formulas"
         | 
| 64 74 | 
             
                def update
         | 
| 65 | 
            -
                   | 
| 75 | 
            +
                  Formula.update_formulas_repo
         | 
| 66 76 | 
             
                  Fontist.ui.say("Formulas have been successfully updated")
         | 
| 67 | 
            -
                   | 
| 77 | 
            +
                  success
         | 
| 68 78 | 
             
                end
         | 
| 69 79 |  | 
| 70 80 | 
             
                desc "manifest-locations MANIFEST",
         | 
| @@ -73,10 +83,8 @@ module Fontist | |
| 73 83 | 
             
                  paths = Fontist::Manifest::Locations.from_file(manifest)
         | 
| 74 84 | 
             
                  print_yaml(paths)
         | 
| 75 85 | 
             
                  success
         | 
| 76 | 
            -
                rescue Fontist::Errors:: | 
| 77 | 
            -
                   | 
| 78 | 
            -
                rescue Fontist::Errors::ManifestCouldNotBeReadError
         | 
| 79 | 
            -
                  error("Manifest could not be read.")
         | 
| 86 | 
            +
                rescue Fontist::Errors::GeneralError => e
         | 
| 87 | 
            +
                  handle_error(e)
         | 
| 80 88 | 
             
                end
         | 
| 81 89 |  | 
| 82 90 | 
             
                desc "manifest-install MANIFEST", "Install fonts from MANIFEST (yaml)"
         | 
| @@ -89,10 +97,8 @@ module Fontist | |
| 89 97 |  | 
| 90 98 | 
             
                  print_yaml(paths)
         | 
| 91 99 | 
             
                  success
         | 
| 92 | 
            -
                rescue Fontist::Errors:: | 
| 93 | 
            -
                   | 
| 94 | 
            -
                rescue Fontist::Errors::ManifestCouldNotBeReadError
         | 
| 95 | 
            -
                  error("Manifest could not be read.")
         | 
| 100 | 
            +
                rescue Fontist::Errors::GeneralError => e
         | 
| 101 | 
            +
                  handle_error(e)
         | 
| 96 102 | 
             
                end
         | 
| 97 103 |  | 
| 98 104 | 
             
                desc "create-formula URL", "Create a new formula with fonts from URL"
         | 
| @@ -104,6 +110,17 @@ module Fontist | |
| 104 110 | 
             
                  require "fontist/import/create_formula"
         | 
| 105 111 | 
             
                  name = Fontist::Import::CreateFormula.new(url, options).call
         | 
| 106 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.")
         | 
| 107 124 | 
             
                  STATUS_SUCCESS
         | 
| 108 125 | 
             
                end
         | 
| 109 126 |  | 
| @@ -113,18 +130,16 @@ module Fontist | |
| 113 130 | 
             
                  STATUS_SUCCESS
         | 
| 114 131 | 
             
                end
         | 
| 115 132 |  | 
| 116 | 
            -
                def  | 
| 117 | 
            -
                   | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
                        "You can update the formula repository using the command " \
         | 
| 122 | 
            -
                        "`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)
         | 
| 123 138 | 
             
                end
         | 
| 124 139 |  | 
| 125 | 
            -
                def error(message)
         | 
| 140 | 
            +
                def error(message, status)
         | 
| 126 141 | 
             
                  Fontist.ui.error(message)
         | 
| 127 | 
            -
                   | 
| 142 | 
            +
                  status
         | 
| 128 143 | 
             
                end
         | 
| 129 144 |  | 
| 130 145 | 
             
                def print_yaml(object)
         | 
| @@ -133,7 +148,7 @@ module Fontist | |
| 133 148 |  | 
| 134 149 | 
             
                def print_formulas(formulas)
         | 
| 135 150 | 
             
                  formulas.each do |formula, fonts|
         | 
| 136 | 
            -
                    Fontist.ui.success(formula. | 
| 151 | 
            +
                    Fontist.ui.success(formula.key)
         | 
| 137 152 |  | 
| 138 153 | 
             
                    fonts.each do |font, styles|
         | 
| 139 154 | 
             
                      Fontist.ui.success(" #{font.name}")
         | 
| @@ -148,7 +163,7 @@ module Fontist | |
| 148 163 | 
             
                # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
         | 
| 149 164 | 
             
                def print_list(formulas)
         | 
| 150 165 | 
             
                  formulas.each do |formula, fonts|
         | 
| 151 | 
            -
                    Fontist.ui.say(formula. | 
| 166 | 
            +
                    Fontist.ui.say(formula.key)
         | 
| 152 167 |  | 
| 153 168 | 
             
                    fonts.each do |font, styles|
         | 
| 154 169 | 
             
                      Fontist.ui.say(" #{font.name}")
         | 
    
        data/lib/fontist/errors.rb
    CHANGED
    
    | @@ -1,16 +1,18 @@ | |
| 1 1 | 
             
            module Fontist
         | 
| 2 2 | 
             
              module Errors
         | 
| 3 | 
            -
                class  | 
| 4 | 
            -
                class  | 
| 5 | 
            -
                class  | 
| 6 | 
            -
                class  | 
| 7 | 
            -
                class InvalidResourceError <  | 
| 8 | 
            -
                class  | 
| 9 | 
            -
                class  | 
| 10 | 
            -
                class  | 
| 11 | 
            -
                class  | 
| 12 | 
            -
                class  | 
| 13 | 
            -
                class  | 
| 14 | 
            -
                class  | 
| 3 | 
            +
                class GeneralError < StandardError; end
         | 
| 4 | 
            +
                class BinaryCallError < GeneralError; end
         | 
| 5 | 
            +
                class FontNotFoundError < GeneralError; end
         | 
| 6 | 
            +
                class FormulaIndexNotFoundError < GeneralError; end
         | 
| 7 | 
            +
                class InvalidResourceError < GeneralError; end
         | 
| 8 | 
            +
                class LicensingError < GeneralError; end
         | 
| 9 | 
            +
                class ManifestCouldNotBeFoundError < GeneralError; end
         | 
| 10 | 
            +
                class ManifestCouldNotBeReadError < GeneralError; end
         | 
| 11 | 
            +
                class MissingAttributeError < GeneralError; end
         | 
| 12 | 
            +
                class MissingFontError < GeneralError; end
         | 
| 13 | 
            +
                class NonSupportedFontError < GeneralError; end
         | 
| 14 | 
            +
                class TamperedFileError < GeneralError; end
         | 
| 15 | 
            +
                class TimeoutError < GeneralError; end
         | 
| 16 | 
            +
                class UnknownFontTypeError < GeneralError; end
         | 
| 15 17 | 
             
              end
         | 
| 16 18 | 
             
            end
         | 
    
        data/lib/fontist/font.rb
    CHANGED
    
    | @@ -1,3 +1,5 @@ | |
| 1 | 
            +
            require "fontist/font_installer"
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module Fontist
         | 
| 2 4 | 
             
              class Font
         | 
| 3 5 | 
             
                def initialize(options = {})
         | 
| @@ -20,10 +22,6 @@ module Fontist | |
| 20 22 | 
             
                  new(name: name, confirmation: confirmation, force: force).install
         | 
| 21 23 | 
             
                end
         | 
| 22 24 |  | 
| 23 | 
            -
                def self.try_install(name, confirmation: "no")
         | 
| 24 | 
            -
                  new(name: name, confirmation: confirmation).try_install
         | 
| 25 | 
            -
                end
         | 
| 26 | 
            -
             | 
| 27 25 | 
             
                def self.uninstall(name)
         | 
| 28 26 | 
             
                  new(name: name).uninstall
         | 
| 29 27 | 
             
                end
         | 
| @@ -37,43 +35,31 @@ module Fontist | |
| 37 35 | 
             
                end
         | 
| 38 36 |  | 
| 39 37 | 
             
                def find
         | 
| 40 | 
            -
                  find_system_font || downloadable_font ||  | 
| 41 | 
            -
                    Fontist::Errors::NonSupportedFontError
         | 
| 42 | 
            -
                  )
         | 
| 38 | 
            +
                  find_system_font || downloadable_font || raise_non_supported_font
         | 
| 43 39 | 
             
                end
         | 
| 44 40 |  | 
| 45 41 | 
             
                def install
         | 
| 46 | 
            -
                  (find_system_font unless @force) || download_font ||  | 
| 47 | 
            -
                    Fontist::Errors::NonSupportedFontError
         | 
| 48 | 
            -
                  )
         | 
| 49 | 
            -
                end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                def try_install
         | 
| 52 | 
            -
                  download_font
         | 
| 42 | 
            +
                  (find_system_font unless @force) || download_font || raise_non_supported_font
         | 
| 53 43 | 
             
                end
         | 
| 54 44 |  | 
| 55 45 | 
             
                def uninstall
         | 
| 56 | 
            -
                  uninstall_font || downloadable_font ||  | 
| 57 | 
            -
                    Fontist::Errors::NonSupportedFontError
         | 
| 58 | 
            -
                  )
         | 
| 46 | 
            +
                  uninstall_font || downloadable_font || raise_non_supported_font
         | 
| 59 47 | 
             
                end
         | 
| 60 48 |  | 
| 61 49 | 
             
                def status
         | 
| 62 50 | 
             
                  return installed_statuses unless @name
         | 
| 63 51 |  | 
| 64 | 
            -
                  font_status || downloadable_font ||  | 
| 65 | 
            -
                    Fontist::Errors::NonSupportedFontError
         | 
| 66 | 
            -
                  )
         | 
| 52 | 
            +
                  font_status || downloadable_font || raise_non_supported_font
         | 
| 67 53 | 
             
                end
         | 
| 68 54 |  | 
| 69 55 | 
             
                def list
         | 
| 70 56 | 
             
                  return all_list unless @name
         | 
| 71 57 |  | 
| 72 | 
            -
                  font_list ||  | 
| 58 | 
            +
                  font_list || raise_non_supported_font
         | 
| 73 59 | 
             
                end
         | 
| 74 60 |  | 
| 75 61 | 
             
                def all
         | 
| 76 | 
            -
                  Fontist::Formula.all. | 
| 62 | 
            +
                  Fontist::Formula.all.map(&:fonts).flatten
         | 
| 77 63 | 
             
                end
         | 
| 78 64 |  | 
| 79 65 | 
             
                private
         | 
| @@ -101,7 +87,7 @@ module Fontist | |
| 101 87 | 
             
                end
         | 
| 102 88 |  | 
| 103 89 | 
             
                def font_installer(formula)
         | 
| 104 | 
            -
                   | 
| 90 | 
            +
                  FontInstaller.new(formula)
         | 
| 105 91 | 
             
                end
         | 
| 106 92 |  | 
| 107 93 | 
             
                def formula
         | 
| @@ -122,8 +108,7 @@ module Fontist | |
| 122 108 | 
             
                def download_font
         | 
| 123 109 | 
             
                  if formula
         | 
| 124 110 | 
             
                    check_and_confirm_required_license(formula)
         | 
| 125 | 
            -
                    paths = font_installer(formula). | 
| 126 | 
            -
                                                               confirmation: confirmation)
         | 
| 111 | 
            +
                    paths = font_installer(formula).install(confirmation: confirmation)
         | 
| 127 112 |  | 
| 128 113 | 
             
                    Fontist.ui.say("Fonts installed at:")
         | 
| 129 114 | 
             
                    paths.each do |path|
         | 
| @@ -186,7 +171,7 @@ module Fontist | |
| 186 171 | 
             
                end
         | 
| 187 172 |  | 
| 188 173 | 
             
                def all_formulas
         | 
| 189 | 
            -
                  Fontist::Formula.all | 
| 174 | 
            +
                  Fontist::Formula.all
         | 
| 190 175 | 
             
                end
         | 
| 191 176 |  | 
| 192 177 | 
             
                def font_status
         | 
| @@ -213,7 +198,9 @@ module Fontist | |
| 213 198 | 
             
                end
         | 
| 214 199 |  | 
| 215 200 | 
             
                def path(style)
         | 
| 216 | 
            -
                  font_paths. | 
| 201 | 
            +
                  font_paths.detect do |path|
         | 
| 202 | 
            +
                    File.basename(path) == style.font
         | 
| 203 | 
            +
                  end
         | 
| 217 204 | 
             
                end
         | 
| 218 205 |  | 
| 219 206 | 
             
                def font_paths
         | 
| @@ -247,5 +234,16 @@ module Fontist | |
| 247 234 | 
             
                def installed(style)
         | 
| 248 235 | 
             
                  path(style) ? true : false
         | 
| 249 236 | 
             
                end
         | 
| 237 | 
            +
             | 
| 238 | 
            +
                def raise_non_supported_font
         | 
| 239 | 
            +
                  raise Fontist::Errors::NonSupportedFontError.new(
         | 
| 240 | 
            +
                    "Font '#{@name}' not found locally nor available in the Fontist " \
         | 
| 241 | 
            +
                    "formula repository.\n" \
         | 
| 242 | 
            +
                    "Perhaps it is available at the latest Fontist formula " \
         | 
| 243 | 
            +
                    "repository.\n" \
         | 
| 244 | 
            +
                    "You can update the formula repository using the command " \
         | 
| 245 | 
            +
                    "`fontist update` and try again."
         | 
| 246 | 
            +
                  )
         | 
| 247 | 
            +
                end
         | 
| 250 248 | 
             
              end
         | 
| 251 249 | 
             
            end
         |