redmine_api_helper 0.3.35

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.

Potentially problematic release.


This version of redmine_api_helper might be problematic. Click here for more details.

Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +2 -0
  3. data/.gitignore +11 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE +339 -0
  7. data/README.md +30 -0
  8. data/Rakefile +2 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/date_helper/date.rb +311 -0
  12. data/lib/odf_writer/bookmark.rb +110 -0
  13. data/lib/odf_writer/bookmark_reader.rb +77 -0
  14. data/lib/odf_writer/document.rb +371 -0
  15. data/lib/odf_writer/field.rb +174 -0
  16. data/lib/odf_writer/field_reader.rb +78 -0
  17. data/lib/odf_writer/image.rb +176 -0
  18. data/lib/odf_writer/image_reader.rb +76 -0
  19. data/lib/odf_writer/images.rb +89 -0
  20. data/lib/odf_writer/list_style.rb +336 -0
  21. data/lib/odf_writer/nested.rb +156 -0
  22. data/lib/odf_writer/odf_helper.rb +57 -0
  23. data/lib/odf_writer/parser/default.rb +691 -0
  24. data/lib/odf_writer/path_finder.rb +114 -0
  25. data/lib/odf_writer/section.rb +120 -0
  26. data/lib/odf_writer/section_reader.rb +61 -0
  27. data/lib/odf_writer/style.rb +483 -0
  28. data/lib/odf_writer/table.rb +135 -0
  29. data/lib/odf_writer/table_reader.rb +61 -0
  30. data/lib/odf_writer/template.rb +234 -0
  31. data/lib/odf_writer/text.rb +97 -0
  32. data/lib/odf_writer/text_reader.rb +77 -0
  33. data/lib/odf_writer/version.rb +29 -0
  34. data/lib/redmine_api_helper/api_helper.rb +333 -0
  35. data/lib/redmine_api_helper/args_helper.rb +106 -0
  36. data/lib/redmine_api_helper/attachments_api_helper.rb +52 -0
  37. data/lib/redmine_api_helper/define_api_helpers.rb +78 -0
  38. data/lib/redmine_api_helper/document_categories_api_helper.rb +38 -0
  39. data/lib/redmine_api_helper/groups_api_helper.rb +80 -0
  40. data/lib/redmine_api_helper/helpers.rb +50 -0
  41. data/lib/redmine_api_helper/issue_priorities_api_helper.rb +38 -0
  42. data/lib/redmine_api_helper/issue_relations_api_helper.rb +66 -0
  43. data/lib/redmine_api_helper/issue_statuses_api_helper.rb +36 -0
  44. data/lib/redmine_api_helper/issues_api_helper.rb +124 -0
  45. data/lib/redmine_api_helper/my_account_api_helper.rb +45 -0
  46. data/lib/redmine_api_helper/news_api_helper.rb +73 -0
  47. data/lib/redmine_api_helper/project_memberships_api_helper.rb +77 -0
  48. data/lib/redmine_api_helper/projects_api_helper.rb +73 -0
  49. data/lib/redmine_api_helper/roles_api_helper.rb +52 -0
  50. data/lib/redmine_api_helper/scripts_api_helper.rb +87 -0
  51. data/lib/redmine_api_helper/search_api_helper.rb +38 -0
  52. data/lib/redmine_api_helper/time_entries_api_helper.rb +73 -0
  53. data/lib/redmine_api_helper/time_entry_activities_api_helper.rb +38 -0
  54. data/lib/redmine_api_helper/trackers_api_helper.rb +38 -0
  55. data/lib/redmine_api_helper/users_api_helper.rb +73 -0
  56. data/lib/redmine_api_helper/version.rb +24 -0
  57. data/lib/redmine_api_helper/wiki_pages_api_helper.rb +66 -0
  58. data/lib/redmine_api_helper.rb +88 -0
  59. data/redmine_api_helper.gemspec +36 -0
  60. metadata +162 -0
