From 71859909ed45618cd57ec82bb6781f062d188b6d Mon Sep 17 00:00:00 2001 From: Scott Date: Thu, 5 Apr 2012 13:43:01 -0400 Subject: Removed rake 0.8.7 dependency specific to ruby 1.9.2, as it didn't seem to break anything without it Made border definitions access instead of delete hash params, as calling it from within a loop without cloning the style hash was causing it to be empty on subsequent loops. Didn't see any reason to be deleting them. Added :edges param to :border hash to specify [:top,:bottom], etc. If it's absent, defaults to all edges. --- axlsx.gemspec | 2 +- lib/axlsx/stylesheet/styles.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/axlsx.gemspec b/axlsx.gemspec index ae3d2aaa..3aa66863 100644 --- a/axlsx.gemspec +++ b/axlsx.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'rmagick4j', '>= 0.3.7' if Object.const_defined? :JRUBY_VERSION s.add_runtime_dependency 'rubyzip', '>= 0.9.5' - s.add_runtime_dependency 'rake', '0.8.7' if RUBY_VERSION == "1.9.2" +# s.add_runtime_dependency 'rake', '0.8.7' if RUBY_VERSION == "1.9.2" s.add_runtime_dependency 'rake', '>= 0.8.7' if ["1.9.3", "1.8.7"].include?(RUBY_VERSION) s.add_development_dependency 'yard' # s.add_development_dependency 'rdiscount' diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index 1fb2e9b3..cd8c7139 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -204,10 +204,12 @@ module Axlsx if borderId.is_a?(Hash) raise ArgumentError, "border hash definitions must include both style and color" unless borderId.keys.include?(:style) && borderId.keys.include?(:color) - s = borderId.delete :style - c = borderId.delete :color + s = borderId[:style] + c = borderId[:color] + edges = borderId[:edges] || [:left, :right, :top, :bottom] + border = Border.new - [:left, :right, :top, :bottom].each {|pr| border.prs << BorderPr.new(:name => pr, :style=>s, :color => Color.new(:rgb => c))} + edges.each {|pr| border.prs << BorderPr.new(:name => pr, :style=>s, :color => Color.new(:rgb => c))} borderId = self.borders << border end -- cgit v1.2.3 From 89f5b16ae10295e93cd976bc79eec3b8e5902cb8 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 6 Apr 2012 07:27:29 -0400 Subject: Add edges() to border to return list of applied edges Add border edge tests to styles spec --- lib/axlsx/stylesheet/border.rb | 7 +++++++ test/stylesheet/tc_styles.rb | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/axlsx/stylesheet/border.rb b/lib/axlsx/stylesheet/border.rb index d23e5476..60b89b6f 100644 --- a/lib/axlsx/stylesheet/border.rb +++ b/lib/axlsx/stylesheet/border.rb @@ -35,6 +35,13 @@ module Axlsx end end + # Return list of edge names applied to this border + def edges + edges = [] + @prs.each {|pr| edges << pr.name} + edges + end + # @see diagonalUp def diagonalUp=(v) Axlsx::validate_boolean v; @diagonalUp = v end # @see diagonalDown diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb index ef14e151..42c64eee 100644 --- a/test/stylesheet/tc_styles.rb +++ b/test/stylesheet/tc_styles.rb @@ -23,7 +23,15 @@ class TestStyles < Test::Unit::TestCase assert_equal(@styles.borders.size, border_count + 1) assert_equal(@styles.borders.last.prs.last.color.rgb, "FFFF0000") assert_raise(ArgumentError) { @styles.add_style :border => {:color => "FFFF0000"} } + [:top,:bottom,:left,:right].each {|edge| assert(@styles.borders.last.edges.include?(edge))} + s2 = @styles.add_style :border => {:style=>:thin, :color => "0000FFFF", :edges => [:top, :bottom]} + assert_equal(@styles.borders.size, border_count + 2) + assert_equal(@styles.borders.last.prs.last.color.rgb, "0000FFFF") + assert(@styles.borders.last.edges.include?(:top)) + assert(@styles.borders.last.edges.include?(:bottom)) + assert(! @styles.borders.last.edges.include?(:left)) + assert(! @styles.borders.last.edges.include?(:right)) end def test_add_style -- cgit v1.2.3