rodf 0.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.
@@ -0,0 +1,2 @@
1
+ v0.1. First version with very basic support for spreadsheet generation
2
+
@@ -0,0 +1,166 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
166
+
@@ -0,0 +1,21 @@
1
+ lib/odf/row.rb
2
+ lib/odf/spreadsheet.rb
3
+ lib/odf/cell.rb
4
+ lib/odf/table.rb
5
+ lib/odf/property.rb
6
+ lib/odf/style.rb
7
+ lib/odf/skeleton/manifest.xml
8
+ lib/odf/skeleton/styles.xml
9
+ lib/odf/container.rb
10
+ CHANGELOG
11
+ README.rdoc
12
+ Rakefile
13
+ LICENSE.LGPL
14
+ spec/cell_spec.rb
15
+ spec/spreadsheet_spec.rb
16
+ spec/spec_helper.rb
17
+ spec/row_spec.rb
18
+ spec/table_spec.rb
19
+ spec/style_spec.rb
20
+ spec/property_spec.rb
21
+ Manifest
@@ -0,0 +1,41 @@
1
+ = rODF
2
+
3
+ This is (soon to be) a RubyGem for writing to ODF output. It currently supports
4
+ creating spreadsheets.
5
+
6
+ This is NOT an ODF reading library.
7
+
8
+ == Installation
9
+
10
+ At some moment you'll be able to
11
+
12
+ sudo gem install rodf
13
+
14
+ But for the time being, try going to the project's GitHub page and downloading
15
+ the source: http://github.com/thiagoarrais/rodf/tree
16
+
17
+ == How do I use it?
18
+
19
+ rODF works pretty much like Builder, but with ODF-aware constructs. Try this:
20
+
21
+ require 'odf/spreadsheet'
22
+
23
+ ODF::SpreadSheet.file("my-spreadsheet.ods") do |spreadsheet|
24
+ spreadsheet.table 'My first table from Ruby' do |table|
25
+ table.row {|row| row.cell 'Hello, rODF world!' }
26
+ end
27
+ end
28
+
29
+ Some basic formatting is also possible:
30
+
31
+ require 'odf/spreadsheet'
32
+
33
+ ODF::SpreadSheet.file("my-spreadsheet.ods") do |spreadsheet|
34
+ spreadsheet.style 'red-cell', :family => :cell do |style|
35
+ style.property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
36
+ end
37
+ spreadsheet.table 'Red text table' do |table|
38
+ table.row {|row| row.cell 'Red', :style => 'red-cell' }
39
+ end
40
+ end
41
+
@@ -0,0 +1,21 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ Spec::Rake::SpecTask.new
4
+ task :default => :spec
5
+ task :test => :spec
6
+
7
+ require 'echoe'
8
+ Echoe.new('rodf') do |gem|
9
+ gem.author = "Thiago Arrais"
10
+ gem.email = "thiago.arrais@gmail.com"
11
+ gem.url = "http://github.com/thiagoarrais/rodf/tree"
12
+ gem.summary = "ODF generation library for Ruby"
13
+
14
+ gem.runtime_dependencies = [
15
+ ["builder", ">= 2.1.2"],
16
+ ["rubyzip", ">= 0.9.1"],
17
+ ["activesupport", ">= 2.0.0"]]
18
+ gem.development_dependencies = [
19
+ ["rspec_hpricot_matchers" , ">= 1.0"],
20
+ ["echoe" , ">= 3.0.2"]]
21
+ end
@@ -0,0 +1,49 @@
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 Cell
23
+ def initialize(*args)
24
+ value = args.first || ''
25
+ opts = args.last.instance_of?(Hash) ? args.last : {}
26
+
27
+ @type = opts[:type] || :string
28
+ @formula = opts[:formula]
29
+ @style = opts[:style]
30
+ @value = value.to_s.strip unless value.instance_of? Hash
31
+ end
32
+
33
+ def xml
34
+ elem_attrs = {'office:value-type' => @type}
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|
40
+ xml.text(:p, @value) if contains_string?
41
+ end
42
+ end
43
+
44
+ def contains_string?
45
+ :string == @type && !@value.nil? && !@value.empty?
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,55 @@
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 'active_support/core_ext/string'
20
+
21
+ module ODF
22
+ class Container
23
+ def self.contains(*stuffs_array)
24
+ stuffs_array.map {|sym| sym.to_s}.each do |stuffs|
25
+ stuff = stuffs.to_s.singularize
26
+ stuff_class = eval(stuff.capitalize)
27
+
28
+ self.class_eval "
29
+ def #{stuffs}
30
+ @#{stuffs} ||= []
31
+ end"
32
+
33
+ self.class_eval "
34
+ def #{stuff}(*args)
35
+ c = #{stuff_class}.new(*args)
36
+ yield c if block_given?
37
+ #{stuffs} << c
38
+ c
39
+ end"
40
+
41
+ self.class_eval "
42
+ def #{stuffs}_xml
43
+ #{stuffs}.map {|c| c.xml}.join
44
+ end"
45
+ end
46
+ end
47
+
48
+ def self.create(*args)
49
+ container = self.new(*args)
50
+ yield container if block_given?
51
+ container.xml
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,40 @@
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 Property
23
+ PROPERTY_NAMES = {:cell => 'style:table-cell-properties',
24
+ :text => 'style:text-properties'}
25
+
26
+ def initialize(type, specs={})
27
+ @name = PROPERTY_NAMES[type]
28
+ @specs = specs.map { |k, v| [k.to_s, v] }
29
+ end
30
+
31
+ def xml
32
+ specs = {}
33
+ @specs.each do |k, v|
34
+ specs['fo:' + k] = v
35
+ end
36
+ Builder::XmlMarkup.new.tag! @name, specs
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,40 @@
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
+ require 'odf/container'
22
+ require 'odf/cell'
23
+
24
+ module ODF
25
+ class Row < Container
26
+ contains :cells
27
+ attr_reader :number
28
+
29
+ def initialize(number=0)
30
+ @number = number
31
+ end
32
+
33
+ def xml
34
+ Builder::XmlMarkup.new.tag! 'table:table-row' do |xml|
35
+ xml << cells_xml
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd">
3
+ <manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
4
+ <manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.spreadsheet" manifest:full-path="/"/>
5
+ <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>
6
+ <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>
7
+ </manifest:manifest>
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
3
+ xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
4
+ xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
5
+ xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0">
6
+ <office:font-face-decls>
7
+ <style:font-face style:name="Arial1" svg:font-family="Arial" style:font-family-generic="swiss"/>
8
+ </office:font-face-decls>
9
+ <office:styles>
10
+ <style:style style:name="Default" style:family="table-cell">
11
+ <style:table-cell-properties style:rotation-align="none"/>
12
+ <style:text-properties style:font-name="Arial1" style:font-name-complex="Arial1"/>
13
+ </style:style>
14
+ <number:number-style style:name="number-currency-positive" style:volatile="true">
15
+ <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true" />
16
+ </number:number-style>
17
+ <number:number-style style:name="number-currency">
18
+ <number:text>-</number:text>
19
+ <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true" />
20
+ <style:map style:condition="value()&gt;=0" style:apply-style-name="number-currency-positive" />
21
+ </number:number-style>
22
+ </office:styles>
23
+ </office:document-styles>
@@ -0,0 +1,71 @@
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
+
20
+ require 'builder'
21
+ require 'zip/zip'
22
+
23
+ require 'odf/container'
24
+ require 'odf/style'
25
+ require 'odf/table'
26
+
27
+ module ODF
28
+ class SpreadSheet < Container
29
+ contains :tables, :styles
30
+
31
+ def self.file(ods_file_name)
32
+ ods_file = Zip::ZipFile.open(ods_file_name, Zip::ZipFile::CREATE)
33
+ ods_file.get_output_stream('styles.xml') {|f| f << skeleton('styles.xml')}
34
+ ods_file.get_output_stream('META-INF/manifest.xml') {|f| f << skeleton('manifest.xml')}
35
+
36
+ yield(spreadsheet = new)
37
+
38
+ ods_file.get_output_stream('content.xml') {|f| f << spreadsheet.xml}
39
+
40
+ ods_file.close
41
+ end
42
+
43
+ def xml
44
+ b = Builder::XmlMarkup.new
45
+
46
+ b.instruct! :xml, :version => '1.0', :encoding => 'UTF-8'
47
+ b.tag! 'office:document-content', 'xmlns:office' => "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
48
+ 'xmlns:table' => "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
49
+ 'xmlns:text' => "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
50
+ 'xmlns:oooc' => "http://openoffice.org/2004/calc",
51
+ 'xmlns:style' => "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
52
+ 'xmlns:fo' => "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" do
53
+ |xml|
54
+ xml.tag! 'office:automatic-styles' do
55
+ xml << styles_xml
56
+ end unless styles.empty?
57
+ xml.office:body do
58
+ xml.office:spreadsheet do
59
+ xml << tables_xml
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ private
66
+ def self.skeleton(fname)
67
+ File.open(File.dirname(__FILE__) + '/skeleton/' + fname).read
68
+ end
69
+ end
70
+ end
71
+
@@ -0,0 +1,44 @@
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
+ require 'odf/container'
22
+ require 'odf/property'
23
+
24
+ module ODF
25
+ class Style < Container
26
+ contains :properties
27
+
28
+ FAMILIES = {:cell => 'table-cell'}
29
+
30
+ def initialize(name='', opts={})
31
+ @name = name
32
+ @family = FAMILIES[opts[:family]]
33
+ end
34
+
35
+ def xml
36
+ Builder::XmlMarkup.new.style:style, 'style:name' => @name,
37
+ 'style:family' => @family do
38
+ |xml|
39
+ xml << properties_xml
40
+ end
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,48 @@
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
+ require 'odf/container'
22
+ require 'odf/row'
23
+
24
+ module ODF
25
+ class Table < Container
26
+ contains :rows
27
+
28
+ def initialize(title)
29
+ @title = title
30
+ @last_row = 0
31
+ end
32
+
33
+ alias create_row row
34
+ def row
35
+ create_row(next_row) {|r| yield r if block_given?}
36
+ end
37
+
38
+ def xml
39
+ Builder::XmlMarkup.new.table:table, 'table:name' => @title do |xml|
40
+ xml << rows_xml
41
+ end
42
+ end
43
+ private
44
+ def next_row
45
+ @last_row += 1
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rodf}
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Thiago Arrais"]
9
+ s.date = %q{2008-11-22}
10
+ s.description = %q{ODF generation library for Ruby}
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"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/thiagoarrais/rodf/tree}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rodf", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{rodf}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{ODF generation library for Ruby}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
28
+ s.add_runtime_dependency(%q<rubyzip>, [">= 0.9.1"])
29
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.0.0"])
30
+ s.add_development_dependency(%q<rspec_hpricot_matchers>, [">= 1.0"])
31
+ s.add_development_dependency(%q<echoe>, [">= 3.0.2"])
32
+ else
33
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
34
+ s.add_dependency(%q<rubyzip>, [">= 0.9.1"])
35
+ s.add_dependency(%q<activesupport>, [">= 2.0.0"])
36
+ s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0"])
37
+ s.add_dependency(%q<echoe>, [">= 3.0.2"])
38
+ end
39
+ else
40
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
41
+ s.add_dependency(%q<rubyzip>, [">= 0.9.1"])
42
+ s.add_dependency(%q<activesupport>, [">= 2.0.0"])
43
+ s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0"])
44
+ s.add_dependency(%q<echoe>, [">= 3.0.2"])
45
+ end
46
+ end
@@ -0,0 +1,73 @@
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 File.expand_path(File.dirname(__FILE__) + '/spec_helper')
19
+
20
+ require 'odf/cell'
21
+
22
+ describe ODF::Cell do
23
+ it "should hold text content in a paragraph tag" do
24
+ output = ODF::Cell.new('Test').xml
25
+ output.should have_tag('//table:table-cell/*')
26
+ output.should have_tag('//text:p')
27
+ Hpricot(output).at('text:p').innerHTML.should == 'Test'
28
+ end
29
+
30
+ it "should have string as default value type" do
31
+ [ODF::Cell.new('Test').xml, ODF::Cell.new(54).xml].each do |xml|
32
+ Hpricot(xml).at('table:table-cell')['office:value-type'].should=='string'
33
+ end
34
+ end
35
+
36
+ it "should allow value types to be specified" do
37
+ output = ODF::Cell.new(34.2, :type => :float).xml
38
+ Hpricot(output).at('table:table-cell')['office:value-type'].should=='float'
39
+ end
40
+
41
+ it "should place strings in a paragraph tag and floats in value attribute" do
42
+ output = ODF::Cell.new('Test').xml
43
+ Hpricot(output).at('text:p').innerHTML.should == 'Test'
44
+
45
+ output = ODF::Cell.new(47, :type => :float).xml
46
+ output.should_not have_tag('//table:table-cell/*')
47
+ Hpricot(output).at('table:table-cell')['office:value'].should == '47'
48
+
49
+ output = ODF::Cell.new(34.2, :type => :string).xml
50
+ Hpricot(output).at('text:p').innerHTML.should == '34.2'
51
+ end
52
+
53
+ it "should accept formulas" do
54
+ output = ODF::Cell.new(:type => :float,
55
+ :formula => "oooc:=SUM([.A1:.A4])").xml
56
+
57
+ elem = Hpricot(output).at('table:table-cell')
58
+ elem['office:value-type'].should == 'float'
59
+ elem['table:formula'].should == 'oooc:=SUM([.A1:.A4])'
60
+ end
61
+
62
+ it "should not have an empty paragraph" do
63
+ [ODF::Cell.new, ODF::Cell.new(''), ODF::Cell.new(' ')].each do |cell|
64
+ cell.xml.should_not have_tag('text:p')
65
+ end
66
+ end
67
+
68
+ it "should allow an style to be specified" do
69
+ cell = ODF::Cell.new 45.8, :type => :float, :style => 'left-column-cell'
70
+ Hpricot(cell.xml).at('table:table-cell')['table:style-name'].
71
+ should == 'left-column-cell'
72
+ end
73
+ end
@@ -0,0 +1,30 @@
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 File.expand_path(File.dirname(__FILE__) + '/spec_helper')
19
+
20
+ require 'odf/property'
21
+
22
+ describe ODF::Property do
23
+ it "should accept either strings or symbols as keys" do
24
+ property = ODF::Property.new :text, :color=>'#4c4c4c', 'font-weight'=>'bold'
25
+ elem = Hpricot(property.xml).at('style:text-properties')
26
+ elem['fo:color'].should == '#4c4c4c'
27
+ elem['fo:font-weight'].should == 'bold'
28
+ end
29
+ end
30
+
@@ -0,0 +1,35 @@
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 File.expand_path(File.dirname(__FILE__) + '/spec_helper')
19
+
20
+ require 'odf/row'
21
+
22
+ describe ODF::Row do
23
+ it "should allow cells to be added" do
24
+ output = ODF::Row.create
25
+ output.should have_tag('//table:table-row')
26
+ output.should_not have_tag('//table:table-row/*')
27
+
28
+ output = ODF::Row.create {|r|
29
+ r.cell
30
+ r.cell
31
+ }
32
+ output.should have_tag('//table:table-row/*', :count => 2)
33
+ output.should have_tag('//table:table-cell')
34
+ end
35
+ end
@@ -0,0 +1,23 @@
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
+ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
19
+
20
+ require 'rubygems'
21
+
22
+ require 'rspec_hpricot_matchers'
23
+ include RspecHpricotMatchers
@@ -0,0 +1,73 @@
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 File.expand_path(File.dirname(__FILE__) + '/spec_helper')
19
+
20
+ require 'odf/spreadsheet'
21
+
22
+ describe ODF::SpreadSheet do
23
+ it "should have the expected structure" do
24
+ output = ODF::SpreadSheet.create {|s| }
25
+ output.should have_tag('//office:document-content/*')
26
+ output.should have_tag('//office:body/*')
27
+ output.should have_tag('//office:spreadsheet')
28
+ end
29
+
30
+ it "should be empty if no tables were added" do
31
+ output = ODF::SpreadSheet.create {|s| }
32
+ output.should_not have_tag('//office:spreadsheet/*')
33
+ end
34
+
35
+ it "should include tables when asked to" do
36
+ output = ODF::SpreadSheet.create { |s|
37
+ s.table 'Example'
38
+ }
39
+ output.should have_tag('//office:spreadsheet/*', :count => 1)
40
+ output.should have_tag('//table:table', :count => 1)
41
+ Hpricot(output).at('//table:table')['table:name'].should == 'Example'
42
+
43
+ output = ODF::SpreadSheet.create { |s|
44
+ s.table 'First table'
45
+ s.table 'Second table'
46
+ }
47
+ output.should have_tag('//office:spreadsheet/*', :count => 2)
48
+ end
49
+
50
+ it "should allow rows to be added inside tables" do
51
+ output = ODF::SpreadSheet.create do |s|
52
+ s.table('My table') do |t|
53
+ t.row
54
+ end
55
+ end
56
+
57
+ output.should have_tag('//table:table/*')
58
+ output.should have_tag('//table:table-row')
59
+ end
60
+
61
+ it "should allow styles to be added" do
62
+ ODF::SpreadSheet.create.should_not have_tag('//office:automatic-styles')
63
+ output = ODF::SpreadSheet.create do |s|
64
+ s.style 'even-row-cell', :family => :cell
65
+ end
66
+
67
+ output.should have_tag('//office:automatic-styles/*', :count => 1)
68
+ output.should have_tag('//style:style')
69
+ Hpricot(output).at('//style:style')['style:name'].should == 'even-row-cell'
70
+ Hpricot(output).at('//style:style')['style:family'].should == 'table-cell'
71
+ end
72
+ end
73
+
@@ -0,0 +1,44 @@
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 File.expand_path(File.dirname(__FILE__) + '/spec_helper')
19
+
20
+ require 'odf/style'
21
+
22
+ describe ODF::Style do
23
+ it "should output properties when they're added" do
24
+ ODF::Style.create.should_not have_tag('//style:style/*')
25
+
26
+ output = ODF::Style.create 'odd-row-cell', :family => :cell do |s|
27
+ s.property :cell, 'background-color' => '#b3b3b3',
28
+ 'border' => '0.002cm solid #000000'
29
+ s.property :text, 'color' => '#4c4c4c'
30
+ end
31
+
32
+ output.should have_tag('//style:style/*', :count => 2)
33
+ output.should have_tag('//style:table-cell-properties')
34
+ output.should have_tag('//style:text-properties')
35
+
36
+ cell_elem = Hpricot(output).at('style:table-cell-properties')
37
+ cell_elem['fo:background-color'].should == '#b3b3b3'
38
+ cell_elem['fo:border'].should == '0.002cm solid #000000'
39
+
40
+ text_elem = Hpricot(output).at('style:text-properties')
41
+ text_elem['fo:color'].should == '#4c4c4c'
42
+ end
43
+ end
44
+
@@ -0,0 +1,48 @@
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 File.expand_path(File.dirname(__FILE__) + '/spec_helper')
19
+
20
+ require 'odf/table'
21
+
22
+ describe ODF::Table do
23
+ it "should allow rows to be added" do
24
+ output = ODF::Table.create('Example') {|t| }
25
+ output.should have_tag('//table:table')
26
+ output.should_not have_tag('//table:table/*')
27
+
28
+ output = ODF::Table.create('MyTable') {|t| t.row }
29
+ output.should have_tag('//table:table/*', :count => 1)
30
+ output.should have_tag('//table:table-row')
31
+
32
+ output = ODF::Table.create('MyTable') {|t|
33
+ t.row
34
+ t.row
35
+ }
36
+ output.should have_tag('//table:table/*', :count => 2)
37
+ output.should have_tag('//table:table-row')
38
+ end
39
+
40
+ it "should provide row numbers" do
41
+ output = ODF::Table.create('Row letter table') {|t|
42
+ t.row {|row| row.cell}
43
+ t.row {|row| row.cell(row.number)}
44
+ }
45
+ output.should have_tag('text:p')
46
+ Hpricot(output).at('text:p').innerHTML.should == '2'
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rodf
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Thiago Arrais
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-22 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: builder
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rubyzip
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.1
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: activesupport
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.0
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: rspec_hpricot_matchers
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "1.0"
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: echoe
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.0.2
64
+ version:
65
+ description: ODF generation library for Ruby
66
+ email: thiago.arrais@gmail.com
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - lib/odf/row.rb
73
+ - lib/odf/spreadsheet.rb
74
+ - lib/odf/cell.rb
75
+ - lib/odf/table.rb
76
+ - lib/odf/property.rb
77
+ - lib/odf/style.rb
78
+ - lib/odf/skeleton/manifest.xml
79
+ - lib/odf/skeleton/styles.xml
80
+ - lib/odf/container.rb
81
+ - CHANGELOG
82
+ - README.rdoc
83
+ - LICENSE.LGPL
84
+ files:
85
+ - lib/odf/row.rb
86
+ - lib/odf/spreadsheet.rb
87
+ - lib/odf/cell.rb
88
+ - lib/odf/table.rb
89
+ - lib/odf/property.rb
90
+ - lib/odf/style.rb
91
+ - lib/odf/skeleton/manifest.xml
92
+ - lib/odf/skeleton/styles.xml
93
+ - lib/odf/container.rb
94
+ - CHANGELOG
95
+ - README.rdoc
96
+ - Rakefile
97
+ - LICENSE.LGPL
98
+ - spec/cell_spec.rb
99
+ - spec/spreadsheet_spec.rb
100
+ - spec/spec_helper.rb
101
+ - spec/row_spec.rb
102
+ - spec/table_spec.rb
103
+ - spec/style_spec.rb
104
+ - spec/property_spec.rb
105
+ - Manifest
106
+ - rodf.gemspec
107
+ has_rdoc: true
108
+ homepage: http://github.com/thiagoarrais/rodf/tree
109
+ post_install_message:
110
+ rdoc_options:
111
+ - --line-numbers
112
+ - --inline-source
113
+ - --title
114
+ - Rodf
115
+ - --main
116
+ - README.rdoc
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: "0"
124
+ version:
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: "1.2"
130
+ version:
131
+ requirements: []
132
+
133
+ rubyforge_project: rodf
134
+ rubygems_version: 1.3.1
135
+ signing_key:
136
+ specification_version: 2
137
+ summary: ODF generation library for Ruby
138
+ test_files: []
139
+