@@ -0,0 +1,483 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Ruby Gem to create a self populating Open Document Format (.odf) text file.
4
+ #
5
+ # Copyright 2021 Stephan Wenzel <stephan.wenzel@drwpatent.de>
6
+ #
7
+ # This program is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License
9
+ # as published by the Free Software Foundation; either version 2
10
+ # of the License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
+ #
21
+
22
+ module ODFWriter
23
+
24
+ ########################################################################################
25
+ #
26
+ # Style: add styles to styles.xml
27
+ #
28
+ ########################################################################################
29
+ class Style
30
+
31
+ ######################################################################################
32
+ #
33
+ # constants
34
+ #
35
+ ######################################################################################
36
+ DOC_STYLES = [:h1, :h2, :h3, :h4, :h5, :h6, # header style
37
+ :paragraph, :subparagraph, :redmine # paragraph style
38
+ ]
39
+
40
+ AUT_STYLES = [:bold, :underline, :italic, :strikethrough, # character style
41
+ :sub, :sup, :code, :a, :large, :medium, :small, # character style
42
+
43
+ :center, :left, :right, :justify, # paragraph style
44
+ :p, :mono, :monoright, :monocenter, :cling, # paragraph style
45
+ :quote, :pre, # paragraph style
46
+
47
+ :table, :thrifty, :tiny, :list, :listmedium, # table style
48
+ :invoice, :boxes, :caption, # table style
49
+
50
+ :tr, :td, :tdbott, :tdbox, :tdhead, :tdfoot, # table content style
51
+ :tc, :tcnarrow, :tcwide, :tcfixed, :tcauto # table content style
52
+ ]
53
+
54
+ LIST_STYLES = [:ul, :ol]
55
+
56
+ ######################################################################################
57
+ #
58
+ # initialize
59
+ #
60
+ ######################################################################################
61
+ def initialize( *styles )
62
+ @styles = *styles
63
+ @font = {}
64
+ end #def
65
+
66
+
67
+ ######################################################################################
68
+ #
69
+ # add_style
70
+ #
71
+ ######################################################################################
72
+ def add_automatic_style( doc )
73
+ ns = doc.collect_namespaces
74
+ automatic_styles = doc.at("//office:automatic-styles", ns)
75
+ font_declarations = doc.at("//office:font-face-decls", ns)
76
+
77
+ @styles.each do |style|
78
+
79
+ @font = nil # will be set in create_style
80
+ automatic_styles << create_style( doc, style ) if automatic_styles.present?
81
+
82
+ if @font.present?
83
+ font_declarations << create_font( doc, @font ) if font_declarations.present?
84
+ end
85
+ end
86
+
87
+ end #def
88
+
89
+ ######################################################################################
90
+ #
91
+ # add_style
92
+ #
93
+ ######################################################################################
94
+ def add_document_style( doc )
95
+ ns = doc.collect_namespaces
96
+ automatic_styles = doc.at("//office:document-styles", ns)
97
+ font_declarations = doc.at("//office:font-face-decls", ns)
98
+
99
+ @styles.each do |style|
100
+
101
+ @font = nil # will be set in create_style
102
+ automatic_styles << create_style( doc, style ) if automatic_styles.present?
103
+
104
+ if @font.present?
105
+ font_declarations << create_font( doc, @font ) if font_declarations.present?
106
+ end
107
+ end
108
+
109
+ end #def
110
+
111
+
112
+ ######################################################################################
113
+ #
114
+ # private
115
+ #
116
+ ######################################################################################
117
+ private
118
+
119
+ def create_font( doc, font )
120
+ node = Nokogiri::XML::Node.new('style:font-face', doc)
121
+ node["style:name"] = font[:font_name]
122
+ node["svg:font-family"] = font[:font_family]
123
+ node["style:font-family-generic"] = font[:font_family_generic]
124
+ node["style:font-pitch"] = font[:font_pitch]
125
+ node
126
+ end #def
127
+
128
+ def create_style( doc, stylename )
129
+
130
+ style = Nokogiri::XML::Node.new('style:style', doc)
131
+
132
+ #
133
+ # common properties
134
+ #
135
+ case stylename
136
+
137
+ when :bold, :underline, :italic, :strikethrough, :sub, :sup, :code, :a, :large, :medium, :small
138
+ style["style:name"] =stylename.to_s
139
+ style["style:family"] ="text"
140
+
141
+ text_properties = Nokogiri::XML::Node.new('style:text-properties', doc)
142
+ style << text_properties
143
+
144
+ when /h(\d)/i
145
+ style["style:name"] =stylename.to_s
146
+ style["style:family"] ="paragraph"
147
+ style["style:parent-style-name"] ="Standard"
148
+ style["style:next-style-name"] ="paragraph"
149
+ style["style:default-outline-level"] =$1 #matches number behind 'h'
150
+
151
+ paragraph_properties = Nokogiri::XML::Node.new('style:paragraph-properties', doc)
152
+ style << paragraph_properties
153
+
154
+ text_properties = Nokogiri::XML::Node.new('style:text-properties', doc)
155
+ style << text_properties
156
+
157
+ when :p, :mono, :monoright, :monocenter, :cling
158
+ style["style:name"] =stylename.to_s
159
+ style["style:family"] ="paragraph"
160
+ style["style:parent-style-name"] ="Standard"
161
+ style["style:next-style-name"] ="paragraph"
162
+
163
+ paragraph_properties = Nokogiri::XML::Node.new('style:paragraph-properties', doc)
164
+ style << paragraph_properties
165
+
166
+ text_properties = Nokogiri::XML::Node.new('style:text-properties', doc)
167
+ style << text_properties
168
+
169
+ when :subparagraph
170
+ style["style:name"] =stylename.to_s
171
+ style["style:family"] ="paragraph"
172
+ style["style:parent-style-name"] ="paragraph"
173
+ style["style:next-style-name"] ="paragraph"
174
+
175
+ paragraph_properties = Nokogiri::XML::Node.new('style:paragraph-properties', doc)
176
+ style << paragraph_properties
177
+
178
+ text_properties = Nokogiri::XML::Node.new('style:text-properties', doc)
179
+ style << text_properties
180
+
181
+ when :center, :left, :right, :justify
182
+ style["style:name"] =stylename.to_s
183
+ style["style:family"] ="paragraph"
184
+ style["style:parent-style-name"] ="paragraph"
185
+
186
+ paragraph_properties = Nokogiri::XML::Node.new('style:paragraph-properties', doc)
187
+ style << paragraph_properties
188
+
189
+ when :quote, :pre
190
+ style["style:name"] =stylename.to_s
191
+ style["style:family"] ="paragraph"
192
+ style["style:parent-style-name"] ="Standard"
193
+
194
+ paragraph_properties = Nokogiri::XML::Node.new('style:paragraph-properties', doc)
195
+ style << paragraph_properties
196
+
197
+ text_properties = Nokogiri::XML::Node.new('style:text-properties', doc)
198
+ style << text_properties
199
+
200
+ when :table, :list, :listmedium, :invoice, :boxes, :caption, :thrifty, :tiny
201
+ style["style:name"] =stylename.to_s
202
+ style["style:family"] ="table"
203
+
204
+ table_properties = Nokogiri::XML::Node.new('style:table-properties', doc)
205
+ style << table_properties
206
+
207
+ when :tr
208
+ style["style:name"] =stylename.to_s
209
+ style["style:family"] ="table-row"
210
+
211
+ table_row_properties = Nokogiri::XML::Node.new('style:table-row-properties', doc)
212
+ style << table_row_properties
213
+
214
+ when :tc, :tcnarrow, :tcwide, :tcfixed, :tcauto
215
+ style["style:name"] =stylename.to_s
216
+ style["style:family"] ="table-column"
217
+
218
+ table_column_properties = Nokogiri::XML::Node.new('style:table-column-properties', doc)
219
+ style << table_column_properties
220
+
221
+ when :td, :tdbott, :tdhead, :tdfoot, :tdbox
222
+ style["style:name"] =stylename.to_s
223
+ style["style:family"] ="table-cell"
224
+
225
+ table_cell_properties = Nokogiri::XML::Node.new('style:table-cell-properties', doc)
226
+ style << table_cell_properties
227
+
228
+ end
229
+
230
+ #
231
+ # individual properties
232
+ #
233
+ case stylename
234
+
235
+ when :bold
236
+ text_properties["fo:font-weight"] ="bold"
237
+ text_properties["fo:font-weight-asian"] ="bold"
238
+
239
+ when :underline
240
+ text_properties["style:text-underline-type"] ="single"
241
+ text_properties["style:text-underline-style"] ="solid"
242
+ text_properties["style:text-underline-width"] ="auto"
243
+ text_properties["style:text-underline-mode"] ="continuous"
244
+
245
+ when :italic
246
+ text_properties["fo:font-style"] ="italic"
247
+ text_properties["fo:font-style-asian"] ="italic"
248
+
249
+ when :strikethrough
250
+ text_properties["style:text-line-through-style"] ="solid"
251
+ text_properties["style:text-line-through-type"] ="single"
252
+
253
+ when /h(\d)/i
254
+ paragraph_properties["fo:text-align"] ="left"
255
+ paragraph_properties["fo:line-height"] ="100%"
256
+ paragraph_properties["fo:margin-left"] ="0cm"
257
+ paragraph_properties["fo:margin-right"] ="0cm"
258
+ paragraph_properties["fo:keep-with-next"] ="always"
259
+ paragraph_properties["fo:margin-top"] ="1.25cm"
260
+ paragraph_properties["fo:margin-right"] ="0cm"
261
+ paragraph_properties["fo:margin-bottom"] ="0.5cm"
262
+ paragraph_properties["fo:margin-left"] ="1.25cm"
263
+ paragraph_properties["fo:text-indent"] ="-1.25cm"
264
+ paragraph_properties["style:auto-text-indent"] ="false"
265
+
266
+ text_properties["fo:font-weight"] ="bold"
267
+ text_properties["fo:font-weight-asian"] ="bold"
268
+ text_properties["fo:hyphenate"] ="true"
269
+
270
+ when :center, :left, :right, :justify
271
+ paragraph_properties["fo:text-align"] =stylename.to_s
272
+
273
+ when :quote
274
+ paragraph_properties["fo:text-align"] ="justify"
275
+ paragraph_properties["fo:line-height"] ="150%"
276
+ paragraph_properties["fo:margin-top"] ="0.5cm"
277
+ paragraph_properties["fo:margin-right"] ="1cm"
278
+ paragraph_properties["fo:margin-bottom"] ="0.5cm"
279
+ paragraph_properties["fo:margin-left"] ="1cm"
280
+
281
+ text_properties["fo:hyphenate"] ="true"
282
+ text_properties["fo:font-style"] ="italic"
283
+ text_properties["fo:font-style-asian"] ="italic"
284
+
285
+ when :mono
286
+ paragraph_properties["fo:text-align"] ="left"
287
+ paragraph_properties["fo:line-height"] ="100%"
288
+ paragraph_properties["fo:margin-top"] ="0cm"
289
+ paragraph_properties["fo:margin-right"] ="0.5cm"
290
+ paragraph_properties["fo:margin-bottom"] ="0cm"
291
+ paragraph_properties["fo:margin-left"] ="0cm"
292
+
293
+ text_properties["fo:hyphenate"] ="false"
294
+ text_properties["fo:font-weight"] ="bold"
295
+ text_properties["fo:font-weight-asian"] ="bold"
296
+
297
+ when :monoright
298
+ paragraph_properties["fo:text-align"] ="right"
299
+ paragraph_properties["fo:line-height"] ="100%"
300
+ paragraph_properties["fo:margin-top"] ="0cm"
301
+ paragraph_properties["fo:margin-right"] ="0cm"
302
+ paragraph_properties["fo:margin-bottom"] ="0cm"
303
+ paragraph_properties["fo:margin-left"] ="0cm"
304
+
305
+ text_properties["fo:hyphenate"] ="false"
306
+ text_properties["fo:font-weight"] ="bold"
307
+ text_properties["fo:font-weight-asian"] ="bold"
308
+
309
+ when :monocenter
310
+ paragraph_properties["fo:text-align"] ="center"
311
+ paragraph_properties["fo:line-height"] ="100%"
312
+ paragraph_properties["fo:margin-top"] ="0cm"
313
+ paragraph_properties["fo:margin-right"] ="0cm"
314
+ paragraph_properties["fo:margin-bottom"] ="0cm"
315
+ paragraph_properties["fo:margin-left"] ="0cm"
316
+
317
+ text_properties["fo:hyphenate"] ="false"
318
+ text_properties["fo:font-weight"] ="bold"
319
+ text_properties["fo:font-weight-asian"] ="bold"
320
+
321
+ when :pre
322
+ paragraph_properties["fo:text-align"] ="left"
323
+ paragraph_properties["fo:line-height"] ="100%"
324
+ paragraph_properties["fo:margin-top"] ="0.5cm"
325
+ paragraph_properties["fo:margin-right"] ="1cm"
326
+ paragraph_properties["fo:margin-bottom"] ="0.5cm"
327
+ paragraph_properties["fo:margin-left"] ="1cm"
328
+ paragraph_properties["fo:background-color"] ="transparent"
329
+ paragraph_properties["fo:padding"] ="0.05cm"
330
+ paragraph_properties["fo:border"] ="0.06pt solid #000000"
331
+
332
+ text_properties["fo:hyphenate"] ="true"
333
+ text_properties["fo:font-style"] ="normal"
334
+ text_properties["fo:font-style-asian"] ="normal"
335
+ text_properties["style:font-name"] ="'Courier New'"
336
+ @font = {
337
+ :font_name => "'Courier New'",
338
+ :font_family => "'Courier New'",
339
+ :font_family_generic => "system",
340
+ :font_pitch => "fixed"
341
+ }
342
+
343
+ when :code
344
+ text_properties["style:font-name"] ="'Courier New'"
345
+ @font = {
346
+ :font_name => "'Courier New'",
347
+ :font_family => "'Courier New'",
348
+ :font_family_generic => "system",
349
+ :font_pitch => "fixed"
350
+ }
351
+
352
+ when :cling
353
+ paragraph_properties["fo:keep-together"] ="always"
354
+ paragraph_properties["fo:keep-with-next"] ="always"
355
+
356
+ when :sup
357
+ text_properties["style:text-position"] ="super 58%"
358
+
359
+ when :sub
360
+ text_properties["style:text-position"] ="sub 58%"
361
+
362
+ when :a
363
+ text_properties["fo:color"] ="#0000ff"
364
+ text_properties["style:text-underline-type"] ="single"
365
+ text_properties["style:text-underline-style"] ="solid"
366
+ text_properties["style:text-underline-width"] ="auto"
367
+ text_properties["style:text-underline-mode"] ="continuous"
368
+
369
+ when :large
370
+ text_properties["fo:font-size"] ="18pt"
371
+ text_properties["style:font-size-asian"] ="18pt"
372
+ text_properties["style:font-size-complex"] ="18pt"
373
+
374
+ when :medium
375
+ text_properties["fo:font-size"] ="9pt"
376
+ text_properties["style:font-size-asian"] ="9pt"
377
+ text_properties["style:font-size-complex"] ="9pt"
378
+
379
+ when :small
380
+ text_properties["fo:font-size"] ="8pt"
381
+ text_properties["style:font-size-asian"] ="8pt"
382
+ text_properties["style:font-size-complex"] ="8pt"
383
+
384
+ when :table, :list, :invoice, :boxes
385
+ table_properties["style:rel-width"] ="100%"
386
+ table_properties["fo:margin-top"] ="0cm"
387
+ table_properties["fo:margin-right"] ="0cm"
388
+ table_properties["fo:margin-bottom"] ="0cm"
389
+ table_properties["fo:margin-left"] ="0cm"
390
+ table_properties["fo:text-align"] ="left"
391
+
392
+ when :caption
393
+ table_properties["style:rel-width"] ="100%"
394
+ table_properties["fo:margin-top"] ="0cm"
395
+ table_properties["fo:margin-right"] ="0cm"
396
+ table_properties["fo:margin-bottom"] ="0cm"
397
+ table_properties["fo:margin-left"] ="0cm"
398
+ table_properties["fo:text-align"] ="left"
399
+
400
+ when :thrifty, :tiny, :listmedium
401
+ table_properties["style:rel-width"] ="50%"
402
+ table_properties["table:align"] ="left"
403
+ table_properties["fo:margin-top"] ="0cm"
404
+ table_properties["fo:margin-right"] ="0cm"
405
+ table_properties["fo:margin-bottom"] ="0cm"
406
+ table_properties["fo:margin-left"] ="0cm"
407
+ table_properties["fo:text-align"] ="left"
408
+
409
+ when :tr
410
+ # currently, nothing
411
+
412
+ when :tc
413
+ table_column_properties["style:column-width"] ="5cm"
414
+ table_column_properties["style:rel-column-width"] ="100*"
415
+ # MS Word errors, if this parameter is set
416
+ #table_column_properties["style:use-optimal-column-width "] ="true"
417
+
418
+ when :tcfixed
419
+ table_column_properties["style:column-width"] ="5cm"
420
+ table_column_properties["style:rel-column-width"] ="100*"
421
+ #table_column_properties["style:use-optimal-column-width "] ="false"
422
+ # for use with tcnarrow and tcwide
423
+
424
+ when :tcnarrow
425
+ table_column_properties["style:column-width"] ="2.5cm"
426
+ table_column_properties["style:rel-column-width"] ="50*"
427
+ #table_column_properties["style:use-optimal-column-width "] ="false"
428
+
429
+ when :tcwide
430
+ table_column_properties["style:column-width"] ="10.0cm"
431
+ table_column_properties["style:rel-column-width"] ="200*"
432
+ #table_column_properties["style:use-optimal-column-width "] ="false"
433
+
434
+ when :tcauto
435
+ table_column_properties["style:column-width"] ="5cm"
436
+ table_column_properties["style:rel-column-width"] ="100*"
437
+ #table_column_properties["style:use-optimal-column-width "] ="true"
438
+
439
+ when :td
440
+ table_cell_properties["style:writing-mode"] ="lr-tb"
441
+ table_cell_properties["fo:padding-top"] ="0cm"
442
+ table_cell_properties["fo:padding-right"] ="0.2cm"
443
+ table_cell_properties["fo:padding-bottom"] ="0.2cm"
444
+ table_cell_properties["fo:padding-left"] ="0cm"
445
+
446
+ when :tdbott
447
+ table_cell_properties["style:writing-mode"] ="lr-tb"
448
+ table_cell_properties["style:vertical-align"] ="bottom"
449
+ table_cell_properties["fo:padding-top"] ="0cm"
450
+ table_cell_properties["fo:padding-right"] ="0.2cm"
451
+ table_cell_properties["fo:padding-bottom"] ="0cm"
452
+ table_cell_properties["fo:padding-right"] ="0.2cm"
453
+
454
+ when :tdhead
455
+ table_cell_properties["style:writing-mode"] ="lr-tb"
456
+ table_cell_properties["fo:padding-top"] ="0cm"
457
+ table_cell_properties["fo:padding-right"] ="0.2cm"
458
+ table_cell_properties["fo:padding-bottom"] ="0.2cm"
459
+ table_cell_properties["fo:padding-right"] ="0.2cm"
460
+ table_cell_properties["fo:border-bottom"] ="0.5pt solid #000000"
461
+
462
+ when :tdfoot
463
+ table_cell_properties["style:writing-mode"] ="lr-tb"
464
+ table_cell_properties["fo:padding-top"] ="0.2cm"
465
+ table_cell_properties["fo:padding-right"] ="0.2cm"
466
+ table_cell_properties["fo:padding-bottom"] ="0cm"
467
+ table_cell_properties["fo:padding-right"] ="0.2cm"
468
+ table_cell_properties["fo:border-top"] ="0.5pt solid #000000"
469
+
470
+ when :tdbox
471
+ table_cell_properties["style:writing-mode"] ="lr-tb"
472
+ table_cell_properties["fo:padding-top"] ="0cm"
473
+ table_cell_properties["fo:padding-right"] ="0.2cm"
474
+ table_cell_properties["fo:padding-bottom"] ="0cm"
475
+ table_cell_properties["fo:padding-right"] ="0.2cm"
476
+ table_cell_properties["fo:border"] ="0.5pt solid #000000"
477
+ end
478
+
479
+ style
480
+ end #def
481
+
482
+ end #class
483
+ end #module
@@ -0,0 +1,135 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Ruby Gem to create a self populating Open Document Format (.odf) text file.
4
+ #
5
+ # Copyright 2021 Stephan Wenzel <stephan.wenzel@drwpatent.de>
6
+ #
7
+ # This program is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License
9
+ # as published by the Free Software Foundation; either version 2
10
+ # of the License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
+ #
21
+
22
+ module ODFWriter
23
+
24
+ ########################################################################################
25
+ #
26
+ # Table: poulate and grow tables
27
+ #
28
+ ########################################################################################
29
+ class Table
30
+
31
+ include Nested
32
+
33
+ attr_accessor :name, :collection, :proc
34
+
35
+ ######################################################################################
36
+ #
37
+ # initialize
38
+ #
39
+ ######################################################################################
40
+ def initialize(options)
41
+ @name = options[:name]
42
+ @field = options[:field]
43
+ @collection = options[:collection]
44
+ @proc = options[:proc]
45
+ @key = @field || @name
46
+
47
+ @fields = []
48
+ @texts = []
49
+ @tables = []
50
+ @images = []
51
+ @bookmarks = []
52
+
53
+ @template_rows = []
54
+ @header = options[:header] || false
55
+ @skip_if_empty = options[:skip_if_empty] || false
56
+
57
+ end #def
58
+
59
+ ######################################################################################
60
+ #
61
+ # replace!
62
+ #
63
+ ######################################################################################
64
+ def replace!(doc, manifest, file, row = nil)
65
+
66
+ return unless table = find_table_node(doc)
67
+
68
+ @template_rows = table.xpath("table:table-row")
69
+
70
+ @header = table.xpath("table:table-header-rows").empty? ? @header : false
71
+
72
+ @collection = items(row, @key, @proc) if row
73
+
74
+ if @skip_if_empty && @collection.empty?
75
+ table.remove
76
+ return
77
+ end
78
+
79
+ @collection.each do |item|
80
+
81
+ new_node = get_next_row
82
+ #
83
+ # experimental: new node must be added to doc prior to replace!
84
+ # else new_section does not have a name space
85
+ #
86
+ table.add_child(new_node)
87
+
88
+ @tables.each { |t| t.replace!(new_node, manifest, file, item) }
89
+ @texts.each { |t| t.replace!(new_node, item) }
90
+ @fields.each { |f| f.replace!(new_node, item) }
91
+ @images.each { |f| f.replace!(new_node, manifest, file, item) }
92
+
93
+ end
94
+ Image.unique_image_names( doc) if @images.present?
95
+
96
+ @template_rows.each_with_index do |r, i|
97
+ r.remove if (get_start_node..template_length) === i
98
+ end
99
+
100
+ end #def
101
+
102
+ ######################################################################################
103
+ #
104
+ # private
105
+ #
106
+ ######################################################################################
107
+ private
108
+
109
+ def get_next_row
110
+ @row_cursor = get_start_node unless defined?(@row_cursor)
111
+
112
+ ret = @template_rows[@row_cursor]
113
+ if @template_rows.size == @row_cursor + 1
114
+ @row_cursor = get_start_node
115
+ else
116
+ @row_cursor += 1
117
+ end
118
+ return ret.dup
119
+ end #def
120
+
121
+ def get_start_node
122
+ @header ? 1 : 0
123
+ end #def
124
+
125
+ def template_length
126
+ @tl ||= @template_rows.size
127
+ end #def
128
+
129
+ def find_table_node(doc)
130
+ tables = doc.xpath(".//table:table[@table:name='#{@name}']")
131
+ tables.empty? ? nil : tables.first
132
+ end #def
133
+
134
+ end #class
135
+ end #module
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Ruby Gem to create a self populating Open Document Format (.odf) text file.
4
+ #
5
+ # Copyright 2021 Stephan Wenzel <stephan.wenzel@drwpatent.de>
6
+ #
7
+ # This program is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License
9
+ # as published by the Free Software Foundation; either version 2
10
+ # of the License, or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
+ #
21
+
22
+ module ODFWriter
23
+
24
+ ########################################################################################
25
+ #
26
+ # TableReader: find all tables and set name
27
+ #
28
+ ########################################################################################
29
+ class TableReader
30
+
31
+ attr_accessor :name
32
+
33
+ ######################################################################################
34
+ #
35
+ # initialize
36
+ #
37
+ ######################################################################################
38
+ def initialize(opts)
39
+ @name = opts[:name]
40
+ end #def
41
+
42
+ ######################################################################################
43
+ #
44
+ # tables
45
+ #
46
+ ######################################################################################
47
+ def tables( doc )
48
+ nodes( doc ).keys
49
+ end #def
50
+
51
+ ######################################################################################
52
+ #
53
+ # nodes
54
+ #
55
+ ######################################################################################
56
+ def nodes( doc )
57
+ doc.xpath(".//table:table").map{|node| [node.attr("table:name"), node] }.to_h
58
+ end #def
59
+ end #class
60
+
61
+ end #module