odf-report 0.7.0 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: babb3d76f7401badd099efc108cc000baa9ce38a556447162dd0d31e1ad2b940
4
- data.tar.gz: 5ee08b656534f7522c60b3f784343120600761478baba47569c52d108d613237
3
+ metadata.gz: 1ff3d6495c26d851b5497d740ce9443d69957efa8b6f11e99c9287e68c339147
4
+ data.tar.gz: 3ffaee2475b15b556c8bdf7f1e15697442c9603e2c8dc09643887c0170effb2c
5
5
  SHA512:
6
- metadata.gz: 432a082f25cf119cc117d476abee396a1a6e24a144d5792f786aa249adf4b1bcf07a7fabad9d0789ca063484ea33c16fb74b05f6b088364efe3a0be3e5f03d5b
7
- data.tar.gz: 07c003adba47dac35a15ef697e750e3a918f42f4db4cb7964c9ec4ce28141a52f74b375fc328d6a4f87ce97df381fa0a7ba14c75598b39bb9c1d435cab4a70ef
6
+ metadata.gz: 6eff87a548135805364a1a214687e3b949975184b71bd0ea1796351110e4e142e02e6fda65a45bd039a4825e7bd58f435e2267a040a7ee69c1f8983a956331ce
7
+ data.tar.gz: 6638443f8259b7b2c8b1fcbee7efa83c935febacbf28141e2392dc2de4a1b67d31caea6726070fe85dfb7eeb1eefb23c39ee57527a8621694252b3a31130ced2
data/.github/stale.yml ADDED
@@ -0,0 +1,17 @@
1
+ # Number of days of inactivity before an issue becomes stale
2
+ daysUntilStale: 90
3
+ # Number of days of inactivity before a stale issue is closed
4
+ daysUntilClose: 21
5
+ # Issues with these labels will never be considered stale
6
+ exemptLabels:
7
+ - pinned
8
+ - security
9
+ # Label to use when marking an issue as stale
10
+ staleLabel: wontfix
11
+ # Comment to post when marking an issue as stale. Set to `false` to disable
12
+ markComment: >
13
+ This issue has been automatically marked as stale because it has not had
14
+ recent activity. It will be closed if no further activity occurs. Thank you
15
+ for your contributions.
16
+ # Comment to post when closing a stale issue. Set to `false` to disable
17
+ closeComment: false
@@ -0,0 +1,40 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby 2.6
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ version: 2.6.x
18
+
19
+ # - name: Publish to GPR
20
+ # run: |
21
+ # mkdir -p $HOME/.gem
22
+ # touch $HOME/.gem/credentials
23
+ # chmod 0600 $HOME/.gem/credentials
24
+ # printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
25
+ # gem build *.gemspec
26
+ # gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
27
+ # env:
28
+ # GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
29
+ # OWNER: username
30
+
31
+ - name: Publish to RubyGems
32
+ run: |
33
+ mkdir -p $HOME/.gem
34
+ touch $HOME/.gem/credentials
35
+ chmod 0600 $HOME/.gem/credentials
36
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
37
+ gem build *.gemspec
38
+ gem push *.gem
39
+ env:
40
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
data/CHANGELOG.md ADDED
@@ -0,0 +1,68 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
+
7
+ ## Unreleased
8
+
9
+ ### Breaking Changes
10
+
11
+ - None
12
+
13
+ ### Added
14
+
15
+ - None
16
+
17
+ ### Fixed
18
+
19
+ - None
20
+
21
+ ## 0.7.3
22
+
23
+ ### Fixed
24
+ - newer versions (> 1.3.0) of Nokogiri where presenting "Nokogiri::CSS::SyntaxError: unexpected '|'" #120
25
+ - prevent unnecessary memory expensive operations with missing placeholders #117
26
+
27
+ ## 0.7.2
28
+
29
+ ### Fixed
30
+
31
+ - files being recognized as "broken file" in Microsoft Word
32
+
33
+
34
+ ## 0.7.1
35
+
36
+ ### Added
37
+
38
+ - remove image if path is null
39
+ - remove section if collection is empty/null
40
+
41
+
42
+ ## 0.7.0
43
+
44
+ ### Added
45
+
46
+ - allow nested images inside tables and sections
47
+ - allow sections inside tables
48
+
49
+ ### Dependencies
50
+
51
+ - rubyzip >= 1.3.0 (was ~> 1.2.0)
52
+
53
+
54
+ ## 0.6.0
55
+
56
+ ### Breaking Changes
57
+
58
+ - `ODFReport::File` renamed to `ODFReport::Template`
59
+ - `ODFReport::Report` constructor signature changed
60
+
61
+ ### Dependencies
62
+
63
+ - rubyzip ~> 1.2.0 (was ~> 1.1.0)
64
+
65
+
66
+ ## Earlier Versions
67
+
68
+ - No docs yet. Contributions welcome!
data/README.md CHANGED
@@ -3,11 +3,6 @@
3
3
 
