rodf 0.1.5 → 0.1.7

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 CHANGED
@@ -1,3 +1,4 @@
1
+ v0.1.6. Fix date handling
1
2
  v0.1.5. Bug fix
2
3
  v0.1.4. Allow the setting of an entire cell's content to a hyperlink (by Merul Patel)
3
4
  v0.1.3. Dependency fix (by Merul Patel)
data/Manifest CHANGED
@@ -6,18 +6,22 @@ Rakefile
6
6
  lib/odf/cell.rb
7
7
  lib/odf/column.rb
8
8
  lib/odf/container.rb
9
+ lib/odf/data_style.rb
9
10
  lib/odf/property.rb
10
11
  lib/odf/row.rb
11
12
  lib/odf/skeleton/manifest.xml
12
13
  lib/odf/skeleton/styles.xml
13
14
  lib/odf/spreadsheet.rb
14
15
  lib/odf/style.rb
16
+ lib/odf/style_section.rb
15
17
  lib/odf/table.rb
16
18
  rodf.gemspec
17
19
  spec/cell_spec.rb
20
+ spec/data_style_spec.rb
18
21
  spec/property_spec.rb
19
22
  spec/row_spec.rb
20
23
  spec/spec_helper.rb
21
24
  spec/spreadsheet_spec.rb
25
+ spec/style_section_spec.rb
22
26
  spec/style_spec.rb
23
27
  spec/table_spec.rb
data/lib/odf/cell.rb CHANGED
@@ -26,7 +26,13 @@ module ODF
26
26
 
27
27
  @url = opts[:url]
28
28
  @type = opts[:type] || :string
29
- @value = value.to_s.strip unless value.instance_of? Hash
29
+ unless value.instance_of?(Hash)
30
+ if [Date, DateTime, Time].include? value.class
31
+ @value = value.strftime("%Y-%m-%d")
32
+ else
33
+ @value = value.to_s.strip
34
+ end
35
+ end
30
36
 
31
37
  @elem_attrs = make_element_attributes(@type, @value, opts)
32
38
  @mutiply = (opts[:span] || 1).to_i
@@ -35,10 +41,14 @@ module ODF
35
41
  def xml
36
42
  markup = Builder::XmlMarkup.new
37
43
  text = markup.tag! 'table:table-cell', @elem_attrs do |xml|
38
- if contains_url?
39
- xml.text(:p){|x| x.text(:a, @value, 'xlink:href' => @url)}
40
- elsif contains_string?
41
- xml.text(:p, @value)
44
+ if contains_string?
45
+ xml.text:p do |p|
46
+ if contains_url?
47
+ p.text:a, @value, 'xlink:href' => @url
48
+ else
49
+ p << @value
50
+ end
51
+ end
42
52
  end
43
53
  end
44
54
  (@mutiply - 1).times {text = markup.tag! 'table:table-cell'}
@@ -55,7 +65,8 @@ module ODF
55
65
 
56
66
  def make_element_attributes(type, value, opts)
57
67
  attrs = {'office:value-type' => type}
58
- attrs['office:value'] = value unless contains_string?
68
+ attrs['office:date-value'] = value if :date == type
69
+ attrs['office:value'] = value if :float == type
59
70
  attrs['table:formula'] = opts[:formula] unless opts[:formula].nil?
60
71
  attrs['table:style-name'] = opts[:style] unless opts[:style].nil?
61
72
  attrs['table:number-columns-spanned'] = opts[:span] unless opts[:span].nil?
data/lib/odf/container.rb CHANGED
@@ -25,7 +25,7 @@ module ODF
25
25
  def self.contains(*stuffs_array)
26
26
  stuffs_array.map {|sym| sym.to_s}.each do |stuffs|
27
27
  stuff = stuffs.to_s.singularize
28
- stuff_class = eval(stuff.capitalize)
28
+ stuff_class = eval(stuff.camelize)
29
29
 
30
30
  self.class_eval "
31
31
  def #{stuffs}
@@ -0,0 +1,45 @@
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/container'
23
+ require 'odf/style_section'
24
+
25
+ module ODF
26
+ class DataStyle < Container
27
+ contains :style_sections
28
+
29
+ alias section style_section
30
+
31
+ def initialize(name, type)
32
+ @type, @name = type, name
33
+ end
34
+
35
+ def xml
36
+ Builder::XmlMarkup.new.tag! "number:#{@type}-style", 'style:name' => @name do |xml|
37
+ xml << style_sections_xml
38
+ end
39
+ end
40
+
41
+ def method_missing(name, *args)
42
+ section(name, *args)
43
+ end
44
+ end
45
+ end
@@ -17,6 +17,13 @@
17
17
  <number:number-style style:name="integer-grouped">
18
18
  <number:number number:decimal-places="0" number:min-integer-digits="1" number:grouping="true" />
