Browse Source

Hinting is set to off, not nil. Some more tests

dev
Andy Meneely 12 years ago
parent
commit
a643cf8025
  1. 2
      README.md
  2. 5
      lib/squib/api/settings.rb
  3. 3
      lib/squib/constants.rb
  4. 1
      lib/squib/graphics/image.rb
  5. 2
      lib/squib/graphics/text.rb
  6. 13
      lib/squib/input_helpers.rb
  7. 2
      samples/text_options.rb
  8. 29
      spec/input_helpers_spec.rb

2
README.md

@ -183,7 +183,7 @@ Squib supports various configuration properties that can be specified in an exte
* `progress_bars` (Boolean, default: false). When set to `true`, long-running operations will show a progress bar on the command line. * `progress_bars` (Boolean, default: false). When set to `true`, long-running operations will show a progress bar on the command line.
* `dpi` (Integer, default: 300). Used in calculations when units are used (e.g. for PDF rendering and unit conversion). * `dpi` (Integer, default: 300). Used in calculations when units are used (e.g. for PDF rendering and unit conversion).
* `hint` (ColorString, default: nil). Text hints are used to show the boundaries of text boxes. Can be enabled/disabled for individual commands, or set globally with the `set` command. This setting is overriden by `set` and individual commands. * `hint` (ColorString, default: off). Text hints are used to show the boundaries of text boxes. Can be enabled/disabled for individual commands, or set globally with the `set` command. This setting is overriden by `set` and individual commands.
* `custom_colors` (Hash of Colors, default: {}). Defines globally-available colors available to the deck that can be specified in commands. * `custom_colors` (Hash of Colors, default: {}). Defines globally-available colors available to the deck that can be specified in commands.
The following sample demonstrates the config file. The following sample demonstrates the config file.

5
lib/squib/api/settings.rb

@ -9,12 +9,11 @@ module Squib
# hint text: :cyan # hint text: :cyan
# hint text: :cyan, progress_bar: true # hint text: :cyan, progress_bar: true
# #
# @param [String] text the color of the text hint. To turn off use nil or :off. @see README.md # @param [String] text the color of the text hint. To turn off use :off. @see README.md
# @param [Boolean] progress_bar enable progress bars on long-running operations # @param [Boolean] progress_bar enable progress bars on long-running operations
# @return [nil] Returns nothing # @return [nil] Returns nothing
# @api public # @api public
def hint(text: nil) def hint(text: :off)
text = nil if text == :off
@text_hint = text @text_hint = text
end end

3
lib/squib/constants.rb

@ -16,6 +16,7 @@ module Squib
:format => :png, :format => :png,
:gap => 0, :gap => 0,
:height => :native, :height => :native,
:hint => :off,
:justify => false, :justify => false,
:margin => 75, :margin => 75,
:markup => false, :markup => false,
@ -50,7 +51,7 @@ module Squib
CONFIG_DEFAULTS = { CONFIG_DEFAULTS = {
'custom_colors' => {}, 'custom_colors' => {},
'dpi' => 300, 'dpi' => 300,
'hint' => nil, 'hint' => :none,
'progress_bar' => false, 'progress_bar' => false,
} }

1
lib/squib/graphics/image.rb

@ -27,6 +27,7 @@ module Squib
# :nodoc: # :nodoc:
# @api private # @api private
def svg(file, id, x, y, width, height, alpha, blend) def svg(file, id, x, y, width, height, alpha, blend)
Squib.logger.debug {"Rendering: #{file}, #{id} #{x}, #{y}, #{width}, #{height}, #{alpha}, #{blend}"}
return if file.nil? or file.eql? '' return if file.nil? or file.eql? ''
svg = RSVG::Handle.new_from_file(file) svg = RSVG::Handle.new_from_file(file)
width = svg.width if width == :native width = svg.width if width == :native

2
lib/squib/graphics/text.rb

@ -6,8 +6,8 @@ module Squib
# :nodoc: # :nodoc:
# @api private # @api private
def draw_text_hint(x,y,layout, color) def draw_text_hint(x,y,layout, color)
return if color.nil? && @deck.text_hint.nil?
color ||= @deck.text_hint color ||= @deck.text_hint
return if color.to_s.eql? 'off'
# when w,h < 0, it was never set. extents[1] are ink extents # when w,h < 0, it was never set. extents[1] are ink extents
w = layout.width / Pango::SCALE w = layout.width / Pango::SCALE
w = layout.extents[1].width / Pango::SCALE if w < 0 w = layout.extents[1].width / Pango::SCALE if w < 0

13
lib/squib/input_helpers.rb

