summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-04-09 02:17:42 -0700
committerRandy Morgan <[email protected]>2012-04-09 02:17:42 -0700
commitcbd73fd925b764e36d031a2b28131854d6d6d588 (patch)
treea62f4b690c4c30fc9a2d207876895bfe07d3ec29
parentff5d690f8c3ac8fcab2f9c21d5ddeb699cf0e5ef (diff)
parent89f5b16ae10295e93cd976bc79eec3b8e5902cb8 (diff)
downloadcaxlsx-cbd73fd925b764e36d031a2b28131854d6d6d588.tar.gz
caxlsx-cbd73fd925b764e36d031a2b28131854d6d6d588.zip
Merge pull request #77 from moskrin/master
Added ability to specify border edges. ie, border:{edges:[:top,:bottom],style: :thin, color: '00'}
-rw-r--r--axlsx.gemspec2
-rw-r--r--lib/axlsx/stylesheet/border.rb7
-rw-r--r--lib/axlsx/stylesheet/styles.rb8
-rw-r--r--test/stylesheet/tc_styles.rb8
4 files changed, 21 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/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/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
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