rodf 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,4 @@
1
+ v0.1.2. Cell span
1
2
  v0.1.1. Basic spreadsheet styling support
2
3
  v0.1. First version with very basic support for spreadsheet generation
3
4
 
data/Manifest CHANGED
@@ -1,22 +1,23 @@
1
- lib/odf/row.rb
2
- lib/odf/spreadsheet.rb
1
+ CHANGELOG
2
+ LICENSE.LGPL
3
+ Manifest
4
+ README.rdoc
5
+ Rakefile
3
6
  lib/odf/cell.rb
4
7
  lib/odf/column.rb
5
- lib/odf/table.rb
8
+ lib/odf/container.rb
6
9
  lib/odf/property.rb
7
- lib/odf/style.rb
10
+ lib/odf/row.rb
8
11
  lib/odf/skeleton/manifest.xml
9
12
  lib/odf/skeleton/styles.xml
10
- lib/odf/container.rb
11
- CHANGELOG
12
- README.rdoc
13
- Rakefile
14
- LICENSE.LGPL
13
+ lib/odf/spreadsheet.rb
14
+ lib/odf/style.rb
15
+ lib/odf/table.rb
16
+ rodf.gemspec
15
17
  spec/cell_spec.rb
16
- spec/spreadsheet_spec.rb
17
- spec/spec_helper.rb
18
+ spec/property_spec.rb
18
19
  spec/row_spec.rb
19
- spec/table_spec.rb
20
+ spec/spec_helper.rb
21
+ spec/spreadsheet_spec.rb
20
22
  spec/style_spec.rb
21
- spec/property_spec.rb
22
- Manifest
23
+ spec/table_spec.rb
@@ -28,12 +28,16 @@ module ODF
28
28
  @value = value.to_s.strip unless value.instance_of? Hash
29
29
 
30
30
  @elem_attrs = make_element_attributes(@type, @value, opts)
31
+ @mutiply = (opts[:span] || 1).to_i
31
32
  end
32
33
 
33
34
  def xml
34
- Builder::XmlMarkup.new.tag! 'table:table-cell', @elem_attrs do |xml|
35
+ markup = Builder::XmlMarkup.new
36
+ text = markup.tag! 'table:table-cell', @elem_attrs do |xml|
35
37
  xml.text(:p, @value) if contains_string?
36
38
  end
39
+ (@mutiply - 1).times {text = markup.tag! 'table:table-cell'}
40
+ text
37
41
  end
38
42
 
39
43
  def contains_string?
@@ -45,6 +49,7 @@ module ODF
45
49
  attrs['office:value'] = value unless contains_string?
46
50
  attrs['table:formula'] = opts[:formula] unless opts[:formula].nil?
47
51
  attrs['table:style-name'] = opts[:style] unless opts[:style].nil?
52
+ attrs['table:number-columns-spanned'] = opts[:span] unless opts[:span].nil?
48
53
  attrs['table:number-matrix-columns-spanned'] =
49
54
  attrs['table:number-matrix-rows-spanned'] = 1 if opts[:matrix_formula]
50
55
  attrs
@@ -23,10 +23,11 @@ module ODF
23
23
  PROPERTY_NAMES = {:cell => 'style:table-cell-properties',
24
24
  :text => 'style:text-properties',
25
25
  :column => 'style:table-column-properties'}
26
+ TRANSLATED_SPECS = [:border_color, :border_style, :border_width]
26
27
 
27
28
  def initialize(type, specs={})
28
29
  @name = PROPERTY_NAMES[type]
29
- @specs = specs.map { |k, v| [k.to_s, v] }
30
+ @specs = translate(specs).map { |k, v| [k.to_s, v] }
30
31
  end
31
32
 
32
33
  def xml
@@ -36,6 +37,37 @@ module ODF
36
37
  end
37
38
  Builder::XmlMarkup.new.tag! @name, specs
38
39
  end
40
+ private
41
+ def translate(specs)
42
+ result = specs.clone
43
+ tspecs = specs.select {|k, v| TRANSLATED_SPECS.include? k}
44
+ tspecs.map {|k, v| result.delete k}
45
+ tspecs = tspecs.inject({}) {|acc, e| acc.merge e.first => e.last}
46
+ if tspecs[:border_width] && tspecs[:border_style] && tspecs[:border_color] then
47
+ width = tspecs[:border_width].split
48
+ style = tspecs[:border_style].split
49
+ color = tspecs[:border_color].split
50
+ if width.length == 1 && style.length == 1 && color.length == 1 then
51
+ result[:border] = [width[0], style[0], color[0]].join(' ')
52
+ else
53
+ result['border-top'] = cascading_join(width, style, color, 0)
54
+ result['border-right'] = cascading_join(width, style, color, 1, 0)
55
+ result['border-bottom'] = cascading_join(width, style, color, 2, 0)
56
+ result['border-left'] = cascading_join(width, style, color, 3, 1, 0)
57
+ end
58
+ end
59
+ result
60
+ end
61
+
62
+ def cascading_join(width_parts, style_parts, color_parts, *prefs)
63
+ [ cascade(width_parts, prefs),
64
+ cascade(style_parts, prefs),
65
+ cascade(color_parts, prefs)].join(' ')
66
+ end
67
+
68
+ def cascade(list, prefs)
69
+ prefs.inject(nil) {|acc, i| acc || list[i]}
70
+ end
39
71
  end