4
4
  Gem for generating .odt files by making strings, images, tables and sections replacements in a previously created .odt file.
5
5
 
6
- ### NEW
7
-
8
- * allow nested images inside tables and sections
9
- * allow sections inside tables
10
-
11
6
  ## INSTALL
12
7
 
13
8
  In your Gemfile
@@ -223,3 +218,19 @@ report = ODFReport::Report.new(io: @template.attachment.read) do |r|
223
218
  **rubyzip**: manipulating the contents of the odt file, since it's actually a zip file.
224
219
  **nokogiri**: parsing and manipulating the document xml files.
225
220
  **mime-types**: identify images mime types
221
+
222
+ #### TROUBLESHOOTING
223
+
224
+ ##### Placeholder not replaced
225
+
226
+ If your placeholder is not being replaced, the problem might come from OpenOffice/LibreOffice which, when a placeholder is edited, add some markup that prevents odf-report from identifying the placeholder.
227
+
228
+ The golden rule is: NEVER edit the placeholders. If you want to change one, delete it an write again, including the []
229
+ Example: if you have, say, [USER] in your template and you want to change to [USERNAME], you should not edit and type NAME.
230
+ Delete the PLACEHOLDER [USER] and type [USERNAME].
231
+
232
+ ##### Word found unreadable content
233
+
234
+ - Symptom: You prepare your template file in eg. LibreOffice, and when you open the template in Word it says "Word found unreadable content"
235
+ - Solution: Open your template in LibreOffice, save as `.docx`, quit LibreOffice. Open the `.docx` in LibreOffice, save as `.odt`.
236
+ - Hypothesis: Word does not support all ODT features. Saving as `.docx` removes those features of the document.
@@ -14,6 +14,7 @@ module ODFReport
14
14
  end
15
15
 
16
16
  def each(&block)
17
+ return unless @value
17
18
  @value.each(&block)
18
19
  end
19
20
 
@@ -17,9 +17,9 @@ module ODFReport
17
17
 
18
18
  txt = content.inner_html
19
19
 
20
- txt.gsub!(to_placeholder, sanitize(@data_source.value))
21
-
22
- content.inner_html = txt
20
+ if txt.gsub!(to_placeholder, sanitize(@data_source.value))
21
+ content.inner_html = txt
22
+ end
23
23
 
24
24
  end
25
25
 
@@ -19,10 +19,15 @@ module ODFReport
19
19
 
20
20
  file = @data_source.value
21
21
 
22
- image.attribute('href').content = File.join(IMAGE_DIR_NAME, File.basename(file))
23
- frame.attribute('name').content = SecureRandom.uuid
24
-
25
- @files << file
22
+ if file
23
+ image.attribute('href').content = File.join(IMAGE_DIR_NAME, File.basename(file))
24
+ frame.attribute('name').content = SecureRandom.uuid
25
+
26
+ @files << file
27
+ else
28
+ frame.remove
29
+ end
30
+
26
31
  end
27
32
 
28
33
  def self.include_image_file(zip_file, image_file)
@@ -45,7 +45,7 @@ class Report
45
45
  yield(sec)
46
46
  end
47
47
 
48
- def add_image(image_name, value='')
48
+ def add_image(image_name, value=nil)
49
49
  opts = {:name => image_name, :value => value}
50
50
  image = Image.new(opts)
51
51
  @images << image
@@ -26,11 +26,11 @@ module ODFReport
26
26
  private
27
27
 
28
28
  def find_section_node(doc)
29
- @section_node = doc.at_css("text|section[@text|name='#{@name}']")
29
+ @section_node = doc.at_xpath("//text:section[@text:name='#{@name}']")
30
30
  end
31
31
 
32
32
  def deep_clone(node)
33
- Nokogiri::XML(wrap_with_ns(node)).at("text|section")
33
+ Nokogiri::XML(wrap_with_ns(node)).at_xpath("//text:section")
34
34
  .tap { |n| n.attribute('name').content = SecureRandom.uuid }
35
35
 
36
36
  end