19
19
  </number:number-style>
20
+ <number:date-style style:name="year-to-day-long">
21
+ <number:year number:style="long"/>
22
+ <number:text>-</number:text>
23
+ <number:month number:style="long"/>
24
+ <number:text>-</number:text>
25
+ <number:day number:style="long"/>
26
+ </number:date-style>
20
27
  </office:styles>
21
28
  </office:document-styles>
22
29
 
@@ -21,12 +21,13 @@ require 'builder'
21
21
  require 'zip/zip'
22
22
 
23
23
  require 'odf/container'
24
+ require 'odf/data_style'
24
25
  require 'odf/style'
25
26
  require 'odf/table'
26
27
 
27
28
  module ODF
28
29
  class SpreadSheet < Container
29
- contains :tables, :styles
30
+ contains :tables, :styles, :data_styles
30
31
 
31
32
  def self.file(ods_file_name)
32
33
  ods_file = Zip::ZipFile.open(ods_file_name, Zip::ZipFile::CREATE)
@@ -50,11 +51,13 @@ module ODF
50
51
  'xmlns:oooc' => "http://openoffice.org/2004/calc",
51
52
  'xmlns:style' => "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
52
53
  'xmlns:fo' => "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",
54
+ 'xmlns:number' => "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0",
53
55
  'xmlns:xlink' => "http://www.w3.org/1999/xlink" do
54
56
  |xml|
55
57
  xml.tag! 'office:automatic-styles' do
56
58
  xml << styles_xml
57
- end unless styles.empty?
59
+ xml << data_styles_xml
60
+ end unless styles.empty? && data_styles.empty?
58
61
  xml.office:body do
59
62
  xml.office:spreadsheet do
60
63
  xml << tables_xml
@@ -0,0 +1,42 @@
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
+ module ODF
23
+ class StyleSection
24
+ def initialize(type, second = {})
25
+ @type = type
26
+ if second.instance_of?(Hash)
27
+ @elem_attrs = make_element_attributes(second)
28
+ else
29
+ @content, @elem_attrs = second, {}
30
+ end
31
+ end
32
+
33
+ def xml
34
+ Builder::XmlMarkup.new.number @type, @content, @elem_attrs
35
+ end
36
+
37
+ def make_element_attributes(opts)
38
+ {'number:style' => opts[:style], 'number:textual' => opts[:textual]}
39
+ end
40
+ end
41
+ end
42
+
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"
5
+ s.version = "0.1.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Thiago Arrais", "Merul Patel"]
9
- s.date = %q{2010-04-08}
8
+ s.authors = ["Thiago Arrais"]
9
+ s.date = %q{2010-04-19}
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/property.rb", "lib/odf/row.rb", "lib/odf/skeleton/manifest.xml", "lib/odf/skeleton/styles.xml", "lib/odf/spreadsheet.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/property.rb", "lib/odf/row.rb", "lib/odf/skeleton/manifest.xml", "lib/odf/skeleton/styles.xml", "lib/odf/spreadsheet.rb", "lib/odf/style.rb", "lib/odf/table.rb", "rodf.gemspec", "spec/cell_spec.rb", "spec/property_spec.rb", "spec/row_spec.rb", "spec/spec_helper.rb", "spec/spreadsheet_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/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"]
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
@@ -102,10 +102,26 @@ describe ODF::Cell do
102
102
  doc.at('text:a')['xlink:href'].should == 'http://www.example.org'
103
103
  end
104
104
 
105
- it "should have the URL set correctly when requested on a float" do
105
+ it "should ignore the URL requested on anything other than a string" do
106
106
  cell = ODF::Cell.new(47.1, :type => :float, :url => 'http://www.example.org')
107
- doc = Hpricot(cell.xml)
108
- doc.at('text:a')['xlink:href'].should == 'http://www.example.org'
109
- doc.at('text:a').innerHTML.should == '47.1'
107
+ cell.xml.should_not have_tag('text:p')
108
+ cell.xml.should_not have_tag('text:a')
109
+
110
+ cell = ODF::Cell.new(Date.parse('15 Apr 2010'), :type => :date, :url => 'http://www.example.org')
111
+ cell.xml.should_not have_tag('text:p')
112
+ cell.xml.should_not have_tag('text:a')
113
+ end
114
+
115
+ it "should have the date set correctly" do
116
+ cell = Hpricot(ODF::Cell.new(Date.parse('15 Apr 2010'), :type => :date).xml).
117
+ at('table:table-cell')
118
+ cell['office:value-type'].should == 'date'
119
+ cell['office:date-value'].should == '2010-04-15'
120
+ cell['office:value'].should be_nil
121
+ end
122
+
123
+ it "should also accept strings as date values" do
124
+ Hpricot(ODF::Cell.new(Date.parse('16 Apr 2010'), :type => :date).xml).
125
+ at('table:table-cell')['office:date-value'] = '2010-04-16'
110
126
  end
111
127
  end
@@ -0,0 +1,50 @@
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/data_style'
21
+
22
+ describe ODF::DataStyle do
23
+ it "should have sections" do
24
+ output = ODF::DataStyle.create 'year-to-day', :date do |s|
25
+ s.section :year, :style => 'long'
26
+ s.section :month, :style => 'long'
27
+ s.section :day
28
+ end
29
+
30
+ output.should have_tag('number:date-style')
31
+ output.should have_tag('number:year')
32
+ output.should have_tag('number:month')
33
+ output.should have_tag('number:day')
34
+
35
+ Hpricot(output).at('number:date-style')['style:name'].should == 'year-to-day'
36
+ end
37
+
38
+ it "should allow short section names" do
39
+ output = ODF::DataStyle.create 'year-to-day', :date do |number|
40
+ number.year :style => 'long'
41
+ number.month :style => 'long'
42
+ number.day
43
+ end
44
+
45
+ output.should have_tag('number:year')
46
+ output.should have_tag('number:month')
47
+ output.should have_tag('number:day')
48
+ end
49
+ end
50
+
@@ -68,6 +68,14 @@ describe ODF::SpreadSheet do
68
68
  output.should have_tag('//style:style')
69
69
  Hpricot(output).at('//style:style')['style:name'].should == 'even-row-cell'
70
70
  Hpricot(output).at('//style:style')['style:family'].should == 'table-cell'
71
+ end
72
+
73
+ it "should have data styles" do
74
+ output = ODF::SpreadSheet.create do |ss|
75
+ ss.data_style 'year-to-day-long', :date
76
+ end
77
+ output.should have_tag('//office:automatic-styles/*', :count => 1)
78
+ output.should have_tag('//number:date-style')
71
79
  end
72
80
  end
73
81
 
@@ -0,0 +1,42 @@
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/style_section'
21
+
22
+ describe ODF::StyleSection do
23
+ it "should allow style attribute" do
24
+ output = ODF::StyleSection.new(:year, :style => 'long').xml
25
+ output.should have_tag('number:year')
26
+ Hpricot(output).at('number:year')['number:style'].should == 'long'
27
+ end
28
+
29
+ it "should allow textual flag" do
30
+ output = ODF::StyleSection.new(:month, :textual => true).xml
31
+ Hpricot(output).at('number:month')['number:textual'].should == 'true'
32
+ end
33
+
34
+ it "should allow text to be inserted" do
35
+ Hpricot(ODF::StyleSection.new(:text, 'content').xml).
36
+ at('number:text').innerHTML.should == 'content'
37
+
38
+ Hpricot(ODF::StyleSection.new(:day).xml).
39
+ at('number:day').innerHTML.should == ''
40
+ end
41
+ end
42
+
metadata CHANGED
@@ -5,17 +5,16 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 7
9
+ version: 0.1.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Thiago Arrais
13
- - Merul Patel
14
13
  autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-04-08 00:00:00 -03:00
17
+ date: 2010-04-19 00:00:00 -03:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -114,11 +113,13 @@ extra_rdoc_files:
114
113
  - lib/odf/cell.rb
115
114
  - lib/odf/column.rb
116
115
  - lib/odf/container.rb
116
+ - lib/odf/data_style.rb
117
117
  - lib/odf/property.rb
118
118
  - lib/odf/row.rb
119
119
  - lib/odf/skeleton/manifest.xml
120
120
  - lib/odf/skeleton/styles.xml
121
121
  - lib/odf/spreadsheet.rb
122
+ - lib/odf/style_section.rb
122
123
  - lib/odf/style.rb
123
124
  - lib/odf/table.rb
124
125
  files:
@@ -130,19 +131,23 @@ files:
130
131
  - lib/odf/cell.rb
131
132
  - lib/odf/column.rb
132
133
  - lib/odf/container.rb
134
+ - lib/odf/data_style.rb
133
135
  - lib/odf/property.rb
134
136
  - lib/odf/row.rb
135
137
  - lib/odf/skeleton/manifest.xml
136
138
  - lib/odf/skeleton/styles.xml
137
139
  - lib/odf/spreadsheet.rb
140
+ - lib/odf/style_section.rb
138
141
  - lib/odf/style.rb
139
142
  - lib/odf/table.rb
140
143
  - rodf.gemspec
141
144
  - spec/cell_spec.rb
145
+ - spec/data_style_spec.rb
142
146
  - spec/property_spec.rb
143
147
  - spec/row_spec.rb
144
148
  - spec/spec_helper.rb
145
149
  - spec/spreadsheet_spec.rb
150
+ - spec/style_section_spec.rb
146
151
  - spec/style_spec.rb
147
152
  - spec/table_spec.rb
148
153
  has_rdoc: true