rodf 0.2.2 → 0.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 +8 -8
- data/lib/odf/cell.rb +9 -8
- data/lib/odf/container.rb +4 -4
- data/lib/odf/document.rb +2 -2
- data/lib/odf/table.rb +2 -2
- data/rodf.gemspec +2 -2
- data/spec/cell_spec.rb +14 -0
- data/spec/data_style_spec.rb +11 -0
- data/spec/hyperlink_spec.rb +9 -0
- data/spec/page_layout_spec.rb +8 -0
- data/spec/row_spec.rb +9 -0
- data/spec/style_spec.rb +9 -1
- data/spec/table_spec.rb +19 -0
- metadata +14 -14
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -18,9 +18,9 @@ rODF works pretty much like Builder, but with ODF-aware constructs. Try this:
|
|
18
18
|
|
19
19
|
require 'odf/spreadsheet'
|
20
20
|
|
21
|
-
ODF::Spreadsheet.file("my-spreadsheet.ods") do
|
22
|
-
|
23
|
-
|
21
|
+
ODF::Spreadsheet.file("my-spreadsheet.ods") do
|
22
|
+
table 'My first table from Ruby' do
|
23
|
+
row {cell 'Hello, rODF world!' }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -28,12 +28,12 @@ Some basic formatting is also possible:
|
|
28
28
|
|
29
29
|
require 'odf/spreadsheet'
|
30
30
|
|
31
|
-
ODF::Spreadsheet.file("my-spreadsheet.ods") do
|
32
|
-
|
33
|
-
|
31
|
+
ODF::Spreadsheet.file("my-spreadsheet.ods") do
|
32
|
+
style 'red-cell', :family => :cell do
|
33
|
+
property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
|
34
34
|
end
|
35
|
-
|
36
|
-
|
35
|
+
table 'Red text table' do
|
36
|
+
row {cell 'Red', :style => 'red-cell' }
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
data/lib/odf/cell.rb
CHANGED
@@ -56,16 +56,16 @@ module ODF
|
|
56
56
|
text
|
57
57
|
end
|
58
58
|
|
59
|
+
def contains_url?
|
60
|
+
!@url.nil? && !@url.empty?
|
61
|
+
end
|
62
|
+
|
59
63
|
private
|
60
64
|
|
61
65
|
def contains_string?
|
62
66
|
:string == @type && !@value.nil? && !@value.empty?
|
63
67
|
end
|
64
68
|
|
65
|
-
def contains_url?
|
66
|
-
!@url.nil? && !@url.empty?
|
67
|
-
end
|
68
|
-
|
69
69
|
def make_element_attributes(type, value, opts)
|
70
70
|
attrs = {}
|
71
71
|
attrs['office:value-type'] = type if :string == type || !empty(value) || !opts[:formula].nil?
|
@@ -81,11 +81,12 @@ module ODF
|
|
81
81
|
|
82
82
|
def make_value_paragraph
|
83
83
|
if contains_string?
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
cell, value, url = self, @value, @url
|
85
|
+
paragraph do
|
86
|
+
if cell.contains_url?
|
87
|
+
link value, :href => url
|
87
88
|
else
|
88
|
-
|
89
|
+
self << value
|
89
90
|
end
|
90
91
|
end
|
91
92
|
end
|
data/lib/odf/container.rb
CHANGED
@@ -33,9 +33,9 @@ module ODF
|
|
33
33
|
end"
|
34
34
|
|
35
35
|
self.class_eval "
|
36
|
-
def #{stuff}(*args)
|
36
|
+
def #{stuff}(*args, &contents)
|
37
37
|
c = #{stuff_class}.new(*args)
|
38
|
-
|
38
|
+
c.instance_eval(&contents) if block_given?
|
39
39
|
#{stuffs} << c
|
40
40
|
c
|
41
41
|
end"
|
@@ -47,9 +47,9 @@ module ODF
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def self.create(*args)
|
50
|
+
def self.create(*args, &contents)
|
51
51
|
container = self.new(*args)
|
52
|
-
|
52
|
+
container.instance_eval(&contents) if block_given?
|
53
53
|
container.xml
|
54
54
|
end
|
55
55
|
end
|
data/lib/odf/document.rb
CHANGED
@@ -27,12 +27,12 @@ module ODF
|
|
27
27
|
class Document < Container
|
28
28
|
contains :styles, :default_styles
|
29
29
|
|
30
|
-
def self.file(ods_file_name)
|
30
|
+
def self.file(ods_file_name, &contents)
|
31
31
|
ods_file = Zip::ZipFile.open(ods_file_name, Zip::ZipFile::CREATE)
|
32
32
|
ods_file.get_output_stream('styles.xml') {|f| f << skeleton.styles }
|
33
33
|
ods_file.get_output_stream('META-INF/manifest.xml') {|f| f << skeleton.manifest(doc_type) }
|
34
34
|
|
35
|
-
|
35
|
+
(doc = new).instance_eval(&contents)
|
36
36
|
|
37
37
|
ods_file.get_output_stream('content.xml') {|f| f << doc.xml}
|
38
38
|
|
data/lib/odf/table.rb
CHANGED
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.
|
5
|
+
s.version = "0.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"]
|
9
|
-
s.date = "2012-
|
9
|
+
s.date = "2012-07-13"
|
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.xml", "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"]
|
data/spec/cell_spec.rb
CHANGED
@@ -164,5 +164,19 @@ describe ODF::Cell do
|
|
164
164
|
cell['office:value-type'].should be_nil
|
165
165
|
end
|
166
166
|
end
|
167
|
+
|
168
|
+
it "should accept parameterless blocks" do
|
169
|
+
output = ODF::Cell.create do
|
170
|
+
paragraph "first"
|
171
|
+
paragraph "second"
|
172
|
+
end
|
173
|
+
|
174
|
+
output.should have_tag("//table:table-cell/*", :count => 2)
|
175
|
+
output.should have_tag("//text:p")
|
176
|
+
|
177
|
+
ps = Hpricot(output).search('text:p')
|
178
|
+
ps[0].innerHTML.should == 'first'
|
179
|
+
ps[1].innerHTML.should == 'second'
|
180
|
+
end
|
167
181
|
end
|
168
182
|
|
data/spec/data_style_spec.rb
CHANGED
@@ -46,5 +46,16 @@ describe ODF::DataStyle do
|
|
46
46
|
output.should have_tag('number:month')
|
47
47
|
output.should have_tag('number:day')
|
48
48
|
end
|
49
|
+
|
50
|
+
it "should accept parameterless blocks" do
|
51
|
+
output = ODF::DataStyle.create 'year-to-day', :date do
|
52
|
+
section :year, :style => 'long'
|
53
|
+
section :month, :style => 'long'
|
54
|
+
section :day
|
55
|
+
end
|
56
|
+
|
57
|
+
output.should have_tag('number:date-style')
|
58
|
+
output.should have_tag('number:year')
|
59
|
+
end
|
49
60
|
end
|
50
61
|
|
data/spec/hyperlink_spec.rb
CHANGED
@@ -49,5 +49,14 @@ describe ODF::Hyperlink do
|
|
49
49
|
span['text:style-name'].should == 'strong'
|
50
50
|
span.innerHTML.should == 'important link'
|
51
51
|
end
|
52
|
+
|
53
|
+
it "should accept parameterless blocks" do
|
54
|
+
output = ODF::Hyperlink.create 'http://www.example.com/' do
|
55
|
+
strong 'important link'
|
56
|
+
end
|
57
|
+
|
58
|
+
output.should have_tag('//text:a/*')
|
59
|
+
output.should have_tag('//text:span/*')
|
60
|
+
end
|
52
61
|
end
|
53
62
|
|
data/spec/page_layout_spec.rb
CHANGED
@@ -33,5 +33,13 @@ describe ODF::PageLayout do
|
|
33
33
|
output.should have_tag('//style:page-layout/*', :count => 1)
|
34
34
|
output.should have_tag('style:page-layout-properties')
|
35
35
|
end
|
36
|
+
|
37
|
+
it "should accept parameterless blocks" do
|
38
|
+
output = ODF::PageLayout.create 'main-layout' do
|
39
|
+
property 'page-layout'
|
40
|
+
end
|
41
|
+
output.should have_tag('//style:page-layout/*', :count => 1)
|
42
|
+
output.should have_tag('style:page-layout-properties')
|
43
|
+
end
|
36
44
|
end
|
37
45
|
|
data/spec/row_spec.rb
CHANGED
@@ -32,4 +32,13 @@ describe ODF::Row do
|
|
32
32
|
output.should have_tag('//table:table-row/*', :count => 2)
|
33
33
|
output.should have_tag('//table:table-cell')
|
34
34
|
end
|
35
|
+
|
36
|
+
it "should accept parameterless blocks" do
|
37
|
+
output = ODF::Row.create do
|
38
|
+
cell
|
39
|
+
cell
|
40
|
+
end
|
41
|
+
output.should have_tag('//table:table-row/*', :count => 2)
|
42
|
+
output.should have_tag('//table:table-cell')
|
43
|
+
end
|
35
44
|
end
|
data/spec/style_spec.rb
CHANGED
@@ -22,7 +22,7 @@ require 'odf/style'
|
|
22
22
|
describe ODF::Style do
|
23
23
|
it "should output properties when they're added" do
|
24
24
|
ODF::Style.create.should_not have_tag('//style:style/*')
|
25
|
-
|
25
|
+
|
26
26
|
output = ODF::Style.create 'odd-row-cell', :family => :cell do |s|
|
27
27
|
s.property :cell, 'background-color' => '#b3b3b3',
|
28
28
|
'border' => '0.002cm solid #000000'
|
@@ -90,5 +90,13 @@ describe ODF::Style do
|
|
90
90
|
Hpricot(ODF::Style.create('text-style', :family => :paragraph)).
|
91
91
|
at('//style:style')['style:family'].should == 'paragraph'
|
92
92
|
end
|
93
|
+
|
94
|
+
it "should accept parameterless blocks" do
|
95
|
+
output = ODF::Style.create 'odd-row-cell', :family => :cell do
|
96
|
+
property :text, 'color' => '#4c4c4c', 'font-weight' => 'bold'
|
97
|
+
end
|
98
|
+
|
99
|
+
output.should have_tag('//style:style/*')
|
100
|
+
end
|
93
101
|
end
|
94
102
|
|
data/spec/table_spec.rb
CHANGED
@@ -55,4 +55,23 @@ describe ODF::Table do
|
|
55
55
|
column = Hpricot(xml).at('table:table-column')
|
56
56
|
column['table:style-name'].should == 'wide'
|
57
57
|
end
|
58
|
+
|
59
|
+
it "should accept parameterless block" do
|
60
|
+
output = ODF::Table.create('MyTable') {
|
61
|
+
row
|
62
|
+
row
|
63
|
+
}
|
64
|
+
output.should have_tag('//table:table/*', :count => 2)
|
65
|
+
output.should have_tag('//table:table-row')
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should have children that accept parameterless blocks too" do
|
69
|
+
output = ODF::Table.create('MyTable') {
|
70
|
+
row {cell}
|
71
|
+
row
|
72
|
+
}
|
73
|
+
output.should have_tag('//table:table/*', :count => 2)
|
74
|
+
output.should have_tag('//table:table-row')
|
75
|
+
output.should have_tag('//table:table-cell')
|
76
|
+
end
|
58
77
|
end
|
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.
|
4
|
+
version: '0.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: 2012-
|
12
|
+
date: 2012-07-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
16
|
-
requirement: &
|
16
|
+
requirement: &75169230 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *75169230
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rubyzip
|
27
|
-
requirement: &
|
27
|
+
requirement: &75169020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *75169020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
38
|
-
requirement: &
|
38
|
+
requirement: &75168810 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *75168810
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &75168600 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '2.9'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *75168600
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec_hpricot_matchers
|
60
|
-
requirement: &
|
60
|
+
requirement: &75168390 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *75168390
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: echoe
|
71
|
-
requirement: &
|
71
|
+
requirement: &75168180 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '4.6'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *75168180
|
80
80
|
description: ODF generation library for Ruby
|
81
81
|
email: thiago.arrais@gmail.com
|
82
82
|
executables: []
|