Sha256: 1095f0aa767571b971164da088677224e6b7388b34cd6dfce48292b23640b790

Contents?: true

Size: 1.05 KB

Versions: 8

Compression:

Stored size: 1.05 KB

Contents

require "erb"
require_relative "template_helper"
require_relative "text_helper"
require_relative "otf_parser"
require_relative "otf_style"

module Fontist
  module Import
    class OtfinfoGenerate
      TEMPLATE_PATH = File.expand_path("otfinfo/template.erb", __dir__)

      def initialize(font)
        @font = font
      end

      def call
        paths = font_paths(@font)
        puts paths
        styles = generate_styles(paths)
        puts render(styles)
      end

      private

      def font_paths(font)
        formula = Fontist::Formula.find(font)
        font_formula = Object.const_get(formula.installer)
        font_formula.fetch_font(nil, confirmation: "yes")
      end

      def generate_styles(paths)
        paths.map do |path|
          info = OtfParser.new(path).call
          OtfStyle.new(info, path).call
        end
      end

      def render(styles)
        template = File.read(TEMPLATE_PATH)
        renderer = ERB.new(template, trim_mode: "-")
        renderer.result(Fontist::Import::TemplateHelper.bind(styles))
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fontist-1.7.3 lib/fontist/import/otfinfo_generate.rb
fontist-1.7.2 lib/fontist/import/otfinfo_generate.rb
fontist-1.7.1 lib/fontist/import/otfinfo_generate.rb
fontist-1.7.0 lib/fontist/import/otfinfo_generate.rb
fontist-1.6.0 lib/fontist/import/otfinfo_generate.rb
fontist-1.5.1 lib/fontist/import/otfinfo_generate.rb
fontist-1.5.0 lib/fontist/import/otfinfo_generate.rb
fontist-1.4.0 lib/fontist/import/otfinfo_generate.rb