@@ -60,7 +60,6 @@ module ODFReport
60
60
  end
61
61
 
62
62
  return deep_clone(ret)
63
- # return ret.dup
64
63
  end
65
64
 
66
65
  def get_start_node
@@ -72,11 +71,11 @@ module ODFReport
72
71
  end
73
72
 
74
73
  def find_table_node(doc)
75
- doc.at_css("table|table[@table|name='#{@name}']")
74
+ doc.at_xpath("//table:table[@table:name='#{@name}']")
76
75
  end
77
76
 
78
77
  def deep_clone(node)
79
- Nokogiri::XML(wrap_with_ns(node)).at("table|table-row")
78
+ Nokogiri::XML(wrap_with_ns(node)).at_xpath("//table:table-row")
80
79
  end
81
80
 
82
81
  end
@@ -35,7 +35,7 @@ module ODFReport
35
35
  process_entry(data, &block)
36
36
  end
37
37
 
38
- update_file(entry.name, data)
38
+ update_file(entry.name, data) unless entry.name == MANIFEST_FILE
39
39
 
40
40
  end
41
41
  end
@@ -1,3 +1,3 @@
1
1
  module ODFReport
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.3"
3
3
  end
data/spec/images_spec.rb CHANGED
@@ -1,77 +1,156 @@
1
1
  RSpec.describe "Images" do
2
2
 
3
- before(:context) do
3
+ context('Adding Images') do
4
4
 
5
- @list = []
6
- @list << OpenStruct.new({ name: "IMG - [1, 1]", path: 'spec/images/image_1.jpg', path2: 'spec/images/image_1.jpg' })
7
- @list << OpenStruct.new({ name: "IMG - [2, 1]", path: 'spec/images/image_2.jpg', path2: 'spec/images/image_1.jpg' })
8
- @list << OpenStruct.new({ name: "IMG - [3, 2]", path: 'spec/images/image_3.jpg', path2: 'spec/images/image_2.jpg' })
9
- @list << OpenStruct.new({ name: "IMG - [1, 3]", path: 'spec/images/image_1.jpg', path2: 'spec/images/image_3.jpg' })
10
- @list << OpenStruct.new({ name: "IMG - [2, 2]", path: 'spec/images/image_2.jpg', path2: 'spec/images/image_2.jpg' })
5
+ before(:context) do
11
6
 
7
+ @list = []
8
+ @list << OpenStruct.new({ name: "IMG - [1, 1]", path: 'spec/images/image_1.jpg', path2: 'spec/images/image_1.jpg' })
9
+ @list << OpenStruct.new({ name: "IMG - [2, 1]", path: 'spec/images/image_2.jpg', path2: 'spec/images/image_1.jpg' })
10
+ @list << OpenStruct.new({ name: "IMG - [3, 2]", path: 'spec/images/image_3.jpg', path2: 'spec/images/image_2.jpg' })
11
+ @list << OpenStruct.new({ name: "IMG - [1, 3]", path: 'spec/images/image_1.jpg', path2: 'spec/images/image_3.jpg' })
12
+ @list << OpenStruct.new({ name: "IMG - [2, 2]", path: 'spec/images/image_2.jpg', path2: 'spec/images/image_2.jpg' })
12
13
 
13
- report = ODFReport::Report.new("spec/templates/images.odt") do |r|
14
14
 
15
- r.add_image("IMAGE_01", 'spec/images/rails.png')
16
- r.add_image("IMAGE_02", 'spec/images/piriapolis.jpg')
15
+ report = ODFReport::Report.new("spec/templates/images.odt") do |r|
16
+
17
+ r.add_image("IMAGE_01", 'spec/images/rails.png')
18
+ r.add_image("IMAGE_02", 'spec/images/piriapolis.jpg')
19
+
20
+ r.add_table('IMAGE_TABLE', @list) do |t|
21
+ t.add_column(:image_name, :name)
22
+ t.add_image('IMAGE_IN_TABLE_01', :path)
23
+ t.add_image('IMAGE_IN_TABLE_02', :path2)
24
+ end
25
+
26
+ r.add_section('SECTION', @list) do |t|
27
+ t.add_field(:image_name, :name)
28
+ t.add_image('IMAGE_IN_SECTION_01', :path2)
29
+ t.add_image('IMAGE_IN_SECTION_02', :path)
30
+ end
17
31
 
18
- r.add_table('IMAGE_TABLE', @list) do |t|
19
- t.add_column(:image_name, :name)
20
- t.add_image('IMAGE_IN_TABLE_01', :path)
21
- t.add_image('IMAGE_IN_TABLE_02', :path2)
22
32
  end
