rodf 0.2.2 → 0.3

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.3. Allow parameterless blocks
1
2
  v0.2.2. Reintroduce compatibility with Ruby 1.8
2
3
  v0.2.1. Update to newer libraries and Ruby 1.9
3
4
  v0.1.6. Fix date handling
data/README.rdoc CHANGED
@@ -18,9 +18,9 @@ rODF works pretty much like Builder, but with ODF-aware constructs. Try this:
18
18
 
19
19
  require 'odf/spreadsheet'
20
20
 
21
- ODF::Spreadsheet.file("my-spreadsheet.ods") do |spreadsheet|
22
- spreadsheet.table 'My first table from Ruby' do |table|
23
- table.row {|row| row.cell 'Hello, rODF world!' }
21
+ ODF::Spreadsheet.file("my-spreadsheet.ods") do
22
+ table 'My first table from Ruby' do
23
+ row {cell 'Hello, rODF world!' }
24
24
  end
25
25
  end
26
26
 
@@ -28,12 +28,12 @@ Some basic formatting is also possible:
28
28
 
29
29
  require 'odf/spreadsheet'
30
30
 
31
- ODF::Spreadsheet.file("my-spreadsheet.ods") do |spreadsheet|
32
- spreadsheet.style 'red-cell', :family => :cell do |style|
33
- style.property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
31
+ ODF::Spreadsheet.file("my-spreadsheet.ods") do
32
+ style 'red-cell', :family => :cell do
33
+ property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
34
34
  end
35
- spreadsheet.table 'Red text table' do |table|
36
- table.row {|row| row.cell 'Red', :style => 'red-cell' }
35
+ table 'Red text table' do
36
+ row {cell 'Red', :style => 'red-cell' }
37
37
  end
38
38
  end
39
39
 
data/lib/odf/cell.rb CHANGED
@@ -56,16 +56,16 @@ module ODF
56
56
  text
57
57
  end
58
58
 
59
+ def contains_url?
60
+ !@url.nil? && !@url.empty?
61
+ end
62
+
59
63
  private
60
64
 
61
65
  def contains_string?
62
66
  :string == @type && !@value.nil? && !@value.empty?
63
67
  end
64
68
 
65
- def contains_url?
66
- !@url.nil? && !@url.empty?
67
- end
68
-
69
69
  def make_element_attributes(type, value, opts)
70
70
  attrs = {}
71
71
  attrs['office:value-type'] = type if :string == type || !empty(value) || !opts[:formula].nil?
@@ -81,11 +81,12 @@ module ODF
81
81
 
82
82
  def make_value_paragraph
83
83
  if contains_string?
84
- paragraph do |p|
85
- if contains_url?
86
- p.link @value, :href => @url
84
+ cell, value, url = self, @value, @url
85
+ paragraph do
86
+ if cell.contains_url?
87
+ link value, :href => url
87
88
  else
88
- p << @value
89
+ self << value
89
90
  end
90
91
  end
91
92
  end
data/lib/odf/container.rb CHANGED
@@ -33,9 +33,9 @@ module ODF
33
33
  end"
34
34
 
35
35
  self.class_eval "
36
- def #{stuff}(*args)
36
+ def #{stuff}(*args, &contents)
37
37
  c = #{stuff_class}.new(*args)
38
- yield c if block_given?
38
+ c.instance_eval(&contents) if block_given?
39
39
  #{stuffs} << c
40
40
  c
41
41
  end"
@@ -47,9 +47,9 @@ module ODF
47
47
  end
48
48
  end
49
49
 
50
- def self.create(*args)
50
+ def self.create(*args, &contents)
51
51
  container = self.new(*args)
52
- yield container if block_given?
52
+ container.instance_eval(&contents) if block_given?
53
53
  container.xml
54
54
  end
55
55
  end
data/lib/odf/document.rb CHANGED
@@ -27,12 +27,12 @@ module ODF
27
27
  class Document < Container
28
28
  contains :styles, :default_styles
29
29
 
30
- def self.file(ods_file_name)
30
+ def self.file(ods_file_name, &contents)
31
31
  ods_file = Zip::ZipFile.open(ods_file_name, Zip::ZipFile::CREATE)
32
32
  ods_file.get_output_stream('styles.xml') {|f| f << skeleton.styles }
33
33
  ods_file.get_output_stream('META-INF/manifest.xml') {|f| f << skeleton.manifest(doc_type) }
34
34
 
35
- yield(doc = new)
35
+ (doc = new).instance_eval(&contents)
36
36
 
37
37
  ods_file.get_output_stream('content.xml') {|f| f << doc.xml}
38
38
 
data/lib/odf/table.rb CHANGED
@@ -32,8 +32,8 @@ module ODF
32
32
  end
33
33
 
34
34
  alias create_row row
35
- def row
36
- create_row(next_row) {|r| yield r if block_given?}
35
+ def row(&contents)
36
+ create_row(next_row) {instance_eval(&contents) if block_given?}
37
37
  end
38
38
 
39
39
  def xml
data/rodf.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rodf"
5
- s.version = "0.2.2"
5
+ s.version = "0.3"
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 = "2012-04-25"
9
+ s.date = "2012-07-13"
10
10
  s.description = "ODF generation library for Ruby"
11
11
  s.email = "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/compatibility.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.rb", "lib/odf/style_section.rb", "lib/odf/tab.rb", "lib/odf/table.rb", "lib/odf/text.rb"]
data/spec/cell_spec.rb CHANGED
@@ -164,5 +164,19 @@ describe ODF::Cell do
164
164
  cell['office:value-type'].should be_nil
165
165
  end
166
166
  end
