Sha256: 4b738f1f4a88b5ff2e27822cf5cbd3876de1ba91ce9e9b9695003952446d8784

Contents?: true

Size: 1.75 KB

Versions: 8

Compression:

Stored size: 1.75 KB

Contents

require "digest/sha2"

module Fontcustom
  class Base
    include Utility

    def initialize(raw_options)
      check_fontforge
      manifest = ".fontcustom-manifest.json"
      raw_options[:manifest] = manifest
      @options = Fontcustom::Options.new(raw_options).options
      @manifest = Fontcustom::Manifest.new(manifest, @options)
    end

    def compile
      current = checksum
      previous = @manifest.get(:checksum)[:previous]

      say_message :status, "Forcing compile." if @options[:force]
      if @options[:force] || current != previous
        @manifest.set :checksum, {:previous => previous, :current => current}
        start_generators
        @manifest.reload
        @manifest.set :checksum, {:previous => current, :current => current}
      else
        say_message :status, "No changes detected. Skipping compile."
      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

    # Calculates a hash of vectors, options, and templates (content and filenames)
    def checksum
      files = Dir.glob(File.join(@options[:input][:vectors], "*.svg")).select { |fn| File.file?(fn) }
      files += Dir.glob(File.join(@options[:input][:templates], "*")).select { |fn| File.file?(fn) }
      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(@manifest.manifest).generate
      Fontcustom::Generator::Template.new(@manifest.manifest).generate
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
gkh-fontcustom-1.3.8 lib/fontcustom/base.rb
gkh-fontcustom-1.3.7 lib/fontcustom/base.rb
fontcustom-1.3.8 lib/fontcustom/base.rb
fontcustom-1.3.7 lib/fontcustom/base.rb
fontcustom-1.3.6 lib/fontcustom/base.rb
fontcustom-1.3.5 lib/fontcustom/base.rb
fontcustom-1.3.5.pre lib/fontcustom/base.rb
fontcustom-1.3.4 lib/fontcustom/base.rb