Browse Source

Suppressing progress bar output and getting hints to work

dev
Andy Meneely 12 years ago
parent
commit
202b4c4235
  1. 4
      lib/squib/deck.rb
  2. 14
      lib/squib/progress.rb
  3. 11
      lib/squib/project_template/config.yml
  4. 4
      samples/custom-config.yml
  5. 2
      samples/custom_config.rb
  6. 16
      spec/samples_run_spec.rb
  7. 3
      spec/spec_helper.rb

4
lib/squib/deck.rb

@ -86,8 +86,8 @@ module Squib
if File.exists?(file) && config = YAML.load_file(file) if File.exists?(file) && config = YAML.load_file(file)
config = Squib::CONFIG_DEFAULTS.merge(config) config = Squib::CONFIG_DEFAULTS.merge(config)
@dpi = config['dpi'].to_i @dpi = config['dpi'].to_i
@hint = config['hint'] @text_hint = config['text_hint']
@progress_bar.enabled = config['progress_bar'] @progress_bar.enabled = config['progress_bars']
end end
end end

14
lib/squib/progress.rb

@ -1,6 +1,13 @@
require 'ruby-progressbar' require 'ruby-progressbar'
module Squib module Squib
class DoNothing
def increment
#do nothing!
end
end
# A facade that handles (or doesn't) the progress bar on the console # A facade that handles (or doesn't) the progress bar on the console
# #
# :nodoc: # :nodoc:
@ -13,12 +20,15 @@ module Squib
end end
def start(title="", total=100, &block) def start(title="", total=100, &block)
if @enabled if @enabled && !(ENV['IN_TEST'].eql? "true")
@bar = ProgressBar.create(title: title, total: total, format: '%t <%B> %p%% %a') @bar = ProgressBar.create(title: title, total: total, format: '%t <%B> %p%% %a')
yield(@bar) yield(@bar)
@bar.finish @bar.finish
else
yield(Squib::DoNothing.new)
end end
end end
end end
end end

11
lib/squib/project_template/config.yml

@ -1,2 +1,11 @@
# Settings in the config.yml are overriding Squib's defaults. Anything in the main script will override this. # Settings in the config.yml are overriding Squib's defaults. Anything in the main script will override this.
#dpi: 72
# DPI is used in making PDFs and in unit conversions
#dpi: 72
# Text hints are used to show the boundaries of text boxes.
# Can be enabled/disabled at the command-level, or set globally with `set`
#text_hint: '#F00'
# Show progress bars on the command line for potentially long-running operations
#progress_bars: true

4
samples/custom-config.yml

@ -1,3 +1,3 @@
dpi: 300 dpi: 300
progress_bar: true progress_bars: true
hint: '#FF0000' text_hint: '#FF0000'

2
samples/custom_config.rb

@ -4,7 +4,7 @@ require 'squib'
Squib::Deck.new(config: 'custom-config.yml') do Squib::Deck.new(config: 'custom-config.yml') do
# Hints are turned on in the config file # Hints are turned on in the config file
text str: "The Title", x: 0, y: 78, width: 750, text str: "The Title", x: 0, y: 78, width: 825,
font: 'Arial 72', align: :center font: 'Arial 72', align: :center
# Progress bars are shown for these commands # Progress bars are shown for these commands

16
spec/samples_run_spec.rb

@ -3,13 +3,17 @@ require 'squib'
describe Squib do describe Squib do
it "should execute all examples with no errors" do context "all samples" do
samples = File.expand_path('../samples', File.dirname(__FILE__))
Dir["#{samples}/**/*.rb"].each do |sample| it "should execute with no errors" do
Dir.chdir(samples) do #to save to _output samples = File.expand_path('../samples', File.dirname(__FILE__))
require_relative "../samples/#{File.basename(sample)}" Dir["#{samples}/**/*.rb"].each do |sample|
Dir.chdir(samples) do #to save to _output
require_relative "../samples/#{File.basename(sample)}"
end
end end
end end
end
end
end end

3
spec/spec_helper.rb

@ -1,9 +1,10 @@
require 'simplecov' require 'simplecov'
require 'coveralls' require 'coveralls'
ENV['IN_TEST']="true"
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter Coveralls::SimpleCov::Formatter
] ]
SimpleCov.start SimpleCov.start

Loading…
Cancel
Save