Sha256: 5df352c97f219e25d22e74754852d32c992d9c35a75163c20b6a59d4807c0c1c

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

require "plist"
require "nokogiri"
require "fontist/import/create_formula"

module Fontist
  module Import
    class Macos
      FONT_XML = "/System/Library/AssetsV2/com_apple_MobileAsset_Font6/com_apple_MobileAsset_Font6.xml".freeze # rubocop:disable Layout/LineLength
      HOMEPAGE = "https://support.apple.com/en-om/HT211240#document".freeze

      def initialize(font_xml = FONT_XML)
        @font_xml = font_xml
      end

      def call
        links.each do |link|
          create_formula(link)
        end

        Fontist::Index.rebuild

        Fontist.ui.success("Created #{links.size} formulas.")
      end

      private

      def links
        data = Plist.parse_xml(@font_xml)
        data["Assets"].map do |x|
          x.values_at("__BaseURL", "__RelativePath").join
        end
      end

      def create_formula(url)
        path = Fontist::Import::CreateFormula.new(
          url,
          platforms: platforms,
          homepage: homepage,
          requires_license_agreement: license,
          formula_dir: formula_dir,
          keep_existing: true,
        ).call
        Fontist.ui.success("Formula has been successfully created: #{path}")

        path
      end

      def platforms
        ["macos"]
      end

      def homepage
        HOMEPAGE
      end

      def license
        @license ||= File.read(File.expand_path("macos/macos_license.txt",
                                                __dir__))
      end

      def formula_dir
        @formula_dir ||= Fontist.formulas_path.join("macos").tap do |path|
          FileUtils.mkdir_p(path) unless File.exist?(path)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fontist-1.21.2 lib/fontist/import/macos.rb
fontist-1.21.1 lib/fontist/import/macos.rb
fontist-1.20.0 lib/fontist/import/macos.rb
fontist-1.19.0 lib/fontist/import/macos.rb
fontist-1.18.2 lib/fontist/import/macos.rb