23
33
 
24
- r.add_section('SECTION', @list) do |t|
25
- t.add_field(:image_name, :name)
26
- t.add_image('IMAGE_IN_SECTION_01', :path2)
27
- t.add_image('IMAGE_IN_SECTION_02', :path)
34
+ report.generate("spec/result/images.odt")
35
+
36
+ @data = Inspector.new("spec/result/images.odt")
37
+
38
+ end
39
+
40
+
41
+ it "simple image replacement" do
42
+
43
+ images = @data.xml.xpath("//draw:image")
44
+
45
+ expect(images[0].attribute('href').value).to eq "Pictures/rails.png"
46
+ expect(images[1].attribute('href').value).to eq "Pictures/piriapolis.jpg"
47
+
48
+ end
49
+
50
+ it "table columns replacement" do
51
+
52
+ table = @data.xml.at_xpath(".//table:table[@table:name='IMAGE_TABLE']")
53
+
54
+ @list.each_with_index do |item, idx|
55
+
56
+ row = table.xpath(".//table:table-row[#{idx+1}]")
57
+
58
+ images = row.xpath(".//draw:image")
59
+
60
+ expect(File.basename(images[0].attribute('href').value)).to eq File.basename(item.path)
61
+ expect(File.basename(images[1].attribute('href').value)).to eq File.basename(item.path2)
62
+
28
63
  end
29
64
 
30
65
  end
31
66
 
32
- report.generate("spec/result/images.odt")
67
+ it "section fields replacement" do
68
+
69
+ @list.each_with_index do |item, idx|
70
+
71
+ section = @data.xml.at_xpath(".//text:section[#{idx+1}]")
72
+
73
+ images = section.xpath(".//draw:image")
33
74
 
34
- @data = Inspector.new("spec/result/images.odt")
75
+ expect(File.basename(images[0].attribute('href').value)).to eq File.basename(item.path)
76
+ expect(File.basename(images[1].attribute('href').value)).to eq File.basename(item.path2)
35
77
 
78
+ end
79
+
80
+ end
36
81
  end
37
82
 
83
+ context "Removing Images" do
38
84
 
39
- it "simple image replacement" do
85
+ before(:context) do
40
86
 
41
- images = @data.xml.xpath("//draw:image")
87
+ @list = []
88
+ @list << OpenStruct.new({ name: "IMG - both ok", path: 'spec/images/image_1.jpg', path2: 'spec/images/image_1.jpg' })
89
+ @list << OpenStruct.new({ name: "IMG - 1 ok", path: 'spec/images/image_2.jpg', path2: nil })
90
+ @list << OpenStruct.new({ name: "IMG - 2 ok", path: nil, path2: 'spec/images/image_3.jpg' })
91
+ # @list << OpenStruct.new({ name: "IMG - 2 invalid", path: nil, path2: 'spec/images/invalid.jpg' })
42
92
 
43
- expect(images[0].attribute('href').value).to eq "Pictures/rails.png"
44
- expect(images[1].attribute('href').value).to eq "Pictures/piriapolis.jpg"
93
+ report = ODFReport::Report.new("spec/templates/images.odt") do |r|
45
94
 
46
- end
95
+ # r.add_image("IMAGE_01")
96
+ r.add_image("IMAGE_02", nil)
47
97
 
48
- it "table columns replacement" do
98
+ r.add_table('IMAGE_TABLE', @list) do |t|
99
+ t.add_column(:image_name, :name)
100
+ t.add_image('IMAGE_IN_TABLE_01', :path)
101
+ t.add_image('IMAGE_IN_TABLE_02', :path2)
102
+ end
49
103
 
50
- table = @data.xml.at_xpath(".//table:table[@table:name='IMAGE_TABLE']")
104
+ r.add_section('SECTION', @list) do |t|
105
+ t.add_field(:image_name, :name)
106
+ t.add_image('IMAGE_IN_SECTION_01', :path2)
107
+ t.add_image('IMAGE_IN_SECTION_02', :path)
108
+ end
51
109
 
52
- @list.each_with_index do |item, idx|
110
+ end
53
111
 
54
- row = table.xpath(".//table:table-row[#{idx+1}]")
112
+ report.generate("spec/result/images.odt")
55
113
 
56
- images = row.xpath(".//draw:image")
114
+ @data = Inspector.new("spec/result/images.odt")
57
115
 