167
+
168
+ it "should accept parameterless blocks" do
169
+ output = ODF::Cell.create do
170
+ paragraph "first"
171
+ paragraph "second"
172
+ end
173
+
174
+ output.should have_tag("//table:table-cell/*", :count => 2)
175
+ output.should have_tag("//text:p")
176
+
177
+ ps = Hpricot(output).search('text:p')
178
+ ps[0].innerHTML.should == 'first'
179
+ ps[1].innerHTML.should == 'second'
180
+ end
167
181
  end
168
182
 
@@ -46,5 +46,16 @@ describe ODF::DataStyle do
46
46
  output.should have_tag('number:month')
47
47
  output.should have_tag('number:day')
48
48
  end
49
+
50
+ it "should accept parameterless blocks" do
51
+ output = ODF::DataStyle.create 'year-to-day', :date do
52
+ section :year, :style => 'long'
53
+ section :month, :style => 'long'
54
+ section :day
55
+ end
56
+
57
+ output.should have_tag('number:date-style')
58
+ output.should have_tag('number:year')
59
+ end
49
60
  end
50
61
 
@@ -49,5 +49,14 @@ describe ODF::Hyperlink do
49
49
  span['text:style-name'].should == 'strong'
50
50
  span.innerHTML.should == 'important link'
51
51
  end
52
+
53
+ it "should accept parameterless blocks" do
54
+ output = ODF::Hyperlink.create 'http://www.example.com/' do
55
+ strong 'important link'
56
+ end
57
+
58
+ output.should have_tag('//text:a/*')
59
+ output.should have_tag('//text:span/*')
60
+ end
52
61
  end
53
62
 
@@ -33,5 +33,13 @@ describe ODF::PageLayout do
33
33
  output.should have_tag('//style:page-layout/*', :count => 1)
34
34
  output.should have_tag('style:page-layout-properties')
35
35
  end
36
+
37
+ it "should accept parameterless blocks" do
38
+ output = ODF::PageLayout.create 'main-layout' do
39
+ property 'page-layout'
40
+ end
41
+ output.should have_tag('//style:page-layout/*', :count => 1)
42
+ output.should have_tag('style:page-layout-properties')
43
+ end
36
44
  end
37
45
 
data/spec/row_spec.rb CHANGED
@@ -32,4 +32,13 @@ describe ODF::Row do
32
32
  output.should have_tag('//table:table-row/*', :count => 2)
33
33
  output.should have_tag('//table:table-cell')
34
34
  end
35
+
36
+ it "should accept parameterless blocks" do
37
+ output = ODF::Row.create do
38
+ cell
39
+ cell
40
+ end
41
+ output.should have_tag('//table:table-row/*', :count => 2)
42
+ output.should have_tag('//table:table-cell')
43
+ end
35
44
  end
data/spec/style_spec.rb CHANGED
@@ -22,7 +22,7 @@ require 'odf/style'
22
22
  describe ODF::Style do
23
23
  it "should output properties when they're added" do
24
24
  ODF::Style.create.should_not have_tag('//style:style/*')
25
-
25
+
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'
@@ -90,5 +90,13 @@ describe ODF::Style do
90
90
  Hpricot(ODF::Style.create('text-style', :family => :paragraph)).
91
91
  at('//style:style')['style:family'].should == 'paragraph'
92
92
  end
93
+
94
+ it "should accept parameterless blocks" do
95
+ output = ODF::Style.create 'odd-row-cell', :family => :cell do
96
+ property :text, 'color' => '#4c4c4c', 'font-weight' => 'bold'
97
+ end
98
+
99
+ output.should have_tag('//style:style/*')
100
+ end
93
101
  end
94
102
 
data/spec/table_spec.rb CHANGED
@@ -55,4 +55,23 @@ describe ODF::Table do
55
55
  column = Hpricot(xml).at('table:table-column')
56
56
  column['table:style-name'].should == 'wide'
57
57
  end
58
+
59
+ it "should accept parameterless block" do
60
+ output = ODF::Table.create('MyTable') {
61
+ row
62
+ row
63
+ }
64
+ output.should have_tag('//table:table/*', :count => 2)
65
+ output.should have_tag('//table:table-row')
66
+ end
67
+
68
+ it "should have children that accept parameterless blocks too" do
69
+ output = ODF::Table.create('MyTable') {
70
+ row {cell}
71
+ row
72
+ }
73
+ output.should have_tag('//table:table/*', :count => 2)
74
+ output.should have_tag('//table:table-row')
75
+ output.should have_tag('//table:table-cell')
76
+ end
58
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-25 00:00:00.000000000 Z
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
16
- requirement: &87158270 !ruby/object:Gem::Requirement
16
+ requirement: &75169230 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *87158270
24
+ version_requirements: *75169230
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rubyzip
27
- requirement: &87158060 !ruby/object:Gem::Requirement
27
+ requirement: &75169020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.9.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *87158060
35
+ version_requirements: *75169020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &87157850 !ruby/object:Gem::Requirement
38
+ requirement: &75168810 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *87157850
46
+ version_requirements: *75168810
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &87157640 !ruby/object:Gem::Requirement
49
+ requirement: &75168600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.9'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *87157640
57
+ version_requirements: *75168600
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec_hpricot_matchers
60
- requirement: &87157430 !ruby/object:Gem::Requirement
60
+ requirement: &75168390 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '1.0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *87157430
68
+ version_requirements: *75168390
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: echoe
71
- requirement: &87157220 !ruby/object:Gem::Requirement
71
+ requirement: &75168180 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '4.6'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *87157220
79
+ version_requirements: *75168180
80
80
  description: ODF generation library for Ruby
81
81
  email: thiago.arrais@gmail.com
82
82
  executables: []