rodf 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.1.5. Bug fix
2
+ v0.1.4. Allow the setting of an entire cell's content to a hyperlink (by Merul Patel)
1
3
  v0.1.3. Dependency fix (by Merul Patel)
2
4
  v0.1.2. Cell span
3
5
  v0.1.1. Basic spreadsheet styling support
data/lib/odf/cell.rb CHANGED
@@ -24,6 +24,7 @@ module ODF
24
24
  value = args.first || ''
25
25
  opts = args.last.instance_of?(Hash) ? args.last : {}
26
26
 
27
+ @url = opts[:url]
27
28
  @type = opts[:type] || :string
28
29
  @value = value.to_s.strip unless value.instance_of? Hash
29
30
 
@@ -34,7 +35,11 @@ module ODF
34
35
  def xml
35
36
  markup = Builder::XmlMarkup.new
36
37
  text = markup.tag! 'table:table-cell', @elem_attrs do |xml|
37
- xml.text(:p, @value) if contains_string?
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)
42
+ end
38
43
  end
39
44
  (@mutiply - 1).times {text = markup.tag! 'table:table-cell'}
40
45
  text
@@ -44,6 +49,10 @@ module ODF
44
49
  :string == @type && !@value.nil? && !@value.empty?
45
50
  end
46
51
 
52
+ def contains_url?
53
+ !@url.nil? && !@url.empty?
54
+ end
55
+
47
56
  def make_element_attributes(type, value, opts)
48
57
  attrs = {'office:value-type' => type}
49
58
  attrs['office:value'] = value unless contains_string?
@@ -23,7 +23,7 @@ require 'zip/zip'
23
23
  require 'odf/container'
24
24
  require 'odf/style'
25
25
  require 'odf/table'
26
-
26
+
27
27
  module ODF
28
28
  class SpreadSheet < Container
29
29
  contains :tables, :styles
@@ -41,31 +41,32 @@ module ODF
41
41
  end
42
42
 
43
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
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",
53
+ 'xmlns:xlink' => "http://www.w3.org/1999/xlink" do
53
54
  |xml|
54
55
  xml.tag! 'office:automatic-styles' do
55
56
  xml << styles_xml
56
57
  end unless styles.empty?
57
- xml.office:body do
58
+ xml.office:body do
58
59
  xml.office:spreadsheet do
59
60
  xml << tables_xml
60
- end
61
- end
62
- end
61
+ end
62
+ end
63
+ end
63
64
  end
64
65
 
65
66
  private
66
67
  def self.skeleton(fname)
67
68
  File.open(File.dirname(__FILE__) + '/skeleton/' + fname).read
68
- end
69
+ end
69
70
  end
70
71
  end
71
72
 
data/rodf.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rodf}
5
- s.version = "0.1.3"
5
+ s.version = "0.1.5"
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", "Merul Patel"]
9
- s.date = %q{2010-04-06}
9
+ s.date = %q{2010-04-08}
10
10
  s.description = %q{ODF generation library for Ruby}
11
11
  s.email = %q{thiago.arrais@gmail.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE.LGPL", "README.rdoc", "lib/odf/cell.rb", "lib/odf/column.rb", "lib/odf/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"]
data/spec/cell_spec.rb CHANGED
@@ -95,4 +95,17 @@ describe ODF::Cell do
95
95
  doc.at('table:table-cell')['table:number-columns-spanned'].should == '4'
96
96
  doc.search('table:table-cell').size.should == 4
97
97
  end
98
+
99
+ it "should have the URL set correctly when requested on a string" do
100
+ cell = ODF::Cell.new 'Example Link', :url => 'http://www.example.org'
101
+ doc = Hpricot(cell.xml)
102
+ doc.at('text:a')['xlink:href'].should == 'http://www.example.org'
103
+ end
104
+
105
+ it "should have the URL set correctly when requested on a float" do
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'
110
+ end
98
111
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Thiago Arrais
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-06 00:00:00 -03:00
18
+ date: 2010-04-08 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency