rodf 0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -1
- data/Manifest +1 -0
- data/README.rdoc +6 -8
- data/Rakefile +2 -1
- data/lib/odf/cell.rb +13 -8
- data/lib/odf/column.rb +33 -0
- data/lib/odf/container.rb +2 -0
- data/lib/odf/property.rb +5 -4
- data/lib/odf/skeleton/styles.xml +6 -7
- data/lib/odf/style.rb +14 -5
- data/lib/odf/table.rb +3 -1
- data/rodf.gemspec +10 -7
- data/spec/cell_spec.rb +18 -0
- data/spec/property_spec.rb +9 -0
- data/spec/style_spec.rb +33 -0
- data/spec/table_spec.rb +10 -0
- metadata +15 -3
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
= rODF
|
2
2
|
|
3
|
-
This is
|
4
|
-
creating spreadsheets.
|
3
|
+
This is a library for writing to ODF output with Ruby. It currently only
|
4
|
+
supports creating spreadsheets (ODS). Text documents (ODT) and slide shows (ODP)
|
5
|
+
may be added some time in the future.
|
5
6
|
|
6
7
|
This is NOT an ODF reading library.
|
7
8
|
|
8
|
-
|
9
|
+
=== Installation
|
9
10
|
|
10
|
-
|
11
|
+
You should be able to install the latest stable version by saying something like
|
11
12
|
|
12
13
|
sudo gem install rodf
|
13
14
|
|
14
|
-
|
15
|
-
the source: http://github.com/thiagoarrais/rodf/tree
|
16
|
-
|
17
|
-
== How do I use it?
|
15
|
+
=== How do I use it?
|
18
16
|
|
19
17
|
rODF works pretty much like Builder, but with ODF-aware constructs. Try this:
|
20
18
|
|
data/Rakefile
CHANGED
@@ -14,8 +14,9 @@ Echoe.new('rodf') do |gem|
|
|
14
14
|
gem.runtime_dependencies = [
|
15
15
|
["builder", ">= 2.1.2"],
|
16
16
|
["rubyzip", ">= 0.9.1"],
|
17
|
-
["activesupport", "
|
17
|
+
["activesupport", "= 2.1.2"]]
|
18
18
|
gem.development_dependencies = [
|
19
|
+
["rspec", ">= 1.1.11"],
|
19
20
|
["rspec_hpricot_matchers" , ">= 1.0"],
|
20
21
|
["echoe" , ">= 3.0.2"]]
|
21
22
|
end
|
data/lib/odf/cell.rb
CHANGED
@@ -25,18 +25,13 @@ module ODF
|
|
25
25
|
opts = args.last.instance_of?(Hash) ? args.last : {}
|
26
26
|
|
27
27
|
@type = opts[:type] || :string
|
28
|
-
@formula = opts[:formula]
|
29
|
-
@style = opts[:style]
|
30
28
|
@value = value.to_s.strip unless value.instance_of? Hash
|
29
|
+
|
30
|
+
@elem_attrs = make_element_attributes(@type, @value, opts)
|
31
31
|
end
|
32
32
|
|
33
33
|
def xml
|
34
|
-
|
35
|
-
elem_attrs['office:value'] = @value unless contains_string?
|
36
|
-
elem_attrs['table:formula'] = @formula unless @formula.nil?
|
37
|
-
elem_attrs['table:style-name'] = @style unless @style.nil?
|
38
|
-
|
39
|
-
Builder::XmlMarkup.new.tag! 'table:table-cell', elem_attrs do |xml|
|
34
|
+
Builder::XmlMarkup.new.tag! 'table:table-cell', @elem_attrs do |xml|
|
40
35
|
xml.text(:p, @value) if contains_string?
|
41
36
|
end
|
42
37
|
end
|
@@ -44,6 +39,16 @@ module ODF
|
|
44
39
|
def contains_string?
|
45
40
|
:string == @type && !@value.nil? && !@value.empty?
|
46
41
|
end
|
42
|
+
|
43
|
+
def make_element_attributes(type, value, opts)
|
44
|
+
attrs = {'office:value-type' => type}
|
45
|
+
attrs['office:value'] = value unless contains_string?
|
46
|
+
attrs['table:formula'] = opts[:formula] unless opts[:formula].nil?
|
47
|
+
attrs['table:style-name'] = opts[:style] unless opts[:style].nil?
|
48
|
+
attrs['table:number-matrix-columns-spanned'] =
|
49
|
+
attrs['table:number-matrix-rows-spanned'] = 1 if opts[:matrix_formula]
|
50
|
+
attrs
|
51
|
+
end
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
data/lib/odf/column.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright (c) 2008 Thiago Arrais
|
2
|
+
#
|
3
|
+
# This file is part of rODF.
|
4
|
+
#
|
5
|
+
# rODF is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as
|
7
|
+
# published by the Free Software Foundation, either version 3 of
|
8
|
+
# the License, or (at your option) any later version.
|
9
|
+
|
10
|
+
# rODF is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with rODF. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require 'rubygems'
|
19
|
+
require 'builder'
|
20
|
+
|
21
|
+
module ODF
|
22
|
+
class Column
|
23
|
+
def initialize(opts={})
|
24
|
+
@elem_attrs = {}
|
25
|
+
@elem_attrs['table:style-name'] = opts[:style] unless opts[:style].nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
def xml
|
29
|
+
Builder::XmlMarkup.new.tag! 'table:table-column', @elem_attrs
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/lib/odf/container.rb
CHANGED
data/lib/odf/property.rb
CHANGED
@@ -21,7 +21,8 @@ require 'builder'
|
|
21
21
|
module ODF
|
22
22
|
class Property
|
23
23
|
PROPERTY_NAMES = {:cell => 'style:table-cell-properties',
|
24
|
-
:text => 'style:text-properties'
|
24
|
+
:text => 'style:text-properties',
|
25
|
+
:column => 'style:table-column-properties'}
|
25
26
|
|
26
27
|
def initialize(type, specs={})
|
27
28
|
@name = PROPERTY_NAMES[type]
|
@@ -29,9 +30,9 @@ module ODF
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def xml
|
32
|
-
specs = {}
|
33
|
-
|
34
|
-
|
33
|
+
specs = @specs.inject({}) do |acc, kv|
|
34
|
+
prefix = 'column-width' == kv.first ? 'style' : 'fo'
|
35
|
+
acc.merge prefix + ':' + kv.first => kv.last
|
35
36
|
end
|
36
37
|
Builder::XmlMarkup.new.tag! @name, specs
|
37
38
|
end
|
data/lib/odf/skeleton/styles.xml
CHANGED
@@ -11,13 +11,12 @@
|
|
11
11
|
<style:table-cell-properties style:rotation-align="none"/>
|
12
12
|
<style:text-properties style:font-name="Arial1" style:font-name-complex="Arial1"/>
|
13
13
|
</style:style>
|
14
|
-
<number:number-style style:name="
|
14
|
+
<number:number-style style:name="currency-grouped">
|
15
15
|
<number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true" />
|
16
16
|
</number:number-style>
|
17
|
-
<number:number-style style:name="
|
18
|
-
<number:
|
19
|
-
|
20
|
-
<style:map style:condition="value()>=0" style:apply-style-name="number-currency-positive" />
|
21
|
-
</number:number-style>
|
17
|
+
<number:number-style style:name="integer-grouped">
|
18
|
+
<number:number number:decimal-places="0" number:min-integer-digits="1" number:grouping="true" />
|
19
|
+
</number:number-style>
|
22
20
|
</office:styles>
|
23
|
-
</office:document-styles>
|
21
|
+
</office:document-styles>
|
22
|
+
|
data/lib/odf/style.rb
CHANGED
@@ -25,20 +25,29 @@ module ODF
|
|
25
25
|
class Style < Container
|
26
26
|
contains :properties
|
27
27
|
|
28
|
-
FAMILIES = {:cell => 'table-cell'}
|
28
|
+
FAMILIES = {:cell => 'table-cell', :column => 'table-column'}
|
29
29
|
|
30
30
|
def initialize(name='', opts={})
|
31
31
|
@name = name
|
32
|
-
@
|
32
|
+
@elem_attrs = make_element_attributes(@name, opts)
|
33
33
|
end
|
34
34
|
|
35
35
|
def xml
|
36
|
-
Builder::XmlMarkup.new.style:style,
|
37
|
-
'style:family' => @family do
|
38
|
-
|xml|
|
36
|
+
Builder::XmlMarkup.new.style:style, @elem_attrs do |xml|
|
39
37
|
xml << properties_xml
|
40
38
|
end
|
41
39
|
end
|
40
|
+
|
41
|
+
def make_element_attributes(name, opts)
|
42
|
+
attrs = {'style:name' => name, 'style:family' => FAMILIES[opts[:family]]}
|
43
|
+
attrs['style:data-style-name'] = opts[:data_style] unless opts[:data_style].nil?
|
44
|
+
attrs['style:parent-style-name'] = opts[:parent].to_s unless opts[:parent].nil?
|
45
|
+
attrs
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_s
|
49
|
+
@name
|
50
|
+
end
|
42
51
|
end
|
43
52
|
end
|
44
53
|
|
data/lib/odf/table.rb
CHANGED
@@ -18,12 +18,13 @@
|
|
18
18
|
require 'rubygems'
|
19
19
|
require 'builder'
|
20
20
|
|
21
|
+
require 'odf/column'
|
21
22
|
require 'odf/container'
|
22
23
|
require 'odf/row'
|
23
24
|
|
24
25
|
module ODF
|
25
26
|
class Table < Container
|
26
|
-
contains :rows
|
27
|
+
contains :rows, :columns
|
27
28
|
|
28
29
|
def initialize(title)
|
29
30
|
@title = title
|
@@ -37,6 +38,7 @@ module ODF
|
|
37
38
|
|
38
39
|
def xml
|
39
40
|
Builder::XmlMarkup.new.table:table, 'table:name' => @title do |xml|
|
41
|
+
xml << columns_xml
|
40
42
|
xml << rows_xml
|
41
43
|
end
|
42
44
|
end
|
data/rodf.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rodf}
|
5
|
-
s.version = "0.1"
|
5
|
+
s.version = "0.1.1"
|
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-
|
9
|
+
s.date = %q{2008-12-02}
|
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/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/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"]
|
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
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/thiagoarrais/rodf/tree}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rodf", "--main", "README.rdoc"]
|
@@ -26,20 +26,23 @@ Gem::Specification.new do |s|
|
|
26
26
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
27
|
s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
|
28
28
|
s.add_runtime_dependency(%q<rubyzip>, [">= 0.9.1"])
|
29
|
-
s.add_runtime_dependency(%q<activesupport>, ["
|
29
|
+
s.add_runtime_dependency(%q<activesupport>, ["= 2.1.2"])
|
30
|
+
s.add_development_dependency(%q<rspec>, [">= 1.1.11"])
|
30
31
|
s.add_development_dependency(%q<rspec_hpricot_matchers>, [">= 1.0"])
|
31
32
|
s.add_development_dependency(%q<echoe>, [">= 3.0.2"])
|
32
33
|
else
|
33
34
|
s.add_dependency(%q<builder>, [">= 2.1.2"])
|
34
35
|
s.add_dependency(%q<rubyzip>, [">= 0.9.1"])
|
35
|
-
s.add_dependency(%q<activesupport>, ["
|
36
|
+
s.add_dependency(%q<activesupport>, ["= 2.1.2"])
|
37
|
+
s.add_dependency(%q<rspec>, [">= 1.1.11"])
|
36
38
|
s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0"])
|
37
39
|
s.add_dependency(%q<echoe>, [">= 3.0.2"])
|
38
40
|
end
|
39
41
|
else
|
40
42
|
s.add_dependency(%q<builder>, [">= 2.1.2"])
|
41
43
|
s.add_dependency(%q<rubyzip>, [">= 0.9.1"])
|
42
|
-
s.add_dependency(%q<activesupport>, ["
|
44
|
+
s.add_dependency(%q<activesupport>, ["= 2.1.2"])
|
45
|
+
s.add_dependency(%q<rspec>, [">= 1.1.11"])
|
43
46
|
s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0"])
|
44
47
|
s.add_dependency(%q<echoe>, [">= 3.0.2"])
|
45
48
|
end
|
data/spec/cell_spec.rb
CHANGED
@@ -59,6 +59,24 @@ describe ODF::Cell do
|
|
59
59
|
elem['table:formula'].should == 'oooc:=SUM([.A1:.A4])'
|
60
60
|
end
|
61
61
|
|
62
|
+
it "should accept matrix formulas" do
|
63
|
+
output = ODF::Cell.new(:type => :float, :matrix_formula => true,
|
64
|
+
:formula => "oooc:=SUM([.A1:.A4])").xml
|
65
|
+
|
66
|
+
elem = Hpricot(output).at('table:table-cell')
|
67
|
+
elem['table:number-matrix-columns-spanned'].should == '1'
|
68
|
+
elem['table:number-matrix-rows-spanned'].should == '1'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should not make a matrix formula when asked not too" do
|
72
|
+
output = ODF::Cell.new(:type => :float, :matrix_formula => false,
|
73
|
+
:formula => "oooc:=SUM([.A1:.A4])").xml
|
74
|
+
|
75
|
+
elem = Hpricot(output).at('table:table-cell')
|
76
|
+
elem['table:number-matrix-columns-spanned'].should be_nil
|
77
|
+
elem['table:number-matrix-rows-spanned'].should be_nil
|
78
|
+
end
|
79
|
+
|
62
80
|
it "should not have an empty paragraph" do
|
63
81
|
[ODF::Cell.new, ODF::Cell.new(''), ODF::Cell.new(' ')].each do |cell|
|
64
82
|
cell.xml.should_not have_tag('text:p')
|
data/spec/property_spec.rb
CHANGED
@@ -26,5 +26,14 @@ describe ODF::Property do
|
|
26
26
|
elem['fo:color'].should == '#4c4c4c'
|
27
27
|
elem['fo:font-weight'].should == 'bold'
|
28
28
|
end
|
29
|
+
|
30
|
+
it "should prefix column-width property with style namespace" do
|
31
|
+
property = ODF::Property.new :column, 'column-width' => '2cm'
|
32
|
+
|
33
|
+
property.xml.should have_tag('//style:table-column-properties')
|
34
|
+
|
35
|
+
elem = Hpricot(property.xml).at('//style:table-column-properties')
|
36
|
+
elem['style:column-width'].should == '2cm'
|
37
|
+
end
|
29
38
|
end
|
30
39
|
|
data/spec/style_spec.rb
CHANGED
@@ -40,5 +40,38 @@ describe ODF::Style do
|
|
40
40
|
text_elem = Hpricot(output).at('style:text-properties')
|
41
41
|
text_elem['fo:color'].should == '#4c4c4c'
|
42
42
|
end
|
43
|
+
|
44
|
+
it "should allow data styles" do
|
45
|
+
xml = ODF::Style.create 'my-style', :family => :cell,
|
46
|
+
:data_style => 'currency-grouped'
|
47
|
+
|
48
|
+
style = Hpricot(xml).at('//style:style')
|
49
|
+
style['style:data-style-name'].should == 'currency-grouped'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should allow parent styles" do
|
53
|
+
xml = ODF::Style.create 'child-style', :family => :cell,
|
54
|
+
:parent => 'cell-default'
|
55
|
+
|
56
|
+
style = Hpricot(xml).at('//style:style')
|
57
|
+
style['style:parent-style-name'].should == 'cell-default'
|
58
|
+
|
59
|
+
cell_style = ODF::Style.new('cell-default', :family => :cell)
|
60
|
+
xml = ODF::Style.create 'child-style', :family => :cell,
|
61
|
+
:parent => cell_style
|
62
|
+
|
63
|
+
style = Hpricot(xml).at('//style:style')
|
64
|
+
style['style:parent-style-name'].should == 'cell-default'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should be able to describe column styles" do
|
68
|
+
xml = ODF::Style.create 'column-style', :family => :column do |style|
|
69
|
+
style.property :column, 'column-width' => '2cm'
|
70
|
+
end
|
71
|
+
|
72
|
+
Hpricot(xml).at('//style:style')['style:family'].should == 'table-column'
|
73
|
+
xml.should have_tag('//style:style/*', :count => 1)
|
74
|
+
xml.should have_tag('//style:table-column-properties')
|
75
|
+
end
|
43
76
|
end
|
44
77
|
|
data/spec/table_spec.rb
CHANGED
@@ -45,4 +45,14 @@ describe ODF::Table do
|
|
45
45
|
output.should have_tag('text:p')
|
46
46
|
Hpricot(output).at('text:p').innerHTML.should == '2'
|
47
47
|
end
|
48
|
+
|
49
|
+
it "should allow column style specifications" do
|
50
|
+
xml = ODF::Table.create('Styles columns table') do |t|
|
51
|
+
t.column :style => 'wide'
|
52
|
+
end
|
53
|
+
|
54
|
+
xml.should have_tag('table:table-column')
|
55
|
+
column = Hpricot(xml).at('table:table-column')
|
56
|
+
column['table:style-name'].should == 'wide'
|
57
|
+
end
|
48
58
|
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:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago Arrais
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-02 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -36,11 +36,21 @@ dependencies:
|
|
36
36
|
name: activesupport
|
37
37
|
type: :runtime
|
38
38
|
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.1.2
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: rspec
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
39
49
|
version_requirements: !ruby/object:Gem::Requirement
|
40
50
|
requirements:
|
41
51
|
- - ">="
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
53
|
+
version: 1.1.11
|
44
54
|
version:
|
45
55
|
- !ruby/object:Gem::Dependency
|
46
56
|
name: rspec_hpricot_matchers
|
@@ -72,6 +82,7 @@ extra_rdoc_files:
|
|
72
82
|
- lib/odf/row.rb
|
73
83
|
- lib/odf/spreadsheet.rb
|
74
84
|
- lib/odf/cell.rb
|
85
|
+
- lib/odf/column.rb
|
75
86
|
- lib/odf/table.rb
|
76
87
|
- lib/odf/property.rb
|
77
88
|
- lib/odf/style.rb
|
@@ -85,6 +96,7 @@ files:
|
|
85
96
|
- lib/odf/row.rb
|
86
97
|
- lib/odf/spreadsheet.rb
|
87
98
|
- lib/odf/cell.rb
|
99
|
+
- lib/odf/column.rb
|
88
100
|
- lib/odf/table.rb
|
89
101
|
- lib/odf/property.rb
|
90
102
|
- lib/odf/style.rb
|