lib/frameit/config_parser.rb in frameit-2.4.1 vs lib/frameit/config_parser.rb in frameit-2.4.2

- old
+ new

@@ -1,21 +1,21 @@ module Frameit class ConfigParser def load(path) return nil unless File.exist?(path) # we are okay with no config at all - Helper.log.info "Parsing config file '#{path}'".yellow if $verbose + UI.message "Parsing config file '#{path}'" if $verbose @path = path self.parse(File.read(path)) end # @param data (String) the JSON data to be parsed def parse(data) begin @data = JSON.parse(data) rescue => ex - Helper.log.fatal ex - raise "Invalid JSON file at path '#{@path}'. Make sure it's a valid JSON file".red + UI.error ex.message + UI.user_error! "Invalid JSON file at path '#{@path}'. Make sure it's a valid JSON file" end self end @@ -61,32 +61,32 @@ values.each do |key, value| if value.kind_of? Hash validate_values(value) # recursive call else if key == 'font' - raise "Could not find font at path '#{File.expand_path(value)}'" unless File.exist? value + UI.user_error! "Could not find font at path '#{File.expand_path(value)}'" unless File.exist? value end if key == 'fonts' - raise "`fonts` must be an array" unless value.kind_of? Array + UI.user_error! "`fonts` must be an array" unless value.kind_of? Array value.each do |current| - raise "You must specify a font path" if current.fetch('font', '').length == 0 - raise "Could not find font at path '#{File.expand_path(current.fetch('font'))}'" unless File.exist? current.fetch('font') - raise "`supported` must be an array" unless current.fetch('supported', []).kind_of? Array + UI.user_error! "You must specify a font path" if current.fetch('font', '').length == 0 + UI.user_error! "Could not find font at path '#{File.expand_path(current.fetch('font'))}'" unless File.exist? current.fetch('font') + UI.user_error! "`supported` must be an array" unless current.fetch('supported', []).kind_of? Array end end if key == 'background' - raise "Could not find background image at path '#{File.expand_path(value)}'" unless File.exist? value + UI.user_error! "Could not find background image at path '#{File.expand_path(value)}'" unless File.exist? value end if key == 'color' - raise "Invalid color '#{value}'. Must be valid Hex #123123" unless value.include? "#" + UI.user_error! "Invalid color '#{value}'. Must be valid Hex #123123" unless value.include? "#" end if key == 'padding' - raise "padding must be type integer or pair of integers of format 'AxB'" unless value.kind_of?(Integer) || value.split('x').length == 2 + UI.user_error! "padding must be type integer or pair of integers of format 'AxB'" unless value.kind_of?(Integer) || value.split('x').length == 2 end end end end end