58
- expect(File.basename(images[0].attribute('href').value)).to eq File.basename(item.path)
59
- expect(File.basename(images[1].attribute('href').value)).to eq File.basename(item.path2)
116
+ end
60
117
 
118
+ it "removes nil images in report" do
119
+ expect(@data.xml.at_xpath(".//draw:frame[@draw:name='IMAGE_01']")).to be
120
+ expect(@data.xml.at_xpath(".//draw:frame[@draw:name='IMAGE_02']")).to be_nil
61
121
  end
62
122
 
63
- end
123
+ it "removes nil images in tables" do
124
+
125
+ table = @data.xml.at_xpath(".//table:table[@table:name='IMAGE_TABLE']")
64
126
 
65
- it "section fields replacement" do
127
+ images = table.xpath(".//table:table-row[1]//draw:image")
128
+ expect(File.basename(images[0].attribute('href').value)).to eq File.basename(@list[0].path)
129
+ expect(File.basename(images[1].attribute('href').value)).to eq File.basename(@list[0].path2)
130
+
131
+ images = table.xpath(".//table:table-row[2]//draw:image")
132
+ expect(File.basename(images[0].attribute('href').value)).to eq File.basename(@list[1].path)
133
+ expect(images[1]).to be_nil
134
+
135
+ images = table.xpath(".//table:table-row[3]//draw:image")
136
+ expect(File.basename(images[0].attribute('href').value)).to eq File.basename(@list[2].path2)
137
+ expect(images[1]).to be_nil
138
+
139
+ end
66
140
 
67
- @list.each_with_index do |item, idx|
141
+ it "removes nil images in sections " do
68
142
 
69
- section = @data.xml.at_xpath(".//text:section[#{idx+1}]")
143
+ images = @data.xml.xpath(".//text:section[1]//draw:image")
144
+ expect(File.basename(images[0].attribute('href').value)).to eq File.basename(@list[0].path)
145
+ expect(File.basename(images[1].attribute('href').value)).to eq File.basename(@list[0].path2)
70
146
 
71
- images = section.xpath(".//draw:image")
147
+ images = @data.xml.xpath(".//text:section[2]//draw:image")
148
+ expect(File.basename(images[0].attribute('href').value)).to eq File.basename(@list[1].path)
149
+ expect(images[1]).to be_nil
72
150
 
73
- expect(File.basename(images[0].attribute('href').value)).to eq File.basename(item.path)
74
- expect(File.basename(images[1].attribute('href').value)).to eq File.basename(item.path2)
151
+ images = @data.xml.xpath(".//text:section[3]//draw:image")
152
+ expect(File.basename(images[0].attribute('href').value)).to eq File.basename(@list[2].path2)
153
+ expect(images[1]).to be_nil
75
154
 
76
155
  end
77
156
 
@@ -0,0 +1,51 @@
1
+ RSpec.describe "Sections" do
2
+
3
+ before(:context) do
4
+ @itens = Item.get_list(3)
5
+
6
+ report = ODFReport::Report.new("spec/templates/specs.odt") do |r|
7
+
8
+ r.add_section('SECTION_01', @itens) do |t|
9
+ t.add_field(:s01_field_01, :id)
10
+ t.add_field(:s01_field_02, :name)
11
+ end
12
+
13
+ r.add_section('SECTION_02', []) do |t|
14
+ t.add_field(:s02_field_01, :id)
15
+ t.add_field(:s02_field_02, :name)
16
+ end
17
+
18
+ r.add_section('SECTION_03', nil) do |t|
19
+ t.add_field(:s03_field_01, :id)
20
+ t.add_field(:s03_field_02, :name)
21
+ end
22
+
23
+ end
24
+
25
+ report.generate("spec/result/specs.odt")
26
+
27
+ @data = Inspector.new("spec/result/specs.odt")
28
+
29
+ end
30
+
31
+ it "should render section with collection" do
32
+ @itens.each_with_index do |item, idx|
33
+ section = @data.xml.at_xpath(".//text:section[#{idx+1}]").to_s
34
+
35
+ expect(section).to match(item.id.to_s)
36
+ expect(section).to match(item.name)
37
+ end
38
+ end
39
+
40
+ it "should remove section with empty collection" do
41
+ section = @data.xml.at_xpath("//text:section[@text:name='SECTION_02']")
42
+ expect(section).to be_nil
43
+ end
44
+
45
+ it "should remove section with nil collection" do
46
+ section = @data.xml.at_xpath("//text:section[@text:name='SECTION_03']")
47
+ expect(section).to be_nil
48
+ end
49
+
50
+
51
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,11 +12,9 @@ class Item
12
12
  end
