Sha256: b3cc89f206807a181cb2a5a40a28ac7ff0522a5b8d8142a23351770f8135baa5

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 KB

Contents

require "digest/sha2"

module Fontcustom
  class Base
    include Utility

    def initialize(cli_options)
      @cli_options = cli_options
      check_fontforge
      init_manifest
    end

    def compile
      @manifest[:checksum][:current] = checksum
      if @options[:force] || @manifest[:checksum][:current] != @manifest[:checksum][:previous]
        save_manifest
        start_generators
        @manifest = get_manifest
        @manifest[:checksum][:previous] = @manifest[:checksum][:current]
        save_manifest
      else
        say_message :status, "No changes detected. Skipping compilation."
      end
    end

    private

    def check_fontforge
      fontforge = `which fontforge`
      if fontforge == "" || fontforge == "fontforge not found"
        raise Fontcustom::Error, "Please install fontforge first. Visit <http://fontcustom.com> for instructions."
      end
    end

    def init_manifest
      file = @cli_options[:manifest] || File.join(Dir.pwd, ".fontcustom-manifest.json")
      @options = Fontcustom::Options.new(@cli_options).options
      @manifest = Fontcustom::Manifest.new(@options).manifest
    end

    # Calculates a hash of vectors, options, and templates (content and filenames)
    def checksum
      files = Dir.glob File.join(@options[:input][:vectors], "*.svg")
      files += Dir.glob File.join(@options[:input][:templates], "*")
      content = files.map { |file| File.read(file) }.join
      content << files.join
      content << @options.flatten(2).join
      Digest::SHA2.hexdigest(content).to_s
    end

    def start_generators
      Fontcustom::Generator::Font.new(@options[:manifest]).generate
      Fontcustom::Generator::Template.new(@options[:manifest]).generate
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fontcustom-1.3.0.beta3 lib/fontcustom/base.rb
fontcustom-1.3.0.beta2 lib/fontcustom/base.rb
fontcustom-1.3.0.beta lib/fontcustom/base.rb