Adding progress bars to the custom configuration

This commit is contained in:
Andy Meneely
2014-07-31 15:20:39 -04:00
parent 65f75a3360
commit 8bfdf4b777
9 changed files with 96 additions and 35 deletions
+11 -5
View File
@@ -1,6 +1,6 @@
module Squib
class Deck
# Renders a png file at the given location.
#
# See {file:samples/image.rb samples/image.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
@@ -18,8 +18,11 @@ module Squib
# @api public
def png(opts = {})
opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout])
opts[:range].each do |i|
@cards[i].png(opts[:file][i], opts[:x], opts[:y], opts[:alpha])
@progress_bar.start("Loading PNGs #{location(opts)}", opts[:range].size) do |bar|
opts[:range].each do |i|
@cards[i].png(opts[:file][i], opts[:x], opts[:y], opts[:alpha])
bar.increment
end
end
end
@@ -40,8 +43,11 @@ module Squib
# @api public
def svg(opts = {})
p = needs(opts,[:range, :files, :svgid, :x, :y, :width, :height, :layout])
p[:range].each do |i|
@cards[i].svg(p[:file][i], p[:id], p[:x], p[:y], p[:width], p[:height])
@progress_bar.start("Loading SVGs #{location(opts)}", p[:range].size) do |bar|
p[:range].each do |i|
@cards[i].svg(p[:file][i], p[:id], p[:x], p[:y], p[:width], p[:height])
bar.increment
end
end
end
+6 -11
View File
@@ -24,20 +24,15 @@ 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, :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]
opts = needs(opts,[:range, :creatable_dir, :prefix])
@progress_bar.start("Saving PNGs to #{opts[:dir]}/#{opts[:prefix]}*") do |bar|
opts[:range].each do |i|
@cards[i].save_png(i, opts[:dir], opts[:prefix])
bar.increment
end
end
end
+5 -2
View File
@@ -6,14 +6,17 @@ module Squib
# Text hints are rectangles around where the text will be laid out. They are intended to be temporary.
# Setting a hint to nil or to :off will disable hints. @see samples/text.rb
# @example
# hint text:cyan
# hint text: :cyan
# hint text: :cyan, progress_bar: true
#
# @param [String] text the color of the text hint. To turn off use nil or :off. @see API.md
# @param [Boolean] progress_bar enable progress bars on long-running operations
# @return [nil] Returns nothing
# @api public
def hint(text: nil)
def hint(text: nil, progress_bar: false)
text = nil if text == :off
@text_hint = text
@progress_bar.enabled = progress_bar
end
# Sets various defaults for this deck. Defaults can be overriden by the commands themselves