@ -8,11 +8,10 @@ module Squib
# :nodoc: # :nodoc:
# @api private # @api private
def needs(opts, params) def needs(opts, params)
Squib.logger.debug {"Pre input-helper opts: #{opts}"} Squib.logger.debug {"Given opts: #{opts}"}
opts = layoutify(opts) if params.include? :layout opts = layoutify(opts) if params.include? :layout
opts = Squib::SYSTEM_DEFAULTS.merge(opts) opts = Squib::SYSTEM_DEFAULTS.merge(opts)
opts = expand_singletons(opts, params) opts = expand_singletons(opts, params)
Squib.logger.debug {"Post expand opts: #{opts}"}
opts = rangeify(opts) if params.include? :range opts = rangeify(opts) if params.include? :range
opts = fileify(opts) if params.include? :file opts = fileify(opts) if params.include? :file
opts = fileify(opts, false) if params.include? :file_to_save opts = fileify(opts, false) if params.include? :file_to_save
@ -40,6 +39,7 @@ module Squib
end end
end end
end end
Squib.logger.debug {"After expand_singletons: #{opts}"}
opts opts
end end
module_function :expand_singletons module_function :expand_singletons
@ -56,13 +56,15 @@ module Squib
entry = @layout[layout.to_s] entry = @layout[layout.to_s]
unless entry.nil? unless entry.nil?
entry.each do |key, value| entry.each do |key, value|
opts[key.to_sym] ||= entry[key] opts[key.to_sym] = [] if opts[key.to_sym].nil?
opts[key.to_sym][i] ||= entry[key] #don't override if it's already there
end end
else else
Squib.logger.warn ("Layout entry '#{layout}' does not exist." ) Squib.logger.warn ("Layout entry '#{layout}' does not exist." )
end end
end end
end end
Squib.logger.debug {"After layoutify: #{opts}"}
opts opts
end end
module_function :layoutify module_function :layoutify
@ -86,6 +88,7 @@ module Squib
raise ArgumentError.new("#{range} is outside of deck range of 0..#{@cards.size-1}") raise ArgumentError.new("#{range} is outside of deck range of 0..#{@cards.size-1}")
end end
opts[:range] = range opts[:range] = range
Squib.logger.debug {"After rangeify: #{opts}"}
opts opts
end end
module_function :rangeify module_function :rangeify
@ -127,6 +130,7 @@ module Squib
opts[key][i] = Cairo::Color.parse(color) opts[key][i] = Cairo::Color.parse(color)
end end
end end
Squib.logger.debug {"After colorify: #{opts}"}
opts opts
end end
module_function :colorify module_function :colorify
@ -138,6 +142,7 @@ module Squib
opts[:font][i] = @font if font==:use_set opts[:font][i] = @font if font==:use_set
opts[:font][i] = Squib::SYSTEM_DEFAULTS[:default_font] if font == :default opts[:font][i] = Squib::SYSTEM_DEFAULTS[:default_font] if font == :default
end end
Squib.logger.debug {"After fontify: #{opts}"}
opts opts
end end
module_function :fontify module_function :fontify
@ -151,6 +156,7 @@ module Squib
opts[:y_radius][i] = radius opts[:y_radius][i] = radius
end end
end end
Squib.logger.debug {"After radiusify: #{opts}"}
opts opts
end end
module_function :radiusify module_function :radiusify
@ -163,6 +169,7 @@ module Squib
opts[:id][i] = '#' << id unless id.start_with? '#' opts[:id][i] = '#' << id unless id.start_with? '#'
end end
end end
Squib.logger.debug {"After svgidify: #{opts}"}
opts opts
end end
module_function :svgidify module_function :svgidify

2
samples/text_options.rb

@ -39,7 +39,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
text str: "Text hints are also globally togglable!", text str: "Text hints are also globally togglable!",
x: 65, y: 625, x: 65, y: 625,
font: 'Arial 22' font: 'Arial 22'
hint text: nil hint text: :off
text str: "See? No hint here.", text str: "See? No hint here.",
x: 565, y: 625, x: 565, y: 625,
font: 'Arial 22' font: 'Arial 22'

29
spec/input_helpers_spec.rb

@ -18,29 +18,46 @@ describe Squib::InputHelpers do
before(:each) do before(:each) do
@deck = DummyDeck.new @deck = DummyDeck.new
@deck.layout = {'blah' => {x: 25}} @deck.layout = {
'blah' => {x: 25},
'apples' => {x: 35},
'oranges' => {y: 45},
}
@deck.cards = %w(a b) @deck.cards = %w(a b)
@deck.custom_colors = {} @deck.custom_colors = {}
end end
context '#layoutify' do context '#layoutify' do
it "should warn on the logger when the layout doesn't exist" do it "warns on the logger when the layout doesn't exist" do
@old_logger = Squib.logger @old_logger = Squib.logger
Squib.logger = instance_double(Logger) Squib.logger = instance_double(Logger)
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice
expect(Squib.logger).to receive(:debug)
expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]}) expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]})
Squib.logger = @old_logger Squib.logger = @old_logger
end end
it "should apply the layout in a normal situation" do it "applies the layout in a normal situation" do
expect(@deck.send(:layoutify, {layout: :blah})).to \ expect(@deck.send(:layoutify, {layout: :blah})).to \
eq({layout: [:blah, :blah], x: 25}) eq({layout: [:blah, :blah], x: [25, 25]})
end end
it "also look up based on strings" do it "applies two different layouts for two different situations" do
expect(@deck.send(:layoutify, {layout: ['blah', 'apples']})).to \
eq({layout: ['blah','apples'], x: [25, 35]})
end
it "still has nils when not applied two different layouts differ in structure" do
expect(@deck.send(:layoutify, {layout: ['apples', 'oranges']})).to \
eq({layout: ['apples','oranges'], x: [35], y: [nil, 45]})
#...this might behavior that is hard to debug for users. Trying to come up with a warning or something...
end
it "also looks up based on strings" do
expect(@deck.send(:layoutify, {layout: 'blah'})).to \ expect(@deck.send(:layoutify, {layout: 'blah'})).to \
eq({layout: ['blah','blah'], x: 25}) eq({layout: ['blah','blah'], x: [25, 25]})
end end
end end
context '#rangeify' do context '#rangeify' do

Loading…
Cancel
Save