diff --git a/README.md b/README.md index f1ee379..6b91aef 100644 --- a/README.md +++ b/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. * `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. The following sample demonstrates the config file. diff --git a/lib/squib/api/settings.rb b/lib/squib/api/settings.rb index 621ecdc..9461aab 100644 --- a/lib/squib/api/settings.rb +++ b/lib/squib/api/settings.rb @@ -9,12 +9,11 @@ module Squib # 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 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 # @return [nil] Returns nothing # @api public - def hint(text: nil) - text = nil if text == :off + def hint(text: :off) @text_hint = text end diff --git a/lib/squib/constants.rb b/lib/squib/constants.rb index c7858cc..e8b505b 100644 --- a/lib/squib/constants.rb +++ b/lib/squib/constants.rb @@ -16,6 +16,7 @@ module Squib :format => :png, :gap => 0, :height => :native, + :hint => :off, :justify => false, :margin => 75, :markup => false, @@ -50,7 +51,7 @@ module Squib CONFIG_DEFAULTS = { 'custom_colors' => {}, 'dpi' => 300, - 'hint' => nil, + 'hint' => :none, 'progress_bar' => false, } diff --git a/lib/squib/graphics/image.rb b/lib/squib/graphics/image.rb index 465f0e0..07d267b 100644 --- a/lib/squib/graphics/image.rb +++ b/lib/squib/graphics/image.rb @@ -27,6 +27,7 @@ module Squib # :nodoc: # @api private 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? '' svg = RSVG::Handle.new_from_file(file) width = svg.width if width == :native diff --git a/lib/squib/graphics/text.rb b/lib/squib/graphics/text.rb index d178d1a..59225ba 100644 --- a/lib/squib/graphics/text.rb +++ b/lib/squib/graphics/text.rb @@ -6,8 +6,8 @@ module Squib # :nodoc: # @api private def draw_text_hint(x,y,layout, color) - return if color.nil? && @deck.text_hint.nil? color ||= @deck.text_hint + return if color.to_s.eql? 'off' # when w,h < 0, it was never set. extents[1] are ink extents w = layout.width / Pango::SCALE w = layout.extents[1].width / Pango::SCALE if w < 0 diff --git a/lib/squib/input_helpers.rb b/lib/squib/input_helpers.rb index 711e407..fdaee21 100644 --- a/lib/squib/input_helpers.rb +++ b/lib/squib/input_helpers.rb @@ -8,11 +8,10 @@ module Squib # :nodoc: # @api private 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 = Squib::SYSTEM_DEFAULTS.merge(opts) opts = expand_singletons(opts, params) - Squib.logger.debug {"Post expand opts: #{opts}"} opts = rangeify(opts) if params.include? :range opts = fileify(opts) if params.include? :file opts = fileify(opts, false) if params.include? :file_to_save @@ -40,6 +39,7 @@ module Squib end end end + Squib.logger.debug {"After expand_singletons: #{opts}"} opts end module_function :expand_singletons @@ -56,13 +56,15 @@ module Squib entry = @layout[layout.to_s] unless entry.nil? 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 else Squib.logger.warn ("Layout entry '#{layout}' does not exist." ) end end end + Squib.logger.debug {"After layoutify: #{opts}"} opts end module_function :layoutify @@ -86,6 +88,7 @@ module Squib raise ArgumentError.new("#{range} is outside of deck range of 0..#{@cards.size-1}") end opts[:range] = range + Squib.logger.debug {"After rangeify: #{opts}"} opts end module_function :rangeify @@ -127,6 +130,7 @@ module Squib opts[key][i] = Cairo::Color.parse(color) end end + Squib.logger.debug {"After colorify: #{opts}"} opts end module_function :colorify @@ -138,6 +142,7 @@ module Squib opts[:font][i] = @font if font==:use_set opts[:font][i] = Squib::SYSTEM_DEFAULTS[:default_font] if font == :default end + Squib.logger.debug {"After fontify: #{opts}"} opts end module_function :fontify @@ -151,6 +156,7 @@ module Squib opts[:y_radius][i] = radius end end + Squib.logger.debug {"After radiusify: #{opts}"} opts end module_function :radiusify @@ -163,6 +169,7 @@ module Squib opts[:id][i] = '#' << id unless id.start_with? '#' end end + Squib.logger.debug {"After svgidify: #{opts}"} opts end module_function :svgidify diff --git a/samples/text_options.rb b/samples/text_options.rb index 509fafd..2de7984 100644 --- a/samples/text_options.rb +++ b/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!", x: 65, y: 625, font: 'Arial 22' - hint text: nil + hint text: :off text str: "See? No hint here.", x: 565, y: 625, font: 'Arial 22' diff --git a/spec/input_helpers_spec.rb b/spec/input_helpers_spec.rb index f4eee62..32bde75 100644 --- a/spec/input_helpers_spec.rb +++ b/spec/input_helpers_spec.rb @@ -18,29 +18,46 @@ describe Squib::InputHelpers do before(:each) do @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.custom_colors = {} end 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 Squib.logger = instance_double(Logger) 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]}) Squib.logger = @old_logger 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 \ - eq({layout: [:blah, :blah], x: 25}) + eq({layout: [:blah, :blah], x: [25, 25]}) 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 \ - eq({layout: ['blah','blah'], x: 25}) + eq({layout: ['blah','blah'], x: [25, 25]}) end + end context '#rangeify' do