rodf 0.1.8 → 0.2.0
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/Manifest +16 -1
- data/README.rdoc +3 -3
- data/lib/odf/cell.rb +24 -11
- data/lib/odf/document.rb +48 -0
- data/lib/odf/hyperlink.rb +51 -0
- data/lib/odf/master_page.rb +33 -0
- data/lib/odf/page_layout.rb +39 -0
- data/lib/odf/paragraph.rb +46 -0
- data/lib/odf/paragraph_container.rb +35 -0
- data/lib/odf/property.rb +3 -2
- data/lib/odf/skeleton.rb +34 -0
- data/lib/odf/skeleton/{manifest.xml → manifest.xml.erb} +2 -2
- data/lib/odf/span.rb +69 -0
- data/lib/odf/spreadsheet.rb +6 -20
- data/lib/odf/style.rb +4 -1
- data/lib/odf/text.rb +64 -0
- data/rodf.gemspec +4 -4
- data/spec/cell_spec.rb +24 -5
- data/spec/hyperlink_spec.rb +53 -0
- data/spec/master_page_spec.rb +35 -0
- data/spec/page_layout_spec.rb +37 -0
- data/spec/paragraph_spec.rb +75 -0
- data/spec/property_spec.rb +19 -0
- data/spec/span_spec.rb +65 -0
- data/spec/style_spec.rb +18 -1
- data/spec/text_spec.rb +71 -0
- metadata +30 -6
data/Manifest
CHANGED
@@ -7,21 +7,36 @@ lib/odf/cell.rb
|
|
7
7
|
lib/odf/column.rb
|
8
8
|
lib/odf/container.rb
|
9
9
|
lib/odf/data_style.rb
|
10
|
+
lib/odf/document.rb
|
11
|
+
lib/odf/hyperlink.rb
|
12
|
+
lib/odf/master_page.rb
|
13
|
+
lib/odf/page_layout.rb
|
14
|
+
lib/odf/paragraph.rb
|
15
|
+
lib/odf/paragraph_container.rb
|
10
16
|
lib/odf/property.rb
|
11
17
|
lib/odf/row.rb
|
12
|
-
lib/odf/skeleton
|
18
|
+
lib/odf/skeleton.rb
|
19
|
+
lib/odf/skeleton/manifest.xml.erb
|
13
20
|
lib/odf/skeleton/styles.xml
|
21
|
+
lib/odf/span.rb
|
14
22
|
lib/odf/spreadsheet.rb
|
15
23
|
lib/odf/style.rb
|
16
24
|
lib/odf/style_section.rb
|
17
25
|
lib/odf/table.rb
|
26
|
+
lib/odf/text.rb
|
18
27
|
rodf.gemspec
|
19
28
|
spec/cell_spec.rb
|
20
29
|
spec/data_style_spec.rb
|
30
|
+
spec/hyperlink_spec.rb
|
31
|
+
spec/master_page_spec.rb
|
32
|
+
spec/page_layout_spec.rb
|
33
|
+
spec/paragraph_spec.rb
|
21
34
|
spec/property_spec.rb
|
22
35
|
spec/row_spec.rb
|
36
|
+
spec/span_spec.rb
|
23
37
|
spec/spec_helper.rb
|
24
38
|
spec/spreadsheet_spec.rb
|
25
39
|
spec/style_section_spec.rb
|
26
40
|
spec/style_spec.rb
|
27
41
|
spec/table_spec.rb
|
42
|
+
spec/text_spec.rb
|
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= rODF
|
2
2
|
|
3
3
|
This is a library for writing to ODF output with Ruby. It currently only
|
4
|
-
supports creating spreadsheets (ODS)
|
4
|
+
supports creating spreadsheets (ODS) and text documents (ODT). Slide shows (ODP)
|
5
5
|
may be added some time in the future.
|
6
6
|
|
7
7
|
This is NOT an ODF reading library.
|
@@ -18,7 +18,7 @@ rODF works pretty much like Builder, but with ODF-aware constructs. Try this:
|
|
18
18
|
|
19
19
|
require 'odf/spreadsheet'
|
20
20
|
|
21
|
-
ODF::
|
21
|
+
ODF::Spreadsheet.file("my-spreadsheet.ods") do |spreadsheet|
|
22
22
|
spreadsheet.table 'My first table from Ruby' do |table|
|
23
23
|
table.row {|row| row.cell 'Hello, rODF world!' }
|
24
24
|
end
|
@@ -28,7 +28,7 @@ Some basic formatting is also possible:
|
|
28
28
|
|
29
29
|
require 'odf/spreadsheet'
|
30
30
|
|
31
|
-
ODF::
|
31
|
+
ODF::Spreadsheet.file("my-spreadsheet.ods") do |spreadsheet|
|
32
32
|
spreadsheet.style 'red-cell', :family => :cell do |style|
|
33
33
|
style.property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
|
34
34
|
end
|
data/lib/odf/cell.rb
CHANGED
@@ -18,8 +18,15 @@
|
|
18
18
|
require 'rubygems'
|
19
19
|
require 'builder'
|
20
20
|
|
21
|
+
require 'odf/container'
|
22
|
+
require 'odf/paragraph'
|
23
|
+
|
21
24
|
module ODF
|
22
|
-
class Cell
|
25
|
+
class Cell < Container
|
26
|
+
contains :paragraphs
|
27
|
+
|
28
|
+
alias :p :paragraph
|
29
|
+
|
23
30
|
def initialize(*args)
|
24
31
|
value = args.first || ''
|
25
32
|
opts = args.last.instance_of?(Hash) ? args.last : {}
|
@@ -36,25 +43,21 @@ module ODF
|
|
36
43
|
|
37
44
|
@elem_attrs = make_element_attributes(@type, @value, opts)
|
38
45
|
@mutiply = (opts[:span] || 1).to_i
|
46
|
+
|
47
|
+
make_value_paragraph
|
39
48
|
end
|
40
49
|
|
41
50
|
def xml
|
42
51
|
markup = Builder::XmlMarkup.new
|
43
52
|
text = markup.tag! 'table:table-cell', @elem_attrs do |xml|
|
44
|
-
|
45
|
-
xml.text:p do |p|
|
46
|
-
if contains_url?
|
47
|
-
p.text:a, @value, 'xlink:href' => @url
|
48
|
-
else
|
49
|
-
p.text! @value
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
+
xml << paragraphs_xml
|
53
54
|
end
|
54
55
|
(@mutiply - 1).times {text = markup.tag! 'table:table-cell'}
|
55
56
|
text
|
56
57
|
end
|
57
58
|
|
59
|
+
private
|
60
|
+
|
58
61
|
def contains_string?
|
59
62
|
:string == @type && !@value.nil? && !@value.empty?
|
60
63
|
end
|
@@ -76,7 +79,17 @@ module ODF
|
|
76
79
|
attrs
|
77
80
|
end
|
78
81
|
|
79
|
-
|
82
|
+
def make_value_paragraph
|
83
|
+
if contains_string?
|
84
|
+
paragraph do |p|
|
85
|
+
if contains_url?
|
86
|
+
p.link @value, :href => @url
|
87
|
+
else
|
88
|
+
p << @value
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
80
93
|
|
81
94
|
def empty(value)
|
82
95
|
value.nil? || value.empty?
|
data/lib/odf/document.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright (c) 2010 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 'zip/zip'
|
21
|
+
|
22
|
+
require 'odf/container'
|
23
|
+
require 'odf/skeleton'
|
24
|
+
|
25
|
+
module ODF
|
26
|
+
class Document < Container
|
27
|
+
def self.file(ods_file_name)
|
28
|
+
ods_file = Zip::ZipFile.open(ods_file_name, Zip::ZipFile::CREATE)
|
29
|
+
ods_file.get_output_stream('styles.xml') {|f| f << skeleton.styles }
|
30
|
+
ods_file.get_output_stream('META-INF/manifest.xml') {|f| f << skeleton.manifest(doc_type) }
|
31
|
+
|
32
|
+
yield(doc = new)
|
33
|
+
|
34
|
+
ods_file.get_output_stream('content.xml') {|f| f << doc.xml}
|
35
|
+
|
36
|
+
ods_file.close
|
37
|
+
end
|
38
|
+
private
|
39
|
+
def self.skeleton
|
40
|
+
@skeleton ||= Skeleton.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.doc_type
|
44
|
+
name.split('::').last.downcase
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright (c) 2010 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/paragraph_container'
|
22
|
+
|
23
|
+
module ODF
|
24
|
+
class Hyperlink < ParagraphContainer
|
25
|
+
def initialize(first, second = {})
|
26
|
+
if second.instance_of?(Hash) && second.empty?
|
27
|
+
@href = first
|
28
|
+
else
|
29
|
+
span(first)
|
30
|
+
@href = second.instance_of?(Hash) ? second[:href] : second
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def xml
|
35
|
+
Builder::XmlMarkup.new.text:a, 'xlink:href' => @href do |a|
|
36
|
+
a << content_parts_xml
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class ParagraphContainer < Container
|
42
|
+
def link(*args)
|
43
|
+
l = Hyperlink.new(*args)
|
44
|
+
yield l if block_given?
|
45
|
+
content_parts << l
|
46
|
+
l
|
47
|
+
end
|
48
|
+
alias a link
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright (c) 2010 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 MasterPage
|
23
|
+
def initialize(name, opts = {})
|
24
|
+
@name, @layout = name, opts[:layout]
|
25
|
+
end
|
26
|
+
|
27
|
+
def xml
|
28
|
+
Builder::XmlMarkup.new.tag! 'style:master-page',
|
29
|
+
'style:name' => @name, 'style:page-layout-name' => @layout
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright (c) 2010 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 PageLayout < Container
|
26
|
+
contains :properties
|
27
|
+
|
28
|
+
def initialize(name)
|
29
|
+
@name = name
|
30
|
+
end
|
31
|
+
|
32
|
+
def xml
|
33
|
+
Builder::XmlMarkup.new.tag! 'style:page-layout', 'style:name' => @name do |b|
|
34
|
+
b << properties_xml
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright (c) 2010 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/paragraph_container'
|
22
|
+
|
23
|
+
module ODF
|
24
|
+
class Paragraph < ParagraphContainer
|
25
|
+
def initialize(fst = nil, snd = {})
|
26
|
+
first_is_hash = fst.instance_of? Hash
|
27
|
+
span(fst) unless first_is_hash
|
28
|
+
@elem_attrs = make_element_attributes(first_is_hash ? fst : snd)
|
29
|
+
end
|
30
|
+
|
31
|
+
def xml
|
32
|
+
Builder::XmlMarkup.new.text:p, @elem_attrs do |xml|
|
33
|
+
xml << content_parts_xml
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def make_element_attributes(opts)
|
40
|
+
attrs = {}
|
41
|
+
attrs['text:style-name'] = opts[:style] unless opts[:style].nil?
|
42
|
+
attrs
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Copyright (c) 2010 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
|
+
|
23
|
+
module ODF
|
24
|
+
# Container for all kinds of paragraph content
|
25
|
+
class ParagraphContainer < Container
|
26
|
+
def content_parts
|
27
|
+
@content_parts ||= []
|
28
|
+
end
|
29
|
+
|
30
|
+
def content_parts_xml
|
31
|
+
content_parts.map {|p| p.xml}.join
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/lib/odf/property.rb
CHANGED
@@ -24,15 +24,16 @@ module ODF
|
|
24
24
|
:text => 'style:text-properties',
|
25
25
|
:column => 'style:table-column-properties'}
|
26
26
|
TRANSLATED_SPECS = [:border_color, :border_style, :border_width]
|
27
|
+
STYLE_ATTRIBUTES = ['column-width', 'rotation-angle', 'text-underline-type']
|
27
28
|
|
28
29
|
def initialize(type, specs={})
|
29
|
-
@name = PROPERTY_NAMES[type]
|
30
|
+
@name = PROPERTY_NAMES[type] || "style:#{type}-properties"
|
30
31
|
@specs = translate(specs).map { |k, v| [k.to_s, v] }
|
31
32
|
end
|
32
33
|
|
33
34
|
def xml
|
34
35
|
specs = @specs.inject({}) do |acc, kv|
|
35
|
-
prefix =
|
36
|
+
prefix = STYLE_ATTRIBUTES.include?(kv.first) ? 'style' : 'fo'
|
36
37
|
acc.merge prefix + ':' + kv.first => kv.last
|
37
38
|
end
|
38
39
|
Builder::XmlMarkup.new.tag! @name, specs
|
data/lib/odf/skeleton.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright (c) 2010 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 'erb'
|
19
|
+
|
20
|
+
module ODF
|
21
|
+
class Skeleton
|
22
|
+
def manifest(document_type)
|
23
|
+
ERB.new(template('manifest.xml.erb')).result(binding)
|
24
|
+
end
|
25
|
+
|
26
|
+
def styles
|
27
|
+
template('styles.xml')
|
28
|
+
end
|
29
|
+
private
|
30
|
+
def template(fname)
|
31
|
+
File.open(File.dirname(__FILE__) + '/skeleton/' + fname).read
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd">
|
3
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.
|
4
|
+
<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.<%= document_type.to_s %>" manifest:full-path="/"/>
|
5
5
|
<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>
|
6
6
|
<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>
|
7
|
-
</manifest:manifest>
|
7
|
+
</manifest:manifest>
|
data/lib/odf/span.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Copyright (c) 2010 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/paragraph_container'
|
22
|
+
|
23
|
+
module ODF
|
24
|
+
class TextNode
|
25
|
+
def initialize(content)
|
26
|
+
@content = content
|
27
|
+
end
|
28
|
+
|
29
|
+
def xml
|
30
|
+
@content.to_s.to_xs
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Span < ParagraphContainer
|
35
|
+
def initialize(first, second = nil)
|
36
|
+
if first.instance_of?(Symbol)
|
37
|
+
@style = first
|
38
|
+
content_parts << TextNode.new(second) unless second.nil?
|
39
|
+
else
|
40
|
+
content_parts << TextNode.new(first)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def xml
|
45
|
+
return content_parts_xml if @style.nil?
|
46
|
+
Builder::XmlMarkup.new.text:span, 'text:style-name' => @style do |xml|
|
47
|
+
xml << content_parts_xml
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class ParagraphContainer < Container
|
53
|
+
def span(*args)
|
54
|
+
s = Span.new(*args)
|
55
|
+
yield s if block_given?
|
56
|
+
content_parts << s
|
57
|
+
s
|
58
|
+
end
|
59
|
+
|
60
|
+
def <<(content)
|
61
|
+
span(content)
|
62
|
+
end
|
63
|
+
|
64
|
+
def method_missing(style, *args)
|
65
|
+
span(style, *args)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/lib/odf/spreadsheet.rb
CHANGED
@@ -18,29 +18,18 @@
|
|
18
18
|
require 'rubygems'
|
19
19
|
|
20
20
|
require 'builder'
|
21
|
-
require 'zip/zip'
|
22
21
|
|
23
|
-
require 'odf/container'
|
24
22
|
require 'odf/data_style'
|
23
|
+
require 'odf/document'
|
24
|
+
require 'odf/hyperlink'
|
25
|
+
require 'odf/span'
|
25
26
|
require 'odf/style'
|
26
27
|
require 'odf/table'
|
27
28
|
|
28
29
|
module ODF
|
29
|
-
class
|
30
|
+
class Spreadsheet < Document
|
30
31
|
contains :tables, :styles, :data_styles
|
31
32
|
|
32
|
-
def self.file(ods_file_name)
|
33
|
-
ods_file = Zip::ZipFile.open(ods_file_name, Zip::ZipFile::CREATE)
|
34
|
-
ods_file.get_output_stream('styles.xml') {|f| f << skeleton('styles.xml')}
|
35
|
-
ods_file.get_output_stream('META-INF/manifest.xml') {|f| f << skeleton('manifest.xml')}
|
36
|
-
|
37
|
-
yield(spreadsheet = new)
|
38
|
-
|
39
|
-
ods_file.get_output_stream('content.xml') {|f| f << spreadsheet.xml}
|
40
|
-
|
41
|
-
ods_file.close
|
42
|
-
end
|
43
|
-
|
44
33
|
def xml
|
45
34
|
b = Builder::XmlMarkup.new
|
46
35
|
|
@@ -65,11 +54,8 @@ module ODF
|
|
65
54
|
end
|
66
55
|
end
|
67
56
|
end
|
68
|
-
|
69
|
-
private
|
70
|
-
def self.skeleton(fname)
|
71
|
-
File.open(File.dirname(__FILE__) + '/skeleton/' + fname).read
|
72
|
-
end
|
73
57
|
end
|
58
|
+
|
59
|
+
SpreadSheet = Spreadsheet
|
74
60
|
end
|
75
61
|
|
data/lib/odf/style.rb
CHANGED
@@ -39,9 +39,12 @@ module ODF
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def make_element_attributes(name, opts)
|
42
|
-
attrs = {
|
42
|
+
attrs = {
|
43
|
+
'style:name' => name,
|
44
|
+
'style:family' => (FAMILIES[opts[:family]] || opts[:family])}
|
43
45
|
attrs['style:data-style-name'] = opts[:data_style] unless opts[:data_style].nil?
|
44
46
|
attrs['style:parent-style-name'] = opts[:parent].to_s unless opts[:parent].nil?
|
47
|
+
attrs['style:master-page-name'] = opts[:master_page] unless opts[:master_page].nil?
|
45
48
|
attrs
|
46
49
|
end
|
47
50
|
|
data/lib/odf/text.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Copyright (c) 2010 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
|
+
|
22
|
+
require 'odf/document'
|
23
|
+
require 'odf/master_page'
|
24
|
+
require 'odf/page_layout'
|
25
|
+
require 'odf/paragraph'
|
26
|
+
require 'odf/span'
|
27
|
+
require 'odf/hyperlink'
|
28
|
+
require 'odf/style'
|
29
|
+
|
30
|
+
module ODF
|
31
|
+
class Text < Document
|
32
|
+
contains :paragraphs, :styles, :page_layouts, :master_pages
|
33
|
+
|
34
|
+
alias :p :paragraph
|
35
|
+
|
36
|
+
def xml
|
37
|
+
b = Builder::XmlMarkup.new
|
38
|
+
|
39
|
+
b.instruct! :xml, :version => '1.0', :encoding => 'UTF-8'
|
40
|
+
b.tag! 'office:document-content', 'xmlns:office' => "urn:oasis:names:tc:opendocument:xmlns:office:1.0",
|
41
|
+
'xmlns:table' => "urn:oasis:names:tc:opendocument:xmlns:table:1.0",
|
42
|
+
'xmlns:text' => "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
|
43
|
+
'xmlns:oooc' => "http://openoffice.org/2004/calc",
|
44
|
+
'xmlns:style' => "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
|
45
|
+
'xmlns:fo' => "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
|
46
|
+
'xmlns:xlink' => "http://www.w3.org/1999/xlink" do
|
47
|
+
|xml|
|
48
|
+
xml.tag! 'office:automatic-styles' do
|
49
|
+
xml << styles_xml
|
50
|
+
xml << page_layouts_xml
|
51
|
+
end unless styles.empty? && page_layouts.empty?
|
52
|
+
xml.tag! 'office:master-styles' do
|
53
|
+
xml << master_pages_xml
|
54
|
+
end unless master_pages.empty?
|
55
|
+
xml.office:body do
|
56
|
+
xml.office:text do
|
57
|
+
xml << paragraphs_xml
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
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.
|
5
|
+
s.version = "0.2.0"
|
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{2010-
|
9
|
+
s.date = %q{2010-05-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 = ["CHANGELOG", "LICENSE.LGPL", "README.rdoc", "lib/odf/cell.rb", "lib/odf/column.rb", "lib/odf/container.rb", "lib/odf/data_style.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_section.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/data_style.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_section.rb", "lib/odf/style.rb", "lib/odf/table.rb", "rodf.gemspec", "spec/cell_spec.rb", "spec/data_style_spec.rb", "spec/property_spec.rb", "spec/row_spec.rb", "spec/spec_helper.rb", "spec/spreadsheet_spec.rb", "spec/style_section_spec.rb", "spec/style_spec.rb", "spec/table_spec.rb"]
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE.LGPL", "README.rdoc", "lib/odf/cell.rb", "lib/odf/column.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_section.rb", "lib/odf/style.rb", "lib/odf/table.rb", "lib/odf/text.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/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_section.rb", "lib/odf/style.rb", "lib/odf/table.rb", "lib/odf/text.rb", "rodf.gemspec", "spec/cell_spec.rb", "spec/data_style_spec.rb", "spec/hyperlink_spec.rb", "spec/master_page_spec.rb", "spec/page_layout_spec.rb", "spec/paragraph_spec.rb", "spec/property_spec.rb", "spec/row_spec.rb", "spec/span_spec.rb", "spec/spec_helper.rb", "spec/spreadsheet_spec.rb", "spec/style_section_spec.rb", "spec/style_spec.rb", "spec/table_spec.rb", "spec/text_spec.rb"]
|
14
14
|
s.homepage = %q{http://github.com/thiagoarrais/rodf/tree}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rodf", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
data/spec/cell_spec.rb
CHANGED
@@ -125,11 +125,29 @@ describe ODF::Cell do
|
|
125
125
|
at('table:table-cell')['office:date-value'] = '2010-04-16'
|
126
126
|
end
|
127
127
|
|
128
|
-
it "should
|
129
|
-
|
130
|
-
|
131
|
-
output.
|
132
|
-
|
128
|
+
it "should contain paragraph" do
|
129
|
+
c = ODF::Cell.new
|
130
|
+
c.paragraph "testing"
|
131
|
+
output = c.xml
|
132
|
+
|
133
|
+
output.should have_tag("//table:table-cell/*", :count => 1)
|
134
|
+
output.should have_tag("//text:p")
|
135
|
+
|
136
|
+
Hpricot(output).at('text:p').innerHTML.should == 'testing'
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should be able to hold multiple paragraphs" do
|
140
|
+
output = ODF::Cell.create do |c|
|
141
|
+
c.paragraph "first"
|
142
|
+
c.paragraph "second"
|
143
|
+
end
|
144
|
+
|
145
|
+
output.should have_tag("//table:table-cell/*", :count => 2)
|
146
|
+
output.should have_tag("//text:p")
|
147
|
+
|
148
|
+
ps = Hpricot(output).search('text:p')
|
149
|
+
ps[0].innerHTML.should == 'first'
|
150
|
+
ps[1].innerHTML.should == 'second'
|
133
151
|
end
|
134
152
|
|
135
153
|
it "should not render value type for non-string nil values" do
|
@@ -145,3 +163,4 @@ describe ODF::Cell do
|
|
145
163
|
end
|
146
164
|
end
|
147
165
|
end
|
166
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright (c) 2010 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/hyperlink'
|
21
|
+
|
22
|
+
describe ODF::Hyperlink do
|
23
|
+
it "should receive content text in first argument" do
|
24
|
+
output = ODF::Hyperlink.new('link somewhere', :href => 'http://www.example.org/').xml
|
25
|
+
output.should have_tag('//text:a')
|
26
|
+
|
27
|
+
link = Hpricot(output).at('text:a')
|
28
|
+
link.innerHTML.should == 'link somewhere'
|
29
|
+
link['xlink:href'].should == 'http://www.example.org/'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should accept ref both in second argument as in argument hash" do
|
33
|
+
Hpricot(ODF::Hyperlink.new('link somewhere', :href => 'http://www.example.org/').xml).
|
34
|
+
at('text:a')['xlink:href'].should == 'http://www.example.org/'
|
35
|
+
|
36
|
+
Hpricot(ODF::Hyperlink.new('link somewhere', 'http://www.example.org/').xml).
|
37
|
+
at('text:a')['xlink:href'].should == 'http://www.example.org/'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should allow nested span elements" do
|
41
|
+
output = ODF::Hyperlink.create 'http://www.example.com/' do |link|
|
42
|
+
link.strong 'important link'
|
43
|
+
end
|
44
|
+
|
45
|
+
output.should have_tag('//text:a/*', :count => 1)
|
46
|
+
tree = Hpricot(output)
|
47
|
+
tree.at('//text:a')['xlink:href'].should == 'http://www.example.com/'
|
48
|
+
span = tree.at('//text:span')
|
49
|
+
span['text:style-name'].should == 'strong'
|
50
|
+
span.innerHTML.should == 'important link'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Copyright (c) 2010 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/master_page'
|
21
|
+
|
22
|
+
describe ODF::MasterPage do
|
23
|
+
it "should have a name" do
|
24
|
+
output = ODF::MasterPage.new('my-master-page').xml
|
25
|
+
output.should have_tag('//style:master-page')
|
26
|
+
|
27
|
+
Hpricot(output).at('style:master-page')['style:name'].should == 'my-master-page'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should accept a layout reference" do
|
31
|
+
Hpricot(ODF::MasterPage.new('my-master-page', :layout => 'A4').xml).
|
32
|
+
at('style:master-page')['style:page-layout-name'].should == 'A4'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (c) 2010 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/page_layout'
|
21
|
+
|
22
|
+
describe ODF::PageLayout do
|
23
|
+
it "should have a name" do
|
24
|
+
output = ODF::PageLayout.new('main-layout').xml
|
25
|
+
output.should have_tag('style:page-layout')
|
26
|
+
Hpricot(output).at('style:page-layout')['style:name'].should == 'main-layout'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have properties" do
|
30
|
+
output = ODF::PageLayout.create 'main-layout' do |l|
|
31
|
+
l.property 'page-layout'
|
32
|
+
end
|
33
|
+
output.should have_tag('//style:page-layout/*', :count => 1)
|
34
|
+
output.should have_tag('style:page-layout-properties')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Copyright (c) 2010 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/paragraph'
|
21
|
+
|
22
|
+
describe ODF::Paragraph do
|
23
|
+
it "should allow text content inside" do
|
24
|
+
output = ODF::Paragraph.new('Hello').xml
|
25
|
+
output.should have_tag('//text:p')
|
26
|
+
Hpricot(output).at('text:p').innerHTML.should == 'Hello'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should accept an input sequence" do
|
30
|
+
output = ODF::Paragraph.create { |p|
|
31
|
+
p << "Hello, "
|
32
|
+
p << "world!"
|
33
|
+
}
|
34
|
+
output.should have_tag('//text:p')
|
35
|
+
Hpricot(output).at('text:p').innerHTML.should == 'Hello, world!'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should accept styled spans" do
|
39
|
+
output = ODF::Paragraph.create { |p|
|
40
|
+
p << "Hello, "
|
41
|
+
p.span :bold, "world! "
|
42
|
+
p << "This is not bold. "
|
43
|
+
p.bold "But this is."
|
44
|
+
}
|
45
|
+
spans = Hpricot(output).at('text:p').search('text:span')
|
46
|
+
spans.first.innerHTML.should == 'world! '
|
47
|
+
spans.first['text:style-name'].should == 'bold'
|
48
|
+
spans.last.innerHTML.should == 'But this is.'
|
49
|
+
spans.last['text:style-name'].should == 'bold'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be able to hold hyperlinks" do
|
53
|
+
output = ODF::Paragraph.create {|p|
|
54
|
+
p << "please visit "
|
55
|
+
p.a "example.org", :href => "http://www.example.org/"
|
56
|
+
p << " for more details"
|
57
|
+
}
|
58
|
+
output.should have_tag("//text:p/*", :count => 3)
|
59
|
+
output.should have_tag("//text:a")
|
60
|
+
|
61
|
+
Hpricot(output).at('text:a').innerHTML.should == 'example.org'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should support style attribute" do
|
65
|
+
Hpricot(ODF::Paragraph.create('styled paragraph', :style => 'highlight')).
|
66
|
+
at('text:p')['text:style-name'].should == 'highlight'
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should accept attributes in the first parameter too" do
|
70
|
+
para = Hpricot(ODF::Paragraph.create(:style => 'testing')).at('text:p')
|
71
|
+
para.innerHTML.should be_empty
|
72
|
+
para['text:style-name'].should == 'testing'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
data/spec/property_spec.rb
CHANGED
@@ -36,6 +36,15 @@ describe ODF::Property do
|
|
36
36
|
elem['style:column-width'].should == '2cm'
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should prefix rotation-angle property with style namespace" do
|
40
|
+
property = ODF::Property.new :cell, 'rotation-angle' => '-90'
|
41
|
+
|
42
|
+
property.xml.should have_tag('//style:table-cell-properties')
|
43
|
+
|
44
|
+
elem = Hpricot(property.xml).at('//style:table-cell-properties')
|
45
|
+
elem['style:rotation-angle'].should == '-90'
|
46
|
+
end
|
47
|
+
|
39
48
|
it "should accept full perimeter border specs" do
|
40
49
|
property = ODF::Property.new :cell, :border => "0.025in solid #000000"
|
41
50
|
|
@@ -109,5 +118,15 @@ describe ODF::Property do
|
|
109
118
|
elem = Hpricot(property.xml).at('//style:table-cell-properties')
|
110
119
|
elem['fo:border-left'].should == "0.1in solid #ffff00"
|
111
120
|
end
|
121
|
+
|
122
|
+
it "should prefix underline property with style namespace" do
|
123
|
+
Hpricot(ODF::Property.new(:text, 'text-underline-type' => 'single').xml).
|
124
|
+
at('style:text-properties')['style:text-underline-type'].should == 'single'
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should support paragraph properties" do
|
128
|
+
ODF::Property.new(:paragraph).xml.
|
129
|
+
should have_tag('style:paragraph-properties')
|
130
|
+
end
|
112
131
|
end
|
113
132
|
|
data/spec/span_spec.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Copyright (c) 2010 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/span'
|
21
|
+
|
22
|
+
describe ODF::Span do
|
23
|
+
it "should print non-styled spans in pure text" do
|
24
|
+
ODF::Span.new('no style').xml.should == 'no style'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should wrap styled output in span tags" do
|
28
|
+
output = ODF::Span.new(:italics, 'styled text').xml
|
29
|
+
output.should have_tag('text:span')
|
30
|
+
span = Hpricot(output).at('text:span')
|
31
|
+
span['text:style-name'].should == 'italics'
|
32
|
+
span.innerHTML.should == 'styled text'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should allow nesting" do
|
36
|
+
output = ODF::Span.create :bold do |s|
|
37
|
+
s.italics 'highlighted text'
|
38
|
+
end
|
39
|
+
|
40
|
+
output.should have_tag('//text:span/*', :count => 2)
|
41
|
+
Hpricot(output).search('//text:span')[1].
|
42
|
+
innerHTML.should == 'highlighted text'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should allow links" do
|
46
|
+
output = ODF::Span.create :bold do |s|
|
47
|
+
s.link 'there', 'http://www.example.org/'
|
48
|
+
s << ' and '
|
49
|
+
s.a 'back again', 'http://www.example.com/'
|
50
|
+
end
|
51
|
+
|
52
|
+
output.should have_tag('//text:a', :count => 2)
|
53
|
+
elem = Hpricot(output)
|
54
|
+
|
55
|
+
links = elem.search('//text:a')
|
56
|
+
links.first.innerHTML.should == 'there'
|
57
|
+
links.last.innerHTML.should == 'back again'
|
58
|
+
|
59
|
+
elem.at('//text:span').children[1].to_plain_text.should == " and "
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should escape entities" do
|
63
|
+
ODF::Span.create('Fish & Chips').should == 'Fish & Chips'
|
64
|
+
end
|
65
|
+
end
|
data/spec/style_spec.rb
CHANGED
@@ -26,7 +26,7 @@ describe ODF::Style do
|
|
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'
|
29
|
-
s.property :text, 'color' => '#4c4c4c'
|
29
|
+
s.property :text, 'color' => '#4c4c4c', 'font-weight' => 'bold'
|
30
30
|
end
|
31
31
|
|
32
32
|
output.should have_tag('//style:style/*', :count => 2)
|
@@ -39,6 +39,7 @@ describe ODF::Style do
|
|
39
39
|
|
40
40
|
text_elem = Hpricot(output).at('style:text-properties')
|
41
41
|
text_elem['fo:color'].should == '#4c4c4c'
|
42
|
+
text_elem['fo:font-weight'].should == 'bold'
|
42
43
|
end
|
43
44
|
|
44
45
|
it "should allow data styles" do
|
@@ -64,6 +65,14 @@ describe ODF::Style do
|
|
64
65
|
style['style:parent-style-name'].should == 'cell-default'
|
65
66
|
end
|
66
67
|
|
68
|
+
it "should allow master pages" do
|
69
|
+
xml = ODF::Style.create 'standard',
|
70
|
+
:family => :paragraph,
|
71
|
+
:master_page => 'letter'
|
72
|
+
|
73
|
+
Hpricot(xml).at('//style:style')['style:master-page-name'].should == 'letter'
|
74
|
+
end
|
75
|
+
|
67
76
|
it "should be able to describe column styles" do
|
68
77
|
xml = ODF::Style.create 'column-style', :family => :column do |style|
|
69
78
|
style.property :column, 'column-width' => '2cm'
|
@@ -73,5 +82,13 @@ describe ODF::Style do
|
|
73
82
|
xml.should have_tag('//style:style/*', :count => 1)
|
74
83
|
xml.should have_tag('//style:table-column-properties')
|
75
84
|
end
|
85
|
+
|
86
|
+
it "should accept other families" do
|
87
|
+
Hpricot(ODF::Style.create('text-style', :family => :text)).
|
88
|
+
at('//style:style')['style:family'].should == 'text'
|
89
|
+
|
90
|
+
Hpricot(ODF::Style.create('text-style', :family => :paragraph)).
|
91
|
+
at('//style:style')['style:family'].should == 'paragraph'
|
92
|
+
end
|
76
93
|
end
|
77
94
|
|
data/spec/text_spec.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Copyright (c) 2010 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/text'
|
21
|
+
|
22
|
+
describe ODF::Text do
|
23
|
+
it "should have the expected structure" do
|
24
|
+
output = ODF::Text.create
|
25
|
+
output.should have_tag('//office:document-content/*')
|
26
|
+
output.should have_tag('//office:body/*')
|
27
|
+
output.should have_tag('//office:text')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have paragraphs" do
|
31
|
+
output = ODF::Text.create { |doc|
|
32
|
+
doc.paragraph "Hello"
|
33
|
+
doc.p "World!"
|
34
|
+
}
|
35
|
+
output.should have_tag('//office:text/*')
|
36
|
+
output.should have_tag('//text:p')
|
37
|
+
ps = Hpricot(output).search('text:p')
|
38
|
+
ps.size.should == 2
|
39
|
+
ps.first.innerHTML.should == 'Hello'
|
40
|
+
ps.last.innerHTML.should == 'World!'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should allow styles" do
|
44
|
+
ODF::Text.create.should_not have_tag('//office:automatic-styles')
|
45
|
+
output = ODF::Text.create { |doc|
|
46
|
+
doc.style('bold', :family => 'text') {|s|
|
47
|
+
s.property(:text, 'font-weight' => 'bold') }
|
48
|
+
doc.style('italic', :family => 'text') {|s|
|
49
|
+
s.property(:text, 'font-weight' => 'italic') }
|
50
|
+
}
|
51
|
+
output.should have_tag('//office:automatic-styles/*', :count => 2)
|
52
|
+
output.should have_tag('//style:style')
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should support page layout as auto-style" do
|
56
|
+
output = ODF::Text.create { |doc|
|
57
|
+
doc.page_layout 'main-layout'
|
58
|
+
}
|
59
|
+
output.should have_tag('//office:automatic-styles/*', :count => 1)
|
60
|
+
output.should have_tag('//style:page-layout')
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should support master pages" do
|
64
|
+
output = ODF::Text.create do |doc|
|
65
|
+
doc.master_page 'standard', :layout => 'letter'
|
66
|
+
end
|
67
|
+
output.should have_tag('//office:master-styles/*', :count => 1)
|
68
|
+
output.should have_tag('//style:master-page')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Thiago Arrais
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-28 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -114,14 +114,23 @@ extra_rdoc_files:
|
|
114
114
|
- lib/odf/column.rb
|
115
115
|
- lib/odf/container.rb
|
116
116
|
- lib/odf/data_style.rb
|
117
|
+
- lib/odf/document.rb
|
118
|
+
- lib/odf/hyperlink.rb
|
119
|
+
- lib/odf/master_page.rb
|
120
|
+
- lib/odf/page_layout.rb
|
121
|
+
- lib/odf/paragraph.rb
|
122
|
+
- lib/odf/paragraph_container.rb
|
117
123
|
- lib/odf/property.rb
|
118
124
|
- lib/odf/row.rb
|
119
|
-
- lib/odf/skeleton
|
125
|
+
- lib/odf/skeleton.rb
|
126
|
+
- lib/odf/skeleton/manifest.xml.erb
|
120
127
|
- lib/odf/skeleton/styles.xml
|
128
|
+
- lib/odf/span.rb
|
121
129
|
- lib/odf/spreadsheet.rb
|
122
130
|
- lib/odf/style_section.rb
|
123
131
|
- lib/odf/style.rb
|
124
132
|
- lib/odf/table.rb
|
133
|
+
- lib/odf/text.rb
|
125
134
|
files:
|
126
135
|
- CHANGELOG
|
127
136
|
- LICENSE.LGPL
|
@@ -132,24 +141,39 @@ files:
|
|
132
141
|
- lib/odf/column.rb
|
133
142
|
- lib/odf/container.rb
|
134
143
|
- lib/odf/data_style.rb
|
144
|
+
- lib/odf/document.rb
|
145
|
+
- lib/odf/hyperlink.rb
|
146
|
+
- lib/odf/master_page.rb
|
147
|
+
- lib/odf/page_layout.rb
|
148
|
+
- lib/odf/paragraph.rb
|
149
|
+
- lib/odf/paragraph_container.rb
|
135
150
|
- lib/odf/property.rb
|
136
151
|
- lib/odf/row.rb
|
137
|
-
- lib/odf/skeleton
|
152
|
+
- lib/odf/skeleton.rb
|
153
|
+
- lib/odf/skeleton/manifest.xml.erb
|
138
154
|
- lib/odf/skeleton/styles.xml
|
155
|
+
- lib/odf/span.rb
|
139
156
|
- lib/odf/spreadsheet.rb
|
140
157
|
- lib/odf/style_section.rb
|
141
158
|
- lib/odf/style.rb
|
142
159
|
- lib/odf/table.rb
|
160
|
+
- lib/odf/text.rb
|
143
161
|
- rodf.gemspec
|
144
162
|
- spec/cell_spec.rb
|
145
163
|
- spec/data_style_spec.rb
|
164
|
+
- spec/hyperlink_spec.rb
|
165
|
+
- spec/master_page_spec.rb
|
166
|
+
- spec/page_layout_spec.rb
|
167
|
+
- spec/paragraph_spec.rb
|
146
168
|
- spec/property_spec.rb
|
147
169
|
- spec/row_spec.rb
|
170
|
+
- spec/span_spec.rb
|
148
171
|
- spec/spec_helper.rb
|
149
172
|
- spec/spreadsheet_spec.rb
|
150
173
|
- spec/style_section_spec.rb
|
151
174
|
- spec/style_spec.rb
|
152
175
|
- spec/table_spec.rb
|
176
|
+
- spec/text_spec.rb
|
153
177
|
has_rdoc: true
|
154
178
|
homepage: http://github.com/thiagoarrais/rodf/tree
|
155
179
|
licenses: []
|