rodf 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/README.rdoc +26 -1
- data/lib/odf/document.rb +9 -6
- data/lib/odf/property.rb +1 -0
- data/lib/odf/row.rb +6 -2
- data/lib/odf/style.rb +1 -1
- data/rodf.gemspec +3 -3
- data/spec/property_spec.rb +6 -0
- data/spec/row_spec.rb +15 -0
- data/spec/style_spec.rb +7 -0
- metadata +45 -15
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -70,4 +70,29 @@ Some basic conditional formatting is also possible:
|
|
70
70
|
row {cell '0', :type => :float, :style => 'cond1' }
|
71
71
|
row {cell '5', :type => :float, :style => 'cond1' }
|
72
72
|
end
|
73
|
-
end
|
73
|
+
end
|
74
|
+
|
75
|
+
==== Procedural style
|
76
|
+
|
77
|
+
The declarative style shown above is just syntatic sugar. A more procedural
|
78
|
+
style can also be used. Like so:
|
79
|
+
|
80
|
+
require 'odf/spreadsheet'
|
81
|
+
|
82
|
+
ss = ODF::Spreadsheet.new
|
83
|
+
t = ss.table 'My first table from Ruby'
|
84
|
+
r = t.row
|
85
|
+
c = r.cell 'Hello, rODF world!'
|
86
|
+
|
87
|
+
ss.write_to 'my-spreadsheet.ods'
|
88
|
+
|
89
|
+
Both styles can be mixed and matched at will:
|
90
|
+
|
91
|
+
require 'odf/spreadsheet'
|
92
|
+
|
93
|
+
ss = ODF::Spreadsheet.new
|
94
|
+
ss.table 'My first table from Ruby' do
|
95
|
+
row { cell 'Hello, rODF world!' }
|
96
|
+
end
|
97
|
+
|
98
|
+
ss.write_to 'my-spreadsheet.ods'
|
data/lib/odf/document.rb
CHANGED
@@ -28,17 +28,20 @@ module ODF
|
|
28
28
|
contains :styles, :default_styles, :office_styles
|
29
29
|
|
30
30
|
def self.file(ods_file_name, &contents)
|
31
|
-
ods_file = Zip::ZipFile.open(ods_file_name, Zip::ZipFile::CREATE)
|
32
|
-
ods_file.get_output_stream('META-INF/manifest.xml') {|f| f << skeleton.manifest(doc_type) }
|
33
|
-
|
34
31
|
(doc = new).instance_eval(&contents)
|
32
|
+
doc.write_to ods_file_name
|
33
|
+
end
|
34
|
+
|
35
|
+
def write_to(ods_file_name)
|
36
|
+
ods_file = Zip::ZipFile.open(ods_file_name, Zip::ZipFile::CREATE)
|
37
|
+
ods_file.get_output_stream('META-INF/manifest.xml') {|f| f << self.class.skeleton.manifest(self.class.doc_type) }
|
35
38
|
|
36
39
|
ods_file.get_output_stream('styles.xml') do |f|
|
37
|
-
f << skeleton.styles
|
38
|
-
f <<
|
40
|
+
f << self.class.skeleton.styles
|
41
|
+
f << self.office_styles_xml unless self.office_styles.empty?
|
39
42
|
f << "</office:styles> </office:document-styles>"
|
40
43
|
end
|
41
|
-
ods_file.get_output_stream('content.xml') {|f| f <<
|
44
|
+
ods_file.get_output_stream('content.xml') {|f| f << self.xml}
|
42
45
|
|
43
46
|
ods_file.close
|
44
47
|
end
|
data/lib/odf/property.rb
CHANGED
@@ -23,6 +23,7 @@ module ODF
|
|
23
23
|
PROPERTY_NAMES = {:cell => 'table-cell-properties',
|
24
24
|
:text => 'text-properties',
|
25
25
|
:column => 'table-column-properties',
|
26
|
+
:row => 'table-row-properties',
|
26
27
|
:conditional => 'map'}
|
27
28
|
TRANSLATED_SPECS = [:border_color, :border_style, :border_width]
|
28
29
|
STYLE_ATTRIBUTES = ['column-width', 'rotation-angle', 'text-underline-type',
|
data/lib/odf/row.rb
CHANGED
@@ -25,13 +25,17 @@ module ODF
|
|
25
25
|
class Row < Container
|
26
26
|
contains :cells
|
27
27
|
attr_reader :number
|
28
|
+
attr_writer :style
|
28
29
|
|
29
|
-
def initialize(number=0)
|
30
|
+
def initialize(number=0, opts={})
|
30
31
|
@number = number
|
32
|
+
@style = opts[:style]
|
31
33
|
end
|
32
34
|
|
33
35
|
def xml
|
34
|
-
|
36
|
+
elem_attrs = {}
|
37
|
+
elem_attrs['table:style-name'] = @style unless @style.nil?
|
38
|
+
Builder::XmlMarkup.new.tag! 'table:table-row', elem_attrs do |xml|
|
35
39
|
xml << cells_xml
|
36
40
|
end
|
37
41
|
end
|
data/lib/odf/style.rb
CHANGED
@@ -25,7 +25,7 @@ module ODF
|
|
25
25
|
class Style < Container
|
26
26
|
contains :properties
|
27
27
|
|
28
|
-
FAMILIES = {:cell => 'table-cell', :column => 'table-column'}
|
28
|
+
FAMILIES = {:cell => 'table-cell', :column => 'table-column', :row => 'table-row'}
|
29
29
|
|
30
30
|
def initialize(name='', opts={}, node_tag='style:style')
|
31
31
|
@name, @node_tag = name, node_tag
|
data/rodf.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "rodf"
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.3"
|
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, Foivos Zakkak"]
|
9
|
-
s.date = "
|
9
|
+
s.date = "2013-02-01"
|
10
10
|
s.description = "ODF generation library for Ruby"
|
11
11
|
s.email = "thiago.arrais@gmail.com"
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE.LGPL", "README.rdoc", "lib/odf/cell.rb", "lib/odf/column.rb", "lib/odf/compatibility.rb", "lib/odf/container.rb", "lib/odf/data_style.rb", "lib/odf/document.rb", "lib/odf/hyperlink.rb", "lib/odf/master_page.rb", "lib/odf/page_layout.rb", "lib/odf/paragraph.rb", "lib/odf/paragraph_container.rb", "lib/odf/property.rb", "lib/odf/row.rb", "lib/odf/skeleton.rb", "lib/odf/skeleton/manifest.xml.erb", "lib/odf/skeleton/styles.pxml", "lib/odf/span.rb", "lib/odf/spreadsheet.rb", "lib/odf/style.rb", "lib/odf/style_section.rb", "lib/odf/tab.rb", "lib/odf/table.rb", "lib/odf/text.rb"]
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rodf", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = "rodf"
|
18
|
-
s.rubygems_version = "1.8.
|
18
|
+
s.rubygems_version = "1.8.25"
|
19
19
|
s.summary = "ODF generation library for Ruby"
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
data/spec/property_spec.rb
CHANGED
@@ -45,6 +45,12 @@ describe ODF::Property do
|
|
45
45
|
elem['style:rotation-angle'].should == '-90'
|
46
46
|
end
|
47
47
|
|
48
|
+
it "should generate row properties tag" do
|
49
|
+
property = ODF::Property.new :row, 'background-color' => '#f5f57a'
|
50
|
+
|
51
|
+
property.xml.should have_tag('//style:table-row-properties')
|
52
|
+
end
|
53
|
+
|
48
54
|
it "should accept full perimeter border specs" do
|
49
55
|
property = ODF::Property.new :cell, :border => "0.025in solid #000000"
|
50
56
|
|
data/spec/row_spec.rb
CHANGED
@@ -41,4 +41,19 @@ describe ODF::Row do
|
|
41
41
|
output.should have_tag('//table:table-row/*', :count => 2)
|
42
42
|
output.should have_tag('//table:table-cell')
|
43
43
|
end
|
44
|
+
|
45
|
+
it "should be stylable in the initialization" do
|
46
|
+
output = ODF::Row.create 0, :style => 'dark' do
|
47
|
+
cell
|
48
|
+
end
|
49
|
+
Hpricot(output).at('table:table-row')['table:style-name'].
|
50
|
+
should == 'dark'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be attr_writer stylable" do
|
54
|
+
row = ODF::Row.new
|
55
|
+
row.style = 'dark'
|
56
|
+
Hpricot(row.xml).at('table:table-row')['table:style-name'].
|
57
|
+
should == 'dark'
|
58
|
+
end
|
44
59
|
end
|
data/spec/style_spec.rb
CHANGED
@@ -83,6 +83,13 @@ describe ODF::Style do
|
|
83
83
|
xml.should have_tag('//style:table-column-properties')
|
84
84
|
end
|
85
85
|
|
86
|
+
it "should be able to describe row styles" do
|
87
|
+
xml = ODF::Style.create 'column-style', :family => :row do |style|
|
88
|
+
end
|
89
|
+
|
90
|
+
Hpricot(xml).at('//style:style')['style:family'].should == 'table-row'
|
91
|
+
end
|
92
|
+
|
86
93
|
it "should accept other families" do
|
87
94
|
Hpricot(ODF::Style.create('text-style', :family => :text)).
|
88
95
|
at('//style:style')['style:family'].should == 'text'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rodf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rubyzip
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: 0.9.1
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.1
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: activesupport
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '3.0'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rspec
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ~>
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '2.9'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.9'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: rspec_hpricot_matchers
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ~>
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '1.0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: echoe
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ~>
|
@@ -76,7 +101,12 @@ dependencies:
|
|
76
101
|
version: '4.6'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '4.6'
|
80
110
|
description: ODF generation library for Ruby
|
81
111
|
email: thiago.arrais@gmail.com
|
82
112
|
executables: []
|
@@ -182,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
212
|
version: '1.2'
|
183
213
|
requirements: []
|
184
214
|
rubyforge_project: rodf
|
185
|
-
rubygems_version: 1.8.
|
215
|
+
rubygems_version: 1.8.25
|
186
216
|
signing_key:
|
187
217
|
specification_version: 3
|
188
218
|
summary: ODF generation library for Ruby
|