lib/fontcustom/base.rb in fontcustom-1.3.0.beta3 vs lib/fontcustom/base.rb in fontcustom-1.3.0.beta4
- old
+ new
@@ -2,24 +2,26 @@
module Fontcustom
class Base
include Utility
- def initialize(cli_options)
- @cli_options = cli_options
+ def initialize(raw_options)
check_fontforge
- init_manifest
+ manifest = ".fontcustom-manifest.json"
+ raw_options[:manifest] = manifest
+ @options = Fontcustom::Options.new(raw_options).options
+ @manifest = Fontcustom::Manifest.new(manifest, @options)
end
def compile
- @manifest[:checksum][:current] = checksum
- if @options[:force] || @manifest[:checksum][:current] != @manifest[:checksum][:previous]
- save_manifest
+ current = checksum
+ previous = @manifest.get(:checksum)[:previous]
+ if @options[:force] || current != previous
+ @manifest.set :checksum, {:previous => previous, :current => current}
start_generators
- @manifest = get_manifest
- @manifest[:checksum][:previous] = @manifest[:checksum][:current]
- save_manifest
+ @manifest.reload
+ @manifest.set :checksum, {:previous => current, :current => current}
else
say_message :status, "No changes detected. Skipping compilation."
end
end
@@ -30,16 +32,10 @@
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
@@ -47,10 +43,10 @@
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
+ Fontcustom::Generator::Font.new(@manifest.manifest).generate
+ Fontcustom::Generator::Template.new(@manifest.manifest).generate
end
end
end