odf-report 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +40 -0
- data/CHANGELOG.md +56 -0
- data/README.md +0 -5
- data/lib/odf-report/data_source.rb +1 -0
- data/lib/odf-report/image.rb +9 -4
- data/lib/odf-report/report.rb +1 -1
- data/lib/odf-report/version.rb +1 -1
- data/spec/images_spec.rb +118 -39
- data/spec/sections_spec.rb +51 -0
- data/spec/spec_helper.rb +2 -4
- data/spec/templates/specs.odt +0 -0
- metadata +6 -3
- data/lib/odf-report/nested.rb +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b953733bc99e0c7e77fc57a5b9e53f38756cc926794df2a8bcfa66156469e1e2
|
4
|
+
data.tar.gz: 69d20e56f5c14cf55c8ddad18019dc656a35a1b247f2d8b07ad0d64ea90cfad0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e14bbf17762213635726cf0a6c8270ce9d701e7315e180a1d46b142ae616ddb20e327aa57f67effc02700da73ce452e310c0c77eb861666039b92b83ffcd6a8
|
7
|
+
data.tar.gz: 18de0c6ca80d7740bbfee94d02cf99e2ea1a6153861b68bdd41a0303b9159dca09899b3123b18a965b608341e754f8ca018599e4ad985a18166832beb974314b
|
@@ -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,56 @@
|
|
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
|
+
|
22
|
+
## 0.7.1
|
23
|
+
|
24
|
+
### Added
|
25
|
+
|
26
|
+
- remove image if path is null
|
27
|
+
- remove section if collection is empty/null
|
28
|
+
|
29
|
+
|
30
|
+
## 0.7.0
|
31
|
+
|
32
|
+
### Added
|
33
|
+
|
34
|
+
- allow nested images inside tables and sections
|
35
|
+
- allow sections inside tables
|
36
|
+
|
37
|
+
### Dependencies
|
38
|
+
|
39
|
+
- rubyzip >= 1.3.0 (was ~> 1.2.0)
|
40
|
+
|
41
|
+
|
42
|
+
## 0.6.0
|
43
|
+
|
44
|
+
### Breaking Changes
|
45
|
+
|
46
|
+
- `ODFReport::File` renamed to `ODFReport::Template`
|
47
|
+
- `ODFReport::Report` constructor signature changed
|
48
|
+
|
49
|
+
### Dependencies
|
50
|
+
|
51
|
+
- rubyzip ~> 1.2.0 (was ~> 1.1.0)
|
52
|
+
|
53
|
+
|
54
|
+
## Earlier Versions
|
55
|
+
|
56
|
+
- 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
|
data/lib/odf-report/image.rb
CHANGED
@@ -19,10 +19,15 @@ module ODFReport
|
|
19
19
|
|
20
20
|
file = @data_source.value
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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)
|
data/lib/odf-report/report.rb
CHANGED
data/lib/odf-report/version.rb
CHANGED
data/spec/images_spec.rb
CHANGED
@@ -1,77 +1,156 @@
|
|
1
1
|
RSpec.describe "Images" do
|
2
2
|
|
3
|
-
|
3
|
+
context('Adding Images') do
|
4
4
|
|
5
|
-
|
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
|
-
|
16
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
85
|
+
before(:context) do
|
40
86
|
|
41
|
-
|
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
|
-
|
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
|
-
|
95
|
+
# r.add_image("IMAGE_01")
|
96
|
+
r.add_image("IMAGE_02", nil)
|
47
97
|
|
48
|
-
|
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
|
-
|
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
|
-
|
110
|
+
end
|
53
111
|
|
54
|
-
|
112
|
+
report.generate("spec/result/images.odt")
|
55
113
|
|
56
|
-
|
114
|
+
@data = Inspector.new("spec/result/images.odt")
|
57
115
|
|
58
|
-
|
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_css("draw|frame[@draw|name='IMAGE_01']")).to be
|
120
|
+
expect(@data.xml.at_css("draw|frame[@draw|name='IMAGE_02']")).to be_nil
|
61
121
|
end
|
62
122
|
|
63
|
-
|
123
|
+
it "removes nil images in tables" do
|
124
|
+
|
125
|
+
table = @data.xml.at_xpath(".//table:table[@table:name='IMAGE_TABLE']")
|
64
126
|
|
65
|
-
|
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
|
-
|
141
|
+
it "removes nil images in sections " do
|
68
142
|
|
69
|
-
|
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 =
|
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
|
-
|
74
|
-
expect(File.basename(images[
|
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_css("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_css("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
|
-
|
16
|
-
|
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
|
data/spec/templates/specs.odt
CHANGED
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.
|
4
|
+
version: 0.7.1
|
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-
|
11
|
+
date: 2020-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,8 +130,10 @@ executables:
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
+
- ".github/workflows/gem-push.yml"
|
133
134
|
- ".gitignore"
|
134
135
|
- ".rspec"
|
136
|
+
- CHANGELOG.md
|
135
137
|
- Gemfile
|
136
138
|
- MIT-LICENSE
|
137
139
|
- Manifest
|
@@ -144,7 +146,6 @@ files:
|
|
144
146
|
- lib/odf-report/field.rb
|
145
147
|
- lib/odf-report/image.rb
|
146
148
|
- lib/odf-report/nestable.rb
|
147
|
-
- lib/odf-report/nested.rb
|
148
149
|
- lib/odf-report/parser/default.rb
|
149
150
|
- lib/odf-report/report.rb
|
150
151
|
- lib/odf-report/section.rb
|
@@ -161,6 +162,7 @@ files:
|
|
161
162
|
- spec/images/placeholder.jpg
|
162
163
|
- spec/images/rails.png
|
163
164
|
- spec/images_spec.rb
|
165
|
+
- spec/sections_spec.rb
|
164
166
|
- spec/spec_helper.rb
|
165
167
|
- spec/tables_spec.rb
|
166
168
|
- spec/template_spec.rb
|
@@ -221,6 +223,7 @@ test_files:
|
|
221
223
|
- spec/images/placeholder.jpg
|
222
224
|
- spec/images/rails.png
|
223
225
|
- spec/images_spec.rb
|
226
|
+
- spec/sections_spec.rb
|
224
227
|
- spec/spec_helper.rb
|
225
228
|
- spec/tables_spec.rb
|
226
229
|
- spec/template_spec.rb
|
data/lib/odf-report/nested.rb
DELETED
@@ -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
|