rodf 1.1.1 → 1.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -5
- data/README.md +151 -81
- data/Rakefile +11 -3
- data/lib/rodf/cell.rb +40 -12
- data/lib/rodf/column.rb +9 -2
- data/lib/rodf/container.rb +5 -55
- data/lib/rodf/data_style.rb +27 -9
- data/lib/rodf/document.rb +91 -10
- data/lib/rodf/hyperlink.rb +3 -4
- data/lib/rodf/master_page.rb +1 -4
- data/lib/rodf/page_layout.rb +26 -7
- data/lib/rodf/paragraph.rb +4 -6
- data/lib/rodf/paragraph_container.rb +18 -4
- data/lib/rodf/property.rb +90 -64
- data/lib/rodf/row.rb +39 -11
- data/lib/rodf/skeleton.rb +3 -3
- data/lib/rodf/span.rb +18 -28
- data/lib/rodf/spreadsheet.rb +99 -28
- data/lib/rodf/style.rb +38 -9
- data/lib/rodf/style_section.rb +5 -2
- data/lib/rodf/tab.rb +2 -4
- data/lib/rodf/table.rb +60 -15
- data/lib/rodf/text.rb +111 -31
- data/lib/rodf/version.rb +1 -1
- data/lib/rodf.rb +26 -1
- metadata +12 -26
- data/lib/rodf/compatibility.rb +0 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ecdbdfb0a316bd69319bcf9fa7371c5e9335317b32153a762819326cd15f7f8a
|
|
4
|
+
data.tar.gz: 07a3016afb19f9c675042a7ee38749eb83040ab04068f3daaea4794903eefde2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 85922b050febd96f80601fd0e5885fbe15cbd73e55b54ebfc850e0e5adffac13d002d0f038a223d10de8a194f0a30b073d71387cd7abe95f93f8146b23dc8090
|
|
7
|
+
data.tar.gz: a66a6811cd575ce4d4a5fd1f77b77a7acaca939624b3ecfb9b5797331d9b23a28aafd484f7ca25e5564a358a2cb554f92d2c491ff1ae496e0491865f12b71d29
|
data/CHANGELOG.md
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
## Unreleased
|
|
3
|
+
## Unreleased - [View Diff](https://github.com/westonganger/rodf/compare/v1.3.0..master)
|
|
4
4
|
- Nothing yet
|
|
5
5
|
|
|
6
|
-
## v1.
|
|
6
|
+
## v1.3.0 - [View Diff](https://github.com/westonganger/rodf/compare/v1.2.0..v1.3.0)
|
|
7
|
+
- [#49](https://github.com/westonganger/rodf/pull/49) - Ensure `bytes` method doesnt use zip64 which started happening with rubyzip >= 3.0
|
|
8
|
+
- Require rubyzip >= 3.2 which requires Ruby 3.0+
|
|
9
|
+
|
|
10
|
+
## v1.2.0 - [View Diff](https://github.com/westonganger/rodf/compare/v1.1.1..v1.2.0)
|
|
11
|
+
- Allow passing `:style` argument to `Span`
|
|
12
|
+
- Added `Table#set_column_widths` method
|
|
13
|
+
- Style `:family` option now supports String and Symbol keys. Previously `:family` the family option would only support the key name as a Symbol.
|
|
14
|
+
- Improve Style List Documentation
|
|
15
|
+
- Allow adding XML attributes directly to `Table`, `Row`, `Column`, `Cell` using the `:attributes` argument
|
|
16
|
+
- Remove usage of `contains` metaprogramming method `Container#contains` that was hiding major implementation details from most RODF classes. The code is now much easier to understand.
|
|
17
|
+
|
|
18
|
+
## v1.1.1 - [View Diff](https://github.com/westonganger/rodf/compare/v1.1.0..v1.1.1)
|
|
7
19
|
- [Issue #36](https://github.com/westonganger/rodf/issues/36) - Improve compatibility for Float Cells
|
|
8
20
|
- Fix gemspec require for Ruby 1.9
|
|
9
21
|
- Cleanup File Commenting
|
|
10
22
|
|
|
11
|
-
## v1.1.0
|
|
23
|
+
## v1.1.0 - [View Diff](https://github.com/westonganger/rodf/compare/v1.0.0..v1.1.0)
|
|
12
24
|
- [#34](https://github.com/westonganger/rodf/pull/34) - Add ability to add many rows or cells at once
|
|
13
25
|
- [#29](https://github.com/westonganger/rodf/pull/29) - Remove ActiveSupport dependency in favor of `dry-inflector`
|
|
14
26
|
- [#21](https://github.com/thiagoarrais/rodf/pull/21) - Allow more attributes for the `data_style` method
|
|
15
27
|
- [#19](https://github.com/westonganger/rodf/issues/19) - Changes to Date/Time handling
|
|
16
28
|
|
|
17
|
-
## v1.0.0
|
|
29
|
+
## v1.0.0 - [View Diff](https://github.com/westonganger/rodf/compare/v0.3.7..v1.0.0)
|
|
18
30
|
- Rename main module ODF to RODF, Fix cell types
|
|
19
31
|
|
|
20
32
|
## v0.3.7
|
|
@@ -59,7 +71,7 @@
|
|
|
59
71
|
## v0.1.3
|
|
60
72
|
- Dependency fix (by Merul Patel)
|
|
61
73
|
|
|
62
|
-
## v0.1.2
|
|
74
|
+
## v0.1.2
|
|
63
75
|
- Cell span
|
|
64
76
|
|
|
65
77
|
## v0.1.1
|
data/README.md
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# RODF
|
|
2
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://
|
|
4
|
-
<a href='https://rubygems.org/gems/rodf' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://
|
|
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
|
+
<a href='https://github.com/westonganger/rodf/actions' target='_blank'><img src="https://github.com/westonganger/rodf/actions/workflows/test.yml/badge.svg?branch=master" style="max-width:100%;" height='21' style='border:0px;height:21px;' border='0' alt="CI Status"></a>
|
|
4
|
+
<a href='https://rubygems.org/gems/rodf' target='_blank'><img height='21' style='border:0px;height:21px;' src='https://img.shields.io/gem/dt/rodf?color=brightgreen&label=Rubygems%20Downloads' border='0' alt='RubyGems Downloads' /></a>
|
|
6
5
|
|
|
7
6
|
RODF is a library for writing to ODF output from Ruby. It mainly focuses creating ODS spreadsheets.
|
|
8
7
|
|
|
@@ -14,13 +13,11 @@ As well as writing ODS spreadsheets, this library also can write ODT text docume
|
|
|
14
13
|
gem install rodf
|
|
15
14
|
```
|
|
16
15
|
|
|
17
|
-
##
|
|
16
|
+
## Usage
|
|
18
17
|
|
|
19
18
|
RODF works pretty much like Builder, but with ODF-aware constructs. For example:
|
|
20
19
|
|
|
21
20
|
```ruby
|
|
22
|
-
require 'rodf'
|
|
23
|
-
|
|
24
21
|
RODF::Spreadsheet.file("my-spreadsheet.ods") do
|
|
25
22
|
table 'My first table from Ruby' do
|
|
26
23
|
row do
|
|
@@ -33,12 +30,10 @@ end
|
|
|
33
30
|
For access to variables and methods from outer code you can use block parameter:
|
|
34
31
|
|
|
35
32
|
```ruby
|
|
36
|
-
require 'rodf'
|
|
37
|
-
|
|
38
33
|
@data = 'Hello world!'
|
|
39
34
|
|
|
40
|
-
RODF::Spreadsheet.file("my-spreadsheet.ods") do |
|
|
41
|
-
|
|
35
|
+
RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|
|
|
36
|
+
sheet.table 'My first table from Ruby' do |table|
|
|
42
37
|
table.row do |row|
|
|
43
38
|
row.cell @data
|
|
44
39
|
end
|
|
@@ -49,18 +44,16 @@ end
|
|
|
49
44
|
Adding many rows or cells at once is supported as well:
|
|
50
45
|
|
|
51
46
|
```ruby
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
table 'My first table from Ruby' do
|
|
56
|
-
add_rows([
|
|
47
|
+
RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|
|
|
48
|
+
sheet.table 'My first table from Ruby' do |t|
|
|
49
|
+
t.add_rows([
|
|
57
50
|
[1, 'Alice'],
|
|
58
51
|
[2, { value: 'Bob', color: '#ff0000'}],
|
|
59
52
|
[3, 'Carol']
|
|
60
53
|
])
|
|
61
54
|
|
|
62
|
-
row do
|
|
63
|
-
add_cells ['ID', 'Name']
|
|
55
|
+
t.row do |r|
|
|
56
|
+
r.add_cells ['ID', 'Name']
|
|
64
57
|
end
|
|
65
58
|
end
|
|
66
59
|
end
|
|
@@ -71,9 +64,8 @@ end
|
|
|
71
64
|
The declarative style shown above is just syntatic sugar. A more procedural style can also be used. Like so:
|
|
72
65
|
|
|
73
66
|
```ruby
|
|
74
|
-
require 'rodf'
|
|
75
|
-
|
|
76
67
|
ss = RODF::Spreadsheet.new
|
|
68
|
+
|
|
77
69
|
t = ss.table 'My first table from Ruby'
|
|
78
70
|
r = t.row
|
|
79
71
|
c = r.cell 'Hello world!'
|
|
@@ -82,82 +74,130 @@ c = r.cell 'Hello world!'
|
|
|
82
74
|
ss.write_to 'my-spreadsheet.ods'
|
|
83
75
|
# or
|
|
84
76
|
File.write('my-spreadsheet.ods', ss.bytes) # you can send your data in Rails over HTTP using the bytes method
|
|
85
|
-
end
|
|
86
77
|
```
|
|
87
78
|
|
|
88
79
|
Both styles can be mixed and matched at will:
|
|
89
80
|
|
|
90
81
|
```ruby
|
|
91
|
-
require 'rodf'
|
|
92
|
-
|
|
93
82
|
ss = RODF::Spreadsheet.new
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
83
|
+
|
|
84
|
+
ss.table 'My first table from Ruby' do |t|
|
|
85
|
+
t.row do |r|
|
|
86
|
+
r.cell 'Hello world!'
|
|
97
87
|
end
|
|
98
88
|
end
|
|
99
89
|
|
|
100
90
|
ss.write_to 'my-spreadsheet.ods'
|
|
101
91
|
```
|
|
102
92
|
|
|
103
|
-
Styling and
|
|
93
|
+
## Styling and Formatting
|
|
104
94
|
|
|
105
95
|
```ruby
|
|
106
|
-
|
|
96
|
+
RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|
|
|
107
97
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
|
|
98
|
+
sheet.style 'red-cell', family: :cell do |s|
|
|
99
|
+
s.property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
|
|
111
100
|
end
|
|
112
101
|
|
|
113
|
-
|
|
114
|
-
row
|
|
115
|
-
|
|
102
|
+
sheet.style 'row-height', family: :row do |s|
|
|
103
|
+
s.property :row, 'row-height' => '18pt', 'use-optimal-row-height' => 'true'
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
sheet.table 'Red text table' do |t|
|
|
107
|
+
t.row style: 'row-height' do |r|
|
|
108
|
+
r.cell 'Red', style: 'red-cell'
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
sheet.table 'Text with Paragraphs' do |t|
|
|
113
|
+
t.row style: 'row-height' do |r|
|
|
114
|
+
r.cell do |cell|
|
|
115
|
+
cell.paragraph do |paragraph|
|
|
116
|
+
text_array = my_text_content.split("\n").select{|x| !x.empty? }
|
|
117
|
+
|
|
118
|
+
text_array.each do |str|
|
|
119
|
+
if str.start_with?("#")
|
|
120
|
+
paragraph.span(str, style: 'red-cell')
|
|
121
|
+
else
|
|
122
|
+
paragraph.span(str)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
116
127
|
end
|
|
117
128
|
end
|
|
129
|
+
|
|
118
130
|
end
|
|
119
131
|
```
|
|
120
132
|
|
|
121
133
|
Conditional formatting is also possible:
|
|
122
134
|
|
|
123
135
|
```ruby
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
RODF::Spreadsheet.file("my-spreadsheet.ods") do
|
|
136
|
+
RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|
|
|
127
137
|
|
|
128
|
-
office_style 'red-cell', family: :cell do
|
|
129
|
-
property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
|
|
138
|
+
sheet.office_style 'red-cell', family: :cell do |s|
|
|
139
|
+
s.property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
|
|
130
140
|
end
|
|
131
141
|
|
|
132
|
-
office_style 'green-cell', family: :cell do
|
|
133
|
-
property :text, 'font-weight' => 'bold', 'color' => '#00ff00'
|
|
142
|
+
sheet.office_style 'green-cell', family: :cell do |s|
|
|
143
|
+
s.property :text, 'font-weight' => 'bold', 'color' => '#00ff00'
|
|
134
144
|
end
|
|
135
145
|
|
|
136
146
|
# conditional formating must be defined as style and the value of
|
|
137
147
|
# apply-style-name must be an office_style
|
|
138
|
-
style 'cond1', family: :cell do
|
|
139
|
-
property :conditional, 'condition' => 'cell-content()<0', 'apply-style-name' => 'red-cell'
|
|
148
|
+
sheet.style 'cond1', family: :cell do |s|
|
|
149
|
+
s.property :conditional, 'condition' => 'cell-content()<0', 'apply-style-name' => 'red-cell'
|
|
140
150
|
|
|
141
|
-
property :conditional, 'condition' => 'cell-content()>0', 'apply-style-name' => 'green-cell'
|
|
151
|
+
s.property :conditional, 'condition' => 'cell-content()>0', 'apply-style-name' => 'green-cell'
|
|
142
152
|
end
|
|
143
153
|
|
|
144
|
-
table 'Red text table' do
|
|
145
|
-
row do
|
|
146
|
-
cell 'Red force', style: 'red-cell'
|
|
154
|
+
sheet.table 'Red text table' do |t|
|
|
155
|
+
t.row do |r|
|
|
156
|
+
r.cell 'Red force', style: 'red-cell'
|
|
147
157
|
end
|
|
148
|
-
row do
|
|
149
|
-
cell '-4', type: :float, style: 'cond1'
|
|
158
|
+
t.row do |r|
|
|
159
|
+
r.cell '-4', type: :float, style: 'cond1'
|
|
150
160
|
end
|
|
151
|
-
row do
|
|
152
|
-
cell '0', type: :float, style: 'cond1'
|
|
161
|
+
t.row do |r|
|
|
162
|
+
r.cell '0', type: :float, style: 'cond1'
|
|
153
163
|
end
|
|
154
|
-
row do
|
|
155
|
-
cell '5', type: :float, style: 'cond1'
|
|
164
|
+
t.row do |r|
|
|
165
|
+
r.cell '5', type: :float, style: 'cond1'
|
|
156
166
|
end
|
|
157
167
|
end
|
|
158
168
|
end
|
|
159
169
|
```
|
|
160
170
|
|
|
171
|
+
## Changing Columns Widths
|
|
172
|
+
|
|
173
|
+
Adding columns or columns width to your spreadsheet can be done with the following
|
|
174
|
+
|
|
175
|
+
```ruby
|
|
176
|
+
RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|
|
|
177
|
+
sheet.table "foo" do |t|
|
|
178
|
+
sheet.style('default-col-width', family: :column) do |s|
|
|
179
|
+
s.property(:column, 'column-width' => '1.234in')
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
col_count.times do
|
|
183
|
+
t.column style: 'default-col-width'
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
### OR
|
|
187
|
+
|
|
188
|
+
### Warning this will overwrite any existing table columns (cells remain unaffected)
|
|
189
|
+
sheet.set_column_widths(
|
|
190
|
+
table: t,
|
|
191
|
+
column_widths: [
|
|
192
|
+
{'column-width' => '1in'},
|
|
193
|
+
{'column-width' => '2cm'},
|
|
194
|
+
{'column-width' => '2.54cm'},
|
|
195
|
+
],
|
|
196
|
+
)
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
```
|
|
200
|
+
|
|
161
201
|
## Columns Types
|
|
162
202
|
|
|
163
203
|
Available columns types are:
|
|
@@ -171,37 +211,67 @@ Available columns types are:
|
|
|
171
211
|
|
|
172
212
|
## Style List
|
|
173
213
|
```ruby
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
property :
|
|
202
|
-
|
|
214
|
+
### family: :cell or "table-cell"
|
|
215
|
+
style "my-cell-style", family: :cell do
|
|
216
|
+
property :text,
|
|
217
|
+
'font-weight' => :bold, #options are :bold, :thin
|
|
218
|
+
'font-size' => 12,
|
|
219
|
+
'font-name' => 'Arial',
|
|
220
|
+
'font-style' => 'italic',
|
|
221
|
+
'text-underline-style' => 'solid', # solid, dashed, dotted, double
|
|
222
|
+
'text-underline-type' => 'single',
|
|
223
|
+
'text-line-through-style' => 'solid',
|
|
224
|
+
align: true,
|
|
225
|
+
color: "#000000"
|
|
226
|
+
|
|
227
|
+
property :cell,
|
|
228
|
+
'background-color' => "#DDDDDD",
|
|
229
|
+
'wrap-option' => 'wrap',
|
|
230
|
+
'vertical_align' => 'automatic',
|
|
231
|
+
'border-top' => '0.75pt solid #999999',
|
|
232
|
+
'border-bottom' => '0.75pt solid #999999',
|
|
233
|
+
'border-left' => '0.75pt solid #999999',
|
|
234
|
+
'border-right' => '0.75pt solid #999999',
|
|
235
|
+
'writing-mode' => 'lr-tb',
|
|
236
|
+
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
### family: :column or "table-column"
|
|
240
|
+
style('my-col-style', family: :column) do
|
|
241
|
+
property :column,
|
|
242
|
+
'column-width' => '4.0cm'
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
### family: :row or "table-row"
|
|
246
|
+
style('my-row-style', family: :row) do
|
|
247
|
+
property :row,
|
|
248
|
+
'row-height' => '18pt',
|
|
249
|
+
'use-optimal-row-height' => 'true'
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
### family: :table
|
|
253
|
+
style('my-row-style', family: :table) do
|
|
254
|
+
property :table,
|
|
255
|
+
'writing-mode' => 'lr-tb',
|
|
203
256
|
```
|
|
204
257
|
|
|
258
|
+
## Adding Arbitrary XML Attributes
|
|
259
|
+
|
|
260
|
+
```ruby
|
|
261
|
+
RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|
|
|
262
|
+
sheet.table 'My first table from Ruby', attributes: {'table-protected' => 'true'} do |table|
|
|
263
|
+
table.row do |row|
|
|
264
|
+
row.cell @data
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Production Usage Examples
|
|
272
|
+
|
|
273
|
+
- `spreadsheet_architect` gem - [View Relevant Source Code](https://github.com/westonganger/spreadsheet_architect/blob/master/lib/spreadsheet_architect/class_methods/ods.rb)
|
|
274
|
+
|
|
205
275
|
## Credits
|
|
206
276
|
|
|
207
277
|
Originally Created by [@thiagoarrais](https://github.com/thiagoarrais)
|
data/Rakefile
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/lib/rodf/version.rb')
|
|
2
2
|
require 'bundler/gem_tasks'
|
|
3
|
-
require 'rspec/core/rake_task'
|
|
4
|
-
|
|
5
|
-
RSpec::Core::RakeTask.new
|
|
6
3
|
|
|
7
4
|
task :test => :spec
|
|
8
5
|
task :default => :test
|
|
6
|
+
|
|
7
|
+
task :spec do
|
|
8
|
+
system("rspec", out: STDOUT)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
task :console do
|
|
12
|
+
require 'rodf'
|
|
13
|
+
|
|
14
|
+
require 'irb'
|
|
15
|
+
binding.irb
|
|
16
|
+
end
|
data/lib/rodf/cell.rb
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
require 'date'
|
|
2
|
-
|
|
3
|
-
require 'builder'
|
|
4
|
-
|
|
5
|
-
require_relative 'container'
|
|
6
|
-
require_relative 'paragraph'
|
|
7
|
-
|
|
8
1
|
module RODF
|
|
9
2
|
class Cell < Container
|
|
10
|
-
contains :paragraphs
|
|
11
|
-
|
|
12
|
-
alias :p :paragraph
|
|
13
3
|
|
|
14
4
|
def initialize(value=nil, opts={})
|
|
15
5
|
super
|
|
@@ -25,6 +15,7 @@ module RODF
|
|
|
25
15
|
end
|
|
26
16
|
|
|
27
17
|
@value = value || ''
|
|
18
|
+
|
|
28
19
|
@type = opts[:type]
|
|
29
20
|
|
|
30
21
|
unless empty?(@value)
|
|
@@ -46,21 +37,58 @@ module RODF
|
|
|
46
37
|
### TODO: set default DataStyle for the Spreadsheet for Date / Time / DateTime cells formatting
|
|
47
38
|
|
|
48
39
|
@elem_attrs = make_element_attributes(@type, @value, opts)
|
|
40
|
+
|
|
41
|
+
if opts[:attributes]
|
|
42
|
+
@elem_attrs.merge!(opts[:attributes])
|
|
43
|
+
end
|
|
44
|
+
|
|
49
45
|
@multiplier = (opts[:span] || 1).to_i
|
|
50
46
|
|
|
51
47
|
make_value_paragraph
|
|
52
48
|
end
|
|
53
49
|
|
|
50
|
+
def paragraphs
|
|
51
|
+
@paragraphs ||= []
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def paragraph(*args, &block)
|
|
55
|
+
x = Paragraph.new(*args, &block)
|
|
56
|
+
|
|
57
|
+
paragraphs << x
|
|
58
|
+
|
|
59
|
+
return x
|
|
60
|
+
end
|
|
61
|
+
alias p paragraph
|
|
62
|
+
|
|
63
|
+
def paragraphs_xml
|
|
64
|
+
paragraphs.map(&:xml).join
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def add_paragraphs(*elements)
|
|
68
|
+
if elements.first.is_a?(Array)
|
|
69
|
+
elements = elements.first
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
elements.each do |element|
|
|
73
|
+
paragraph(element)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
54
77
|
def style=(style_name)
|
|
55
78
|
@elem_attrs['table:style-name'] = style_name
|
|
56
79
|
end
|
|
57
80
|
|
|
58
81
|
def xml
|
|
59
82
|
markup = Builder::XmlMarkup.new
|
|
83
|
+
|
|
60
84
|
text = markup.tag! 'table:table-cell', @elem_attrs do |xml|
|
|
61
85
|
xml << paragraphs_xml
|
|
62
86
|
end
|
|
63
|
-
|
|
87
|
+
|
|
88
|
+
(@multiplier - 1).times do
|
|
89
|
+
text = markup.tag! 'table:table-cell'
|
|
90
|
+
end
|
|
91
|
+
|
|
64
92
|
text
|
|
65
93
|
end
|
|
66
94
|
|
|
@@ -68,7 +96,7 @@ module RODF
|
|
|
68
96
|
!empty?(@url)
|
|
69
97
|
end
|
|
70
98
|
|
|
71
|
-
|
|
99
|
+
private
|
|
72
100
|
|
|
73
101
|
def make_element_attributes(type, value, opts)
|
|
74
102
|
attrs = {}
|
data/lib/rodf/column.rb
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
require 'builder'
|
|
2
|
-
|
|
3
1
|
module RODF
|
|
4
2
|
class Column
|
|
5
3
|
def initialize(opts={})
|
|
6
4
|
@elem_attrs = {}
|
|
5
|
+
|
|
7
6
|
@elem_attrs['table:style-name'] = opts[:style] unless opts[:style].nil?
|
|
7
|
+
|
|
8
|
+
if opts[:attributes]
|
|
9
|
+
@elem_attrs.merge!(opts[:attributes])
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def style=(style_name)
|
|
14
|
+
@elem_attrs['table:style-name'] = style_name
|
|
8
15
|
end
|
|
9
16
|
|
|
10
17
|
def xml
|
data/lib/rodf/container.rb
CHANGED
|
@@ -1,60 +1,5 @@
|
|
|
1
|
-
require 'dry/inflector'
|
|
2
|
-
|
|
3
1
|
module RODF
|
|
4
2
|
class Container
|
|
5
|
-
INFLECTOR = Dry::Inflector.new.freeze
|
|
6
|
-
|
|
7
|
-
def self.contains(*stuffs_array)
|
|
8
|
-
stuffs_array.map {|sym| sym.to_s}.each do |stuffs|
|
|
9
|
-
stuff = INFLECTOR.singularize(stuffs.to_s)
|
|
10
|
-
stuff_class = RODF.const_get(INFLECTOR.camelize(stuff))
|
|
11
|
-
|
|
12
|
-
module_for_stuff.instance_exec do
|
|
13
|
-
define_method stuffs do
|
|
14
|
-
instance_variable_name = :"@#{stuffs}"
|
|
15
|
-
|
|
16
|
-
if instance_variable_defined?(instance_variable_name)
|
|
17
|
-
return instance_variable_get(instance_variable_name)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
instance_variable_set(instance_variable_name, [])
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
define_method stuff do |*args, &contents|
|
|
24
|
-
c = stuff_class.new(*args, &contents)
|
|
25
|
-
public_send(stuffs) << c
|
|
26
|
-
c
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
define_method "add_#{stuffs}" do |*elements|
|
|
30
|
-
elements = elements.first if elements.first.is_a?(Array)
|
|
31
|
-
elements.each do |element|
|
|
32
|
-
public_send(stuff, element)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
define_method "#{stuffs}_xml" do
|
|
37
|
-
public_send(stuffs).map(&:xml).join
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def self.module_for_stuff
|
|
44
|
-
if const_defined?(:StuffMethods, false)
|
|
45
|
-
mod = const_get(:StuffMethods)
|
|
46
|
-
else
|
|
47
|
-
mod = const_set(:StuffMethods, Module.new)
|
|
48
|
-
include mod
|
|
49
|
-
end
|
|
50
|
-
mod
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def self.create(*args, &contents)
|
|
54
|
-
container = new(*args, &contents)
|
|
55
|
-
container.xml
|
|
56
|
-
end
|
|
57
|
-
|
|
58
3
|
def initialize(*_args, &contents)
|
|
59
4
|
return unless contents
|
|
60
5
|
|
|
@@ -64,5 +9,10 @@ module RODF
|
|
|
64
9
|
yield(self)
|
|
65
10
|
end
|
|
66
11
|
end
|
|
12
|
+
|
|
13
|
+
def self.create(*args, &contents)
|
|
14
|
+
container = self.new(*args, &contents)
|
|
15
|
+
container.xml
|
|
16
|
+
end
|
|
67
17
|
end
|
|
68
18
|
end
|
data/lib/rodf/data_style.rb
CHANGED
|
@@ -1,20 +1,38 @@
|
|
|
1
|
-
require 'builder'
|
|
2
|
-
|
|
3
|
-
require_relative 'container'
|
|
4
|
-
require_relative 'style_section'
|
|
5
|
-
|
|
6
1
|
module RODF
|
|
7
2
|
class DataStyle < Container
|
|
8
|
-
contains :style_sections
|
|
9
|
-
|
|
10
|
-
alias section style_section
|
|
11
|
-
|
|
12
3
|
def initialize(name, type)
|
|
13
4
|
super
|
|
14
5
|
|
|
15
6
|
@type, @name = type, name
|
|
16
7
|
end
|
|
17
8
|
|
|
9
|
+
def style_sections
|
|
10
|
+
@style_sections ||= []
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def style_section(*args, &block)
|
|
14
|
+
x = StyleSection.new(*args, &block)
|
|
15
|
+
|
|
16
|
+
style_sections << x
|
|
17
|
+
|
|
18
|
+
return x
|
|
19
|
+
end
|
|
20
|
+
alias section style_section
|
|
21
|
+
|
|
22
|
+
def style_sections_xml
|
|
23
|
+
style_sections.map(&:xml).join
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def add_style_sections(*elements)
|
|
27
|
+
if elements.first.is_a?(Array)
|
|
28
|
+
elements = elements.first
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
elements.each do |element|
|
|
32
|
+
style_section(element)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
18
36
|
def xml
|
|
19
37
|
Builder::XmlMarkup.new.tag! "number:#{@type}-style", 'style:name' => @name do |xml|
|
|
20
38
|
xml << style_sections_xml
|