diff --git a/lib/squib/api/save.rb b/lib/squib/api/save.rb index ea2a061..782fa1f 100644 --- a/lib/squib/api/save.rb +++ b/lib/squib/api/save.rb @@ -24,12 +24,20 @@ module Squib # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges} # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist. # @option opts [String] prefix (card_) the prefix of the file name to be printed. + # @option opts [Boolean] progress_bar (false) if true, show a progress bar on stdout while saving # @return [nil] Returns nothing # @api public def save_png(opts = {}) - opts = needs(opts,[:range, :creatable_dir, :prefix]) + opts = needs(opts,[:range, :creatable_dir, :prefix, :progress_bar]) + if opts[:progress_bar] + require 'ruby-progressbar' + bar = ProgressBar.create(title: "Saving to PNGs", + starting_at: 0, total: opts[:range].size, + format: '%t <%B> %p%% %a') + end opts[:range].each do |i| @cards[i].save_png(i, opts[:dir], opts[:prefix]) + bar.increment if opts[:progress_bar] end end diff --git a/lib/squib/constants.rb b/lib/squib/constants.rb index 259e947..f0c64b5 100644 --- a/lib/squib/constants.rb +++ b/lib/squib/constants.rb @@ -34,7 +34,8 @@ module Squib :prefix => "card_", :margin => 75, :gap => 0, - :trim => 0 + :trim => 0, + :progress_bar => false } end \ No newline at end of file diff --git a/samples/basic.rb b/samples/basic.rb index f316dfb..1e90272 100644 --- a/samples/basic.rb +++ b/samples/basic.rb @@ -13,8 +13,8 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do text str: data['level'], x: 75, y: 85, width: 128, font: 'Arial 72', align: :center - png range: [0,2], file: 'shiny-purse.png', x: 620, y: 75 - svg range: 1..2, file: 'spanner.svg', x: 620, y: 218 + png range: [0,2], file: 'shiny-purse.png', x: 620, y: 75 + svg range: 1..2, file: 'spanner.svg', x: 620, y: 218 - save prefix: 'basic_', format: :png + save prefix: 'basic_', format: :png#, progress_bar: true end \ No newline at end of file diff --git a/squib.gemspec b/squib.gemspec index 60da14f..fda7c22 100644 --- a/squib.gemspec +++ b/squib.gemspec @@ -32,6 +32,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'roo', '~> 1.13.2' spec.add_runtime_dependency 'rsvg2', '~> 2.2.0' spec.add_runtime_dependency 'mercenary', '~> 0.3.4' + spec.add_runtime_dependency 'ruby-progressbar', '~> 1.5.1' spec.add_development_dependency "bundler", "~> 1.6" spec.add_development_dependency "rake"