lib/squib/deck.rb in squib-0.0.5 vs lib/squib/deck.rb in squib-0.0.6

- old
+ new

@@ -48,10 +48,11 @@ # @param width [Integer] the width of each card in pixels # @param height [Integer] the height of each card in pixels # @param cards [Integer] the number of cards in the deck # @param dpi [Integer] the pixels per inch when rendering out to PDF or calculating using inches. # @param config [String] the file used for global settings of this deck + # @param layout [String, Array] load a YML file of custom layouts. Multiple files are merged sequentially, redefining collisons. See README and sample for details. # @param block [Block] the main body of the script. # @api public def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block) @width=width; @height=height @dpi = dpi @@ -60,10 +61,11 @@ @custom_colors = {} @img_dir = '.' @progress_bar = Squib::Progress.new(false) @text_hint = :off cards.times{ @cards << Squib::Card.new(self, width, height) } + show_info(config, layout) load_config(config) load_layout(layout) if block_given? instance_eval(&block) end @@ -92,10 +94,11 @@ # Load the configuration file, if exists, overriding hardcoded defaults # @api private def load_config(file) if File.exists?(file) && config = YAML.load_file(file) + Squib::logger.info { " using config: #{file}" } config = Squib::CONFIG_DEFAULTS.merge(config) @dpi = config['dpi'].to_i @text_hint = config['text_hint'] @progress_bar.enabled = config['progress_bars'] @custom_colors = config['custom_colors'] @@ -103,16 +106,25 @@ end end # Load the layout configuration file, if exists # @api private - def load_layout(file) - return if file.nil? + def load_layout(files) @layout = {} - yml = YAML.load_file(file) - yml.each do |key, value| - @layout[key] = recurse_extends(yml, key, {}) + Squib::logger.info { " using layout(s): #{files}" } + Array(files).each do |file| + thefile = file + thefile = "#{File.dirname(__FILE__)}/layouts/#{file}" unless File.exists?(file) + if File.exists? thefile + yml = @layout.merge(YAML.load_file(thefile)) + yml.each do |key, value| + @layout[key] = recurse_extends(yml, key, {}) + end + else + puts "the file: #{thefile}" + Squib::logger.error { "Layout file not found: #{file}" } + end end end # Process the extends recursively # :nodoc: @@ -153,9 +165,14 @@ # @api private def assert_not_visited(key, visited) if visited.key? key raise "Invalid layout: circular extends with '#{key}'" end + end + + def show_info(config, layout) + Squib::logger.info "Squib v#{Squib::VERSION}" + Squib::logger.info " building #{@cards.size} #{@width}x#{@height} cards" end ################## ### PUBLIC API ### ##################