40
72
  end
41
73
 
@@ -2,26 +2,25 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rodf}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Thiago Arrais"]
9
- s.date = %q{2008-12-02}
9
+ s.date = %q{2009-10-28}
10
10
  s.description = %q{ODF generation library for Ruby}
11
11
  s.email = %q{thiago.arrais@gmail.com}
12
- s.extra_rdoc_files = ["lib/odf/row.rb", "lib/odf/spreadsheet.rb", "lib/odf/cell.rb", "lib/odf/column.rb", "lib/odf/table.rb", "lib/odf/property.rb", "lib/odf/style.rb", "lib/odf/skeleton/manifest.xml", "lib/odf/skeleton/styles.xml", "lib/odf/container.rb", "CHANGELOG", "README.rdoc", "LICENSE.LGPL"]
13
- s.files = ["lib/odf/row.rb", "lib/odf/spreadsheet.rb", "lib/odf/cell.rb", "lib/odf/column.rb", "lib/odf/table.rb", "lib/odf/property.rb", "lib/odf/style.rb", "lib/odf/skeleton/manifest.xml", "lib/odf/skeleton/styles.xml", "lib/odf/container.rb", "CHANGELOG", "README.rdoc", "Rakefile", "LICENSE.LGPL", "spec/cell_spec.rb", "spec/spreadsheet_spec.rb", "spec/spec_helper.rb", "spec/row_spec.rb", "spec/table_spec.rb", "spec/style_spec.rb", "spec/property_spec.rb", "Manifest", "rodf.gemspec"]
14
- s.has_rdoc = true
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE.LGPL", "README.rdoc", "lib/odf/cell.rb", "lib/odf/column.rb", "lib/odf/container.rb", "lib/odf/property.rb", "lib/odf/row.rb", "lib/odf/skeleton/manifest.xml", "lib/odf/skeleton/styles.xml", "lib/odf/spreadsheet.rb", "lib/odf/style.rb", "lib/odf/table.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE.LGPL", "Manifest", "README.rdoc", "Rakefile", "lib/odf/cell.rb", "lib/odf/column.rb", "lib/odf/container.rb", "lib/odf/property.rb", "lib/odf/row.rb", "lib/odf/skeleton/manifest.xml", "lib/odf/skeleton/styles.xml", "lib/odf/spreadsheet.rb", "lib/odf/style.rb", "lib/odf/table.rb", "rodf.gemspec", "spec/cell_spec.rb", "spec/property_spec.rb", "spec/row_spec.rb", "spec/spec_helper.rb", "spec/spreadsheet_spec.rb", "spec/style_spec.rb", "spec/table_spec.rb"]
15
14
  s.homepage = %q{http://github.com/thiagoarrais/rodf/tree}
16
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rodf", "--main", "README.rdoc"]
17
16
  s.require_paths = ["lib"]
18
17
  s.rubyforge_project = %q{rodf}
19
- s.rubygems_version = %q{1.3.1}
18
+ s.rubygems_version = %q{1.3.5}
20
19
  s.summary = %q{ODF generation library for Ruby}
21
20
 
22
21
  if s.respond_to? :specification_version then
23
22
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
- s.specification_version = 2
23
+ s.specification_version = 3
25
24
 
26
25
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
26
  s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
@@ -88,4 +88,11 @@ describe ODF::Cell do
88
88
  Hpricot(cell.xml).at('table:table-cell')['table:style-name'].
89
89
  should == 'left-column-cell'
90
90
  end
91
+
92
+ it "should span multiple cells when asked to" do
93
+ cell = ODF::Cell.new 'Spreadsheet title', :span => 4
94
+ doc = Hpricot(cell.xml)
95
+ doc.at('table:table-cell')['table:number-columns-spanned'].should == '4'
96
+ doc.search('table:table-cell').size.should == 4
97
+ end
91
98
  end
@@ -35,5 +35,79 @@ describe ODF::Property do
35
35
  elem = Hpricot(property.xml).at('//style:table-column-properties')
36
36
  elem['style:column-width'].should == '2cm'
37
37
  end
38
+
39
+ it "should accept full perimeter border specs" do
40
+ property = ODF::Property.new :cell, :border => "0.025in solid #000000"
41
+
42
+ Hpricot(property.xml).at('//style:table-cell-properties')['fo:border'].
43
+ should == "0.025in solid #000000"
44
+ end
45
+
46
+ it "should accept splited full perimeter border specs" do
47
+ property = ODF::Property.new :cell, :border_width => '0.025in',
48
+ :border_color => '#000000',
49
+ :border_style => 'solid'
50
+
51
+ Hpricot(property.xml).at('//style:table-cell-properties')['fo:border'].
52
+ should == "0.025in solid #000000"
53
+ end
54
+
55
+ it "should use the first value for vertical and second for horizontal border side specs" do
56
+ property = ODF::Property.new :cell, :border_width => '0.025in 0.3in',
57
+ :border_color => '#ff0000 #0000ff',
58
+ :border_style => 'solid'
59
+
60
+ elem= Hpricot(property.xml).at('//style:table-cell-properties')
61
+ elem['fo:border-top'].should == "0.025in solid #ff0000"
62
+ elem['fo:border-right'].should == "0.3in solid #0000ff"
63
+ elem['fo:border-bottom'].should == "0.025in solid #ff0000"
64
+ elem['fo:border-left'].should == "0.3in solid #0000ff"
65
+ end
66
+
67
+ it "should use the third value for bottom border specs when present" do
68
+ property = ODF::Property.new :cell, :border_width => '0.025in 0.3in 0.4in',
69
+ :border_color => '#ff0000 #0000ff',
70
+ :border_style => 'dotted solid solid'
71
+
72
+ elem = Hpricot(property.xml).at('//style:table-cell-properties')
73
+ elem['fo:border-bottom'].should == "0.4in solid #ff0000"
74
+
75
+ property = ODF::Property.new :cell, :border_width => '0.025in',
76
+ :border_color => '#ff0000 #0000ff #00ff00',
77
+ :border_style => 'dotted solid'
78
+
79
+ elem = Hpricot(property.xml).at('//style:table-cell-properties')
80
+ elem['fo:border-bottom'].should == "0.025in dotted #00ff00"
81
+ end
82
+
83
+ it "should cascade left border specs from fourth to second to first" do
84
+ property = ODF::Property.new :cell, :border_width => '0.1in 0.2in 0.3in 0.4in',
85
+ :border_color => '#ff0000 #0000ff #00ff00',
86
+ :border_style => 'dotted solid'
87
+
88
+ elem = Hpricot(property.xml).at('//style:table-cell-properties')
89
+ elem['fo:border-left'].should == "0.4in solid #0000ff"
90
+
91
+ property = ODF::Property.new :cell, :border_width => '0.1in 0.2in 0.3in',
92
+ :border_color => '#ff0000 #0000ff',
93
+ :border_style => 'dotted'
94
+
95
+ elem = Hpricot(property.xml).at('//style:table-cell-properties')
96
+ elem['fo:border-left'].should == "0.2in dotted #0000ff"
97
+
98
+ property = ODF::Property.new :cell, :border_width => '0.1in 0.2in',
99
+ :border_color => '#ff0000',
100
+ :border_style => 'dotted solid dashed double'
101
+
102
+ elem = Hpricot(property.xml).at('//style:table-cell-properties')
103
+ elem['fo:border-left'].should == "0.2in double #ff0000"
104
+
105
+ property = ODF::Property.new :cell, :border_width => '0.1in',
106
+ :border_color => '#ff0000 #0000ff #00ff00 #ffff00',
107
+ :border_style => 'dotted solid dashed'
108
+
109
+ elem = Hpricot(property.xml).at('//style:table-cell-properties')
110
+ elem['fo:border-left'].should == "0.1in solid #ffff00"
111
+ end
38
112
  end
39
113
 
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 2
9
+ version: 0.1.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Thiago Arrais
@@ -9,69 +14,92 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2008-12-02 00:00:00 -03:00
17
+ date: 2009-10-28 00:00:00 -03:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: builder
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 1
30
+ - 2
23
31
  version: 2.1.2
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: rubyzip
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 9
44
+ - 1
33
45
  version: 0.9.1
34
- version:
46
+ type: :runtime
47
+ version_requirements: *id002
35
48
  - !ruby/object:Gem::Dependency
36
49
  name: activesupport
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
40
52
  requirements:
41
53
  - - "="
42
54
  - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 1
58
+ - 2
43
59
  version: 2.1.2
44
- version:
60
+ type: :runtime
61
+ version_requirements: *id003
45
62
  - !ruby/object:Gem::Dependency
46
63
  name: rspec
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
50
66
  requirements:
51
67
  - - ">="
52
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 1
72
+ - 11
53
73
  version: 1.1.11
54
- version:
74
+ type: :development
75
+ version_requirements: *id004
55
76
  - !ruby/object:Gem::Dependency
56
77
  name: rspec_hpricot_matchers
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
60
80
  requirements:
61
81
  - - ">="
62
82
  - !ruby/object:Gem::Version
83
+ segments:
84
+ - 1
85
+ - 0
63
86
  version: "1.0"
64
- version:
87
+ type: :development
88
+ version_requirements: *id005
65
89
  - !ruby/object:Gem::Dependency
66
90
  name: echoe
67
- type: :development
68
- version_requirement:
69
- version_requirements: !ruby/object:Gem::Requirement
91
+ prerelease: false
92
+ requirement: &id006 !ruby/object:Gem::Requirement
70
93
  requirements:
71
94
  - - ">="
72
95
  - !ruby/object:Gem::Version
96
+ segments:
97
+ - 3
98
+ - 0
99
+ - 2
73
100
  version: 3.0.2
74
- version:
101
+ type: :development
102
+ version_requirements: *id006
75
103
  description: ODF generation library for Ruby
76
104
  email: thiago.arrais@gmail.com
77
105
  executables: []
@@ -79,45 +107,47 @@ executables: []
79
107
  extensions: []
80
108
 
81
109
  extra_rdoc_files:
82
- - lib/odf/row.rb
83
- - lib/odf/spreadsheet.rb
110
+ - CHANGELOG
111
+ - LICENSE.LGPL
112
+ - README.rdoc
84
113
  - lib/odf/cell.rb
85
114
  - lib/odf/column.rb
86
- - lib/odf/table.rb
115
+ - lib/odf/container.rb
87
116
  - lib/odf/property.rb
88
- - lib/odf/style.rb
117
+ - lib/odf/row.rb
89
118
  - lib/odf/skeleton/manifest.xml
90
119
  - lib/odf/skeleton/styles.xml
91
- - lib/odf/container.rb
120
+ - lib/odf/spreadsheet.rb
121
+ - lib/odf/style.rb
122
+ - lib/odf/table.rb
123
+ files:
92
124
  - CHANGELOG
93
- - README.rdoc
94
125
  - LICENSE.LGPL
95
- files:
96
- - lib/odf/row.rb
97
- - lib/odf/spreadsheet.rb
126
+ - Manifest
127
+ - README.rdoc
128
+ - Rakefile
98
129
  - lib/odf/cell.rb
99
130
  - lib/odf/column.rb
100
- - lib/odf/table.rb
131
+ - lib/odf/container.rb
101
132
  - lib/odf/property.rb
102
- - lib/odf/style.rb
133
+ - lib/odf/row.rb
103
134
  - lib/odf/skeleton/manifest.xml
104
135
  - lib/odf/skeleton/styles.xml
105
- - lib/odf/container.rb
106
- - CHANGELOG
107
- - README.rdoc
108
- - Rakefile
109
- - LICENSE.LGPL
136
+ - lib/odf/spreadsheet.rb
137
+ - lib/odf/style.rb
138
+ - lib/odf/table.rb
139
+ - rodf.gemspec
110
140
  - spec/cell_spec.rb
111
- - spec/spreadsheet_spec.rb
112
- - spec/spec_helper.rb
141
+ - spec/property_spec.rb
113
142
  - spec/row_spec.rb
114
- - spec/table_spec.rb
143
+ - spec/spec_helper.rb
144
+ - spec/spreadsheet_spec.rb
115
145
  - spec/style_spec.rb
116
- - spec/property_spec.rb
117
- - Manifest
118
- - rodf.gemspec
146
+ - spec/table_spec.rb
119
147
  has_rdoc: true
120
148
  homepage: http://github.com/thiagoarrais/rodf/tree
149
+ licenses: []
150
+
121
151
  post_install_message:
122
152
  rdoc_options:
123
153
  - --line-numbers
@@ -132,20 +162,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
162
  requirements:
133
163
  - - ">="
134
164
  - !ruby/object:Gem::Version
165
+ segments:
166
+ - 0
135
167
  version: "0"
136
- version:
137
168
  required_rubygems_version: !ruby/object:Gem::Requirement
138
169
  requirements:
139
170
  - - ">="
140
171
  - !ruby/object:Gem::Version
172
+ segments:
173
+ - 1
174
+ - 2
141
175
  version: "1.2"
142
- version:
143
176
  requirements: []
144
177
 
145
178
  rubyforge_project: rodf
146
- rubygems_version: 1.3.1
179
+ rubygems_version: 1.3.6
147
180
  signing_key:
148
- specification_version: 2
181
+ specification_version: 3
149
182
  summary: ODF generation library for Ruby
150
183
  test_files: []
151
184