13
13
 
14
14
  def self.get_list(quant = 3)
15
- r = []
16
- (1..quant).each do |i|
17
- r << Item.new(Faker::Number.number(digits: 10), Faker::Name.name)
15
+ (1..quant).map do |i|
16
+ Item.new(Faker::Number.number(digits: 10), Faker::Name.name)
18
17
  end
19
- r
20
18
  end
21
19
 
22
20
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odf-report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Duarte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-06 00:00:00.000000000 Z
11
+ date: 2022-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,8 +130,11 @@ executables:
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
+ - ".github/stale.yml"
134
+ - ".github/workflows/gem-push.yml"
133
135
  - ".gitignore"
134
136
  - ".rspec"
137
+ - CHANGELOG.md
135
138
  - Gemfile
136
139
  - MIT-LICENSE
137
140
  - Manifest
@@ -144,7 +147,6 @@ files:
144
147
  - lib/odf-report/field.rb
145
148
  - lib/odf-report/image.rb
146
149
  - lib/odf-report/nestable.rb
147
- - lib/odf-report/nested.rb
148
150
  - lib/odf-report/parser/default.rb
149
151
  - lib/odf-report/report.rb
150
152
  - lib/odf-report/section.rb
@@ -161,6 +163,7 @@ files:
161
163
  - spec/images/placeholder.jpg
162
164
  - spec/images/rails.png
163
165
  - spec/images_spec.rb
166
+ - spec/sections_spec.rb
164
167
  - spec/spec_helper.rb
165
168
  - spec/tables_spec.rb
166
169
  - spec/template_spec.rb
@@ -208,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
211
  - !ruby/object:Gem::Version
209
212
  version: '0'
210
213
  requirements: []
211
- rubygems_version: 3.0.3
214
+ rubygems_version: 3.2.32
212
215
  signing_key:
213
216
  specification_version: 4
214
217
  summary: Generates ODF files, given a template (.odt) and data, replacing tags
@@ -221,6 +224,7 @@ test_files:
221
224
  - spec/images/placeholder.jpg
222
225
  - spec/images/rails.png
223
226
  - spec/images_spec.rb
227
+ - spec/sections_spec.rb
224
228
  - spec/spec_helper.rb
225
229
  - spec/tables_spec.rb
226
230
  - spec/template_spec.rb
@@ -1,67 +0,0 @@
1
- module ODFReport
2
-
3
- module Nested
4
-
5
- def add_field(name, data_field=nil, &block)
6
- opts = {name: name, data_field: data_field}
7
- @fields << Field.new(opts, &block)
8
-
9
- end
10
- alias_method :add_column, :add_field
11
-
12
- def add_text(name, data_field=nil, &block)
13
- opts = {name: name, data_field: data_field}
14
- @texts << Text.new(opts, &block)
15
- end
16
-
17
- def add_image(name, data_field=nil, &block)
18
- opts = {name: name, data_field: data_field}
19
- @images << Image.new(opts, &block)
20
- end
21
-
22
- def add_table(table_name, collection_field, opts={})
23
- opts.merge!(name: table_name, collection_field: collection_field)
24
- tab = Table.new(opts)
25
- @tables << tab
26
-
27
- yield(tab)
28
- end
29
-
30
- def add_section(section_name, collection_field, opts={})
31
- opts.merge!(name: section_name, collection_field: collection_field)
32
- sec = Section.new(opts)
33
- @sections << sec
34
-
35
- yield(sec)
36
- end
37
-
38
- def all_images
39
- (@images.map(&:files) + @sections.map(&:all_images) + @tables.map(&:all_images)).flatten
40
- end
41
-
42
- def get_collection_from_item(item, collection_field)
43
-
44
- return item[collection_field] if item.is_a?(Hash)
45
-
46
- if collection_field.is_a?(Array)
47
- tmp = item.dup
48
- collection_field.each do |f|
49
- if f.is_a?(Hash)
50
- tmp = tmp.send(f.keys[0], f.values[0])
51
- else
52
- tmp = tmp.send(f)
53
- end
54
- end
55
- collection = tmp
56
- elsif collection_field.is_a?(Hash)
57
- collection = item.send(collection_field.keys[0], collection_field.values[0])
58
- else
59
- collection = item.send(collection_field)
60
- end
61
-
62
- return collection
63
- end
64
-
65
- end
66
-
67
- end