rodf 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4baedf0ea44080eb12e4184c97e388dda1ad3174
4
- data.tar.gz: 41f4048ce761bfc790c4e81f2b7e2f794b07e0fe
2
+ SHA256:
3
+ metadata.gz: 6d5bdd76cb3b3ddf5b262b30b74190fc932c096ef74ddce506ccece191a1b4c4
4
+ data.tar.gz: 40949bf8a0bfe4fe39a89a7b34e8a97814e3160e94f762f34abab16dfcfb4322
5
5
  SHA512:
6
- metadata.gz: f00589a65f0a1a77993c320ed7c7d39927c0bc1a609010f82c0f44119faa29e2de139e2c02fb303d8a1a9b7be0dc70b174fac58bc45a9d596eb4c704e21fb976
7
- data.tar.gz: 9c9ea98eb21673b50eebb823c7c8b886bede10e3c86b14463c473f0b9eafca4bb24c0a4a5417d01e4cf242e5f379e252f5723a2314f10cfd7508c000429cdfed
6
+ metadata.gz: af1a5477be81146254b67ac087bf67c1fc8b28e03f327699e3678a3cacb2017b3c3792d4b422a4585c299cdc2ce0930841db0ecdac67b43cc73028613e5fef9e
7
+ data.tar.gz: 5358ba34d162d5ef45775813458fcf2a0a0ab10b191d2c42c012f5c0807f7517c1377f09d998cfe69424c2b1b96fe75a054f6fa60e2852038455a9684b755c2a
data/CHANGELOG.md CHANGED
@@ -1,18 +1,61 @@
1
- v1.0.0 Rename main module ODF to RODF, Fix cell types
2
- v0.3.7 Add Rails 5 support to gemspec
3
- v0.3.6 Resulting ODF files as bitstrings
4
- v0.3.5 Allows current libraries
5
- v0.3.4 Procedural cell styling
6
- v0.3.3 Documents can now write themselves to disk
7
- v0.3.2 Fixes broken styles.xml
8
- v0.3.1 Adds support for conditional formatting
9
- v0.3.0 Allow parameterless blocks
10
- v0.2.2 Reintroduce compatibility with Ruby 1.8
11
- v0.2.1 Update to newer libraries and Ruby 1.9
12
- v0.1.6 Fix date handling
13
- v0.1.5 Bug fix
14
- v0.1.4 Allow the setting of an entire cell's content to a hyperlink (by Merul Patel)
15
- v0.1.3 Dependency fix (by Merul Patel)
16
- v0.1.2 Cell span
17
- v0.1.1 Basic spreadsheet styling support
18
- v0.1.0 First version with very basic support for spreadsheet generation
1
+ # CHANGELOG
2
+
3
+ ## v1.1.0
4
+ * [#34](https://github.com/westonganger/rodf/pull/34) - Add ability to add many rows or cells at once
5
+ * [#29](https://github.com/westonganger/rodf/pull/29) - Remove ActiveSupport dependency in favor of `dry-inflector`
6
+ * [#21](https://github.com/thiagoarrais/rodf/pull/21) - Allow more attributes for the `data_style` method
7
+ * [#19](https://github.com/westonganger/rodf/issues/19) - Changes to Date/Time handling
8
+
9
+ ## v1.0.0
10
+ - Rename main module ODF to RODF, Fix cell types
11
+
12
+ ## v0.3.7
13
+ - Add Rails 5 support to gemspec
14
+
15
+ ## v0.3.6
16
+ - Resulting ODF files as bitstrings
17
+
18
+ ## v0.3.5
19
+ - Allows current libraries
20
+
21
+ ## v0.3.4
22
+ - Procedural cell styling
23
+
24
+ ## v0.3.3
25
+ - Documents can now write themselves to disk
26
+
27
+ ## v0.3.2
28
+ - Fixes broken styles.xml
29
+
30
+ ## v0.3.1
31
+ - Adds support for conditional formatting
32
+
33
+ ## v0.3.0
34
+ - Allow parameterless blocks
35
+
36
+ ## v0.2.2
37
+ - Reintroduce compatibility with Ruby 1.8
38
+
39
+ ## v0.2.1
40
+ - Update to newer libraries and Ruby 1.9
41
+
42
+ ## v0.1.6
43
+ - Fix date handling
44
+
45
+ ## v0.1.5
46
+ - Bug fix
47
+
48
+ ## v0.1.4
49
+ - Allow the setting of an entire cell's content to a hyperlink (by Merul Patel)
50
+
51
+ ## v0.1.3
52
+ - Dependency fix (by Merul Patel)
53
+
54
+ ## v0.1.2
55
+ - Cell span
56
+
57
+ ## v0.1.1
58
+ - Basic spreadsheet styling support
59
+
60
+ ## v0.1.0
61
+ - First version with very basic support for spreadsheet generation
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2008 Thiago Arrais
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
- <a href='https://ko-fi.com/A5071NK' target='_blank'><img height='32' style='border:0px;height:32px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /></a>
2
1
  # RODF
2
+ <a href="https://badge.fury.io/rb/rodf" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/rodf.svg" alt="Gem Version"></a>
3
+ <a href='https://travis-ci.org/westonganger/rodf' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://api.travis-ci.org/westonganger/rodf.svg?branch=master' border='0' alt='Build Status' /></a>
4
+ <a href='https://rubygems.org/gems/rodf' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://ruby-gem-downloads-badge.herokuapp.com/rodf?label=rubygems&type=total&total_label=downloads&color=brightgreen' border='0' alt='RubyGems Downloads' /></a>
5
+ <a href='https://ko-fi.com/A5071NK' target='_blank'><img height='22' style='border:0px;height:22px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /></a>
3
6
 
4
7
  This is a library for writing to ODF output from Ruby. It mainly focuses creating ODS spreadsheets.
5
8
 
@@ -7,18 +10,13 @@ As well as writing ODS spreadsheets, this library also can write ODT text docume
7
10
 
8
11
  This is NOT an ODF reading library.
9
12
 
10
- ### v1.0.0 Breaking Changes
11
- The main module `ODF` has changed to `RODF`
12
-
13
- `require 'odf/spreadsheet'` must be changed to `require 'rodf'`
14
-
15
- ### Install
13
+ ## Install
16
14
 
17
15
  ```
18
16
  gem install rodf
19
17
  ```
20
18
 
21
- ### How do I use it?
19
+ ## How do I use it?
22
20
 
23
21
  rODF works pretty much like Builder, but with ODF-aware constructs. Try this:
24
22
 
@@ -34,6 +32,77 @@ RODF::Spreadsheet.file("my-spreadsheet.ods") do
34
32
  end
35
33
  ```
36
34
 
35
+ For access to variables and methods from outer code you can use block parameter:
36
+
37
+ ```ruby
38
+ require 'rodf'
39
+
40
+ @data = 'Hello, rODF world!'
41
+
42
+ RODF::Spreadsheet.file("my-spreadsheet.ods") do |spreadsheet|
43
+ spreadsheet.table 'My first table from Ruby' do |table|
44
+ table.row do |row|
45
+ row.cell @data
46
+ end
47
+ end
48
+ end
49
+ ```
50
+
51
+ Adding many rows or cells at once is supported as well:
52
+
53
+ ```ruby
54
+ require 'rodf'
55
+
56
+ RODF::Spreadsheet.file("my-spreadsheet.ods") do
57
+ table 'My first table from Ruby' do
58
+ add_rows([
59
+ [1, 'Alice'],
60
+ [2, { value: 'Bob', color: '#ff0000'}],
61
+ [3, 'Carol']
62
+ ])
63
+
64
+ row do
65
+ add_cells ['ID', 'Name']
66
+ end
67
+ end
68
+ end
69
+ ```
70
+
71
+ ## Procedural style
72
+
73
+ The declarative style shown above is just syntatic sugar. A more procedural
74
+ style can also be used. Like so:
75
+
76
+ ```ruby
77
+ require 'rodf'
78
+
79
+ ss = RODF::Spreadsheet.new
80
+ t = ss.table 'My first table from Ruby'
81
+ r = t.row
82
+ c = r.cell 'Hello, rODF world!'
83
+
84
+ # two methods to write to file
85
+ ss.write_to 'my-spreadsheet.ods'
86
+ # or
87
+ File.write('my-spreadsheet.ods', ss.bytes) # you can send your data in Rails over HTTP using the bytes method
88
+ end
89
+ ```
90
+
91
+ Both styles can be mixed and matched at will:
92
+
93
+ ```ruby
94
+ require 'rodf'
95
+
96
+ ss = RODF::Spreadsheet.new
97
+ ss.table 'My first table from Ruby' do
98
+ row do
99
+ cell 'Hello, rODF world!'
100
+ end
101
+ end
102
+
103
+ ss.write_to 'my-spreadsheet.ods'
104
+ ```
105
+
37
106
  Styling and formatting is also possible:
38
107
 
39
108
  ```ruby
@@ -92,45 +161,20 @@ RODF::Spreadsheet.file("my-spreadsheet.ods") do
92
161
  end
93
162
  ```
94
163
 
95
- ### Procedural style
96
-
97
- The declarative style shown above is just syntatic sugar. A more procedural
98
- style can also be used. Like so:
99
-
100
- ```ruby
101
- require 'rodf'
102
-
103
- ss = RODF::Spreadsheet.new
104
- t = ss.table 'My first table from Ruby'
105
- r = t.row
106
- c = r.cell 'Hello, rODF world!'
107
-
108
- # two methods to write to file
109
- ss.write_to 'my-spreadsheet.ods'
110
- # or
111
- File.write('my-spreadsheet.ods') do |f|
112
- f.write ss.bytes # you can send your data in Rails over HTTP using the bytes method
113
- end
114
- ```
115
-
116
- Both styles can be mixed and matched at will:
117
-
118
- ```ruby
119
- require 'rodf'
164
+ ## Columns Types
120
165
 
121
- ss = RODF::Spreadsheet.new
122
- ss.table 'My first table from Ruby' do
123
- row do
124
- cell 'Hello, rODF world!'
125
- end
126
- end
166
+ Available columns types are:
127
167
 
128
- ss.write_to 'my-spreadsheet.ods'
129
- ```
168
+ - :string
169
+ - :float
170
+ - :date
171
+ - :time
172
+ - :currency
173
+ - :percentage
130
174
 
131
- ### Style List
175
+ ## Style List
132
176
  ```ruby
133
- property :text,
177
+ property :text,
134
178
  'font-weight' => :bold, #options are :bold, :thin
135
179
  'font-size' => 12,
136
180
  'font-name' => 'Arial',
@@ -141,7 +185,7 @@ property :text,
141
185
  align: true,
142
186
  color: "#000000"
143
187
 
144
- property :cell,
188
+ property :cell,
145
189
  'background-color' => "#DDDDDD",
146
190
  'wrap-option' => 'wrap',
147
191
  'vertical_align' => 'automatic',
@@ -150,10 +194,10 @@ property :cell,
150
194
  'border-left' => '0.75pt solid #999999',
151
195
  'border-right' => '0.75pt solid #999999',
152
196
 
153
- property :column,
197
+ property :column,
154
198
  'column-width' => '4.0cm'
155
199
 
156
- property :row,
200
+ property :row,
157
201
  'row-height' => '18pt',
158
202
  'use-optimal-row-height' => 'true'
159
203
 
@@ -162,9 +206,9 @@ property :table,
162
206
  ```
163
207
 
164
208
 
165
- ### Credits
166
- Created by [@thiagoarrais](https://github.com/thiagoarrais)
209
+ ## Credits
210
+ Currently Maintained by [@westonganger](https://github.com/westonganger) for simplified ODS spreadsheet creation in the [spreadsheet_architect](https://github.com/westonganger/spreadsheet_architect) gem
167
211
 
168
- Currently maintained by [@westonganger](https://github.com/westonganger) to support simplified ODS spreadsheet making in the [spreadsheet_architect](https://github.com/westonganger/spreadsheet_architect) gem
212
+ Originally Created by [@thiagoarrais](https://github.com/thiagoarrais)
169
213
 
170
- <a href='https://ko-fi.com/A5071NK' target='_blank'><img height='32' style='border:0px;height:32px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /></a>
214
+ Created & Maintained by [Weston Ganger](https://westonganger.com) [(@westonganger)](https://github.com/westonganger) to support simplified ODS spreadsheet making in the [spreadsheet_architect](https://github.com/westonganger/spreadsheet_architect) gem
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/lib/rodf/version.rb')
2
2
  require 'bundler/gem_tasks'
3
3
  require 'rspec/core/rake_task'
4
-
4
+
5
5
  RSpec::Core::RakeTask.new
6
6
 
7
7
  task :test => :spec
data/lib/rodf.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'builder'
2
- require 'rodf/spreadsheet'
2
+ require_relative 'rodf/spreadsheet'
3
3
 
4
4
  module RODF
5
-
5
+
6
6
  end
data/lib/rodf/cell.rb CHANGED
@@ -1,24 +1,13 @@
1
1
  # Copyright (c) 2008 Thiago Arrais
2
2
  #
3
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
4
 
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/>.
5
+ require 'date'
17
6
 
18
7
  require 'builder'
19
8
 
20
- require 'rodf/container'
21
- require 'rodf/paragraph'
9
+ require_relative 'container'
10
+ require_relative 'paragraph'
22
11
 
23
12
  module RODF
24
13
  class Cell < Container
@@ -27,9 +16,11 @@ module RODF
27
16
  alias :p :paragraph
28
17
 
29
18
  def initialize(value=nil, opts={})
19
+ super
20
+
30
21
  if value.is_a?(Hash)
31
22
  opts = value
32
- value = ''
23
+ value = opts[:value]
33
24
  else
34
25
  if value.is_a?(String)
35
26
  value = value.strip
@@ -44,24 +35,20 @@ module RODF
44
35
  @url = opts[:url]
45
36
 
46
37
  if !@type
47
- if value.is_a?(Numeric)
38
+ if @value.is_a?(Numeric)
48
39
  @type = :float
49
40
  elsif @value.respond_to?(:strftime)
41
+ ### for auto type inference force :date type because :time doesnt store any date info
50
42
  @type = :date
51
- @value = value.to_s
52
-
53
- #if value.is_a?(Date)
54
- # @value = value.strftime("%Y-%m-%d")
55
- #else
56
- # @value = value.strftime("%Y%m%dT%H%M%S")
57
- #end
58
43
  else
59
44
  @type = :string
60
- @value = value.to_s
45
+ @value = @value.to_s
61
46
  end
62
47
  end
63
48
  end
64
49
 
50
+ ### TODO: set default DataStyle for the Spreadsheet for Date / Time / DateTime cells formatting
51
+
65
52
  @elem_attrs = make_element_attributes(@type, @value, opts)
66
53
  @multiplier = (opts[:span] || 1).to_i
67
54
 
@@ -93,25 +80,54 @@ module RODF
93
80
 
94
81
  def make_element_attributes(type, value, opts)
95
82
  attrs = {}
96
- attrs['office:value-type'] = type if type == :string || !empty?(value) || !opts[:formula].nil?
97
- attrs['office:date-value'] = value if type == :date && !empty?(value)
98
- attrs['office:value'] = value if type == :float && !empty?(value)
99
- attrs['table:formula'] = opts[:formula] unless opts[:formula].nil?
100
- attrs['table:style-name'] = opts[:style] unless opts[:style].nil?
101
- attrs['table:number-columns-spanned'] = opts[:span] unless opts[:span].nil?
102
- attrs['table:number-matrix-columns-spanned'] =
103
- attrs['table:number-matrix-rows-spanned'] = 1 if opts[:matrix_formula]
83
+
84
+ if !empty?(value) || !opts[:formula].nil? || type == :string
85
+ attrs['office:value-type'] = type
86
+ end
87
+
88
+ if type != :string && !empty?(value)
89
+ case type
90
+ when :date
91
+ attrs['office:date-value'] = value
92
+ when :time
93
+ attrs['office:time-value'] = value
94
+ else ### :float, :percentage, :currency
95
+ attrs['office:value'] = value
96
+ end
97
+ end
98
+
99
+ unless opts[:formula].nil?
100
+ attrs['table:formula'] = opts[:formula]
101
+ end
102
+
103
+ unless opts[:style].nil?
104
+ attrs['table:style-name'] = opts[:style]
105
+ end
106
+
107
+ unless opts[:span].nil?
108
+ attrs['table:number-columns-spanned'] = opts[:span]
109
+ end
110
+
111
+ if opts[:matrix_formula]
112
+ attrs['table:number-matrix-columns-spanned'] = 1
113
+ attrs['table:number-matrix-rows-spanned'] = 1
114
+ end
115
+
104
116
  return attrs
105
117
  end
106
118
 
107
119
  def make_value_paragraph
108
120
  if contains_string?
109
121
  cell, value, url = self, @value, @url
110
- paragraph do
111
- if cell.contains_url?
112
- link value, href: url
113
- else
114
- self << value
122
+
123
+ # Split out newlines to be new cells since the text has been escaped at this point
124
+ value.to_s.split("\n").each do |split_value|
125
+ paragraph do
126
+ if cell.contains_url?
127
+ link split_value, href: url
128
+ else
129
+ self << split_value
130
+ end
115
131
  end
116
132
  end
117
133
  end
@@ -121,5 +137,6 @@ module RODF
121
137
  value.respond_to?(:empty?) ? value.empty? : value.nil?
122
138
  #respond_to?(:empty?) ? (value.empty? || value =~ /\A[[:space:]]*\z/) : value.nil?
123
139
  end
140
+
124
141
  end
125
142
  end