odf-report 0.7.2 → 0.8.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/.github/stale.yml +17 -0
- data/.github/workflows/gem-push.yml +7 -4
- data/CHANGELOG.md +12 -0
- data/README.md +18 -2
- data/lib/odf-report/field.rb +3 -3
- data/lib/odf-report/parser/default.rb +3 -4
- data/lib/odf-report/section.rb +2 -2
- data/lib/odf-report/table.rb +2 -3
- data/lib/odf-report/version.rb +1 -1
- data/odf-report.gemspec +1 -1
- data/spec/images_spec.rb +2 -2
- data/spec/sections_spec.rb +2 -2
- data/spec/templates/specs.odt +0 -0
- data/spec/texts_spec.rb +48 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14183fe9ba54b5f98cd72cd48aa1277aa9d5b576c7980ae2bbfeef2346c9c49d
|
4
|
+
data.tar.gz: dcf77b2934897f3b490effdd62a1ee1effc2d13898523249b81b4be62be1eea9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7eb665c1fe1f414dac1b5e3ef3714b398d207125b00589573f2e2e9a2d4632355f26bf968fe3eec53c7bdcdff92c3fe24f5216fe18a1e160ddd4c8947804390a
|
7
|
+
data.tar.gz: 237f77a79aa11754aff00d0973c696dc9f62a8ce65b6b57c1c101293b632ee0399025f13b04f9649feaeda1d63310b58ac83ac67d5565cc602c9b2bcd5be127c
|
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
|
@@ -8,13 +8,16 @@ jobs:
|
|
8
8
|
build:
|
9
9
|
name: Build + Publish
|
10
10
|
runs-on: ubuntu-latest
|
11
|
+
permissions:
|
12
|
+
contents: read
|
13
|
+
packages: write
|
11
14
|
|
12
15
|
steps:
|
13
|
-
- uses: actions/checkout@
|
14
|
-
-
|
15
|
-
uses: actions/setup-ruby@v1
|
16
|
+
- uses: actions/checkout@v4
|
17
|
+
- uses: ruby/setup-ruby@v1
|
16
18
|
with:
|
17
|
-
version: 2
|
19
|
+
ruby-version: '3.2'
|
20
|
+
bundler-cache: true
|
18
21
|
|
19
22
|
# - name: Publish to GPR
|
20
23
|
# run: |
|
data/CHANGELOG.md
CHANGED
@@ -18,6 +18,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
18
18
|
|
19
19
|
- None
|
20
20
|
|
21
|
+
## 0.8.0
|
22
|
+
|
23
|
+
### Dependencies
|
24
|
+
|
25
|
+
- nokogiri >= 1.12.0 (was >= 1.10.0)
|
26
|
+
|
27
|
+
## 0.7.3
|
28
|
+
|
29
|
+
### Fixed
|
30
|
+
- newer versions (> 1.13.0) of Nokogiri where presenting "Nokogiri::CSS::SyntaxError: unexpected '|'" #120
|
31
|
+
- prevent unnecessary memory expensive operations with missing placeholders #117
|
32
|
+
|
21
33
|
## 0.7.2
|
22
34
|
|
23
35
|
### Fixed
|
data/README.md
CHANGED
@@ -56,7 +56,7 @@ report = ODFReport::Report.new("Users/john/my_template.odt") do |r|
|
|
56
56
|
r.add_field "USER_NAME", @user.nome
|
57
57
|
r.add_field "ADDRESS", @user.address
|
58
58
|
|
59
|
-
r.add_table("TABLE_1", @
|
59
|
+
r.add_table("TABLE_1", @list_of_items, :header=>true) do |t|
|
60
60
|
t.add_column(:item_id, :id)
|
61
61
|
t.add_column(:description) { |item| "==> #{item.description}" }
|
62
62
|
end
|
@@ -71,7 +71,7 @@ and considering you have a table like this in your template
|
|
71
71
|
| [ITEM_ID] | [DESCRIPTION] |
|
72
72
|
|
73
73
|
|
74
|
-
and a collection `@
|
74
|
+
and a collection `@list_of_items`, it will create one row for each item in the collection, and the replacement will take place accordingly.
|
75
75
|
|
76
76
|
Any format applied to the fields in the template will be preserved.
|
77
77
|
|
@@ -218,3 +218,19 @@ report = ODFReport::Report.new(io: @template.attachment.read) do |r|
|
|
218
218
|
**rubyzip**: manipulating the contents of the odt file, since it's actually a zip file.
|
219
219
|
**nokogiri**: parsing and manipulating the document xml files.
|
220
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.
|
data/lib/odf-report/field.rb
CHANGED
@@ -34,11 +34,9 @@ module Parser
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def parse
|
37
|
+
html = Nokogiri::HTML5.fragment(@text)
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
xml.css("p", "h1", "h2").each do |p|
|
41
|
-
|
39
|
+
html.css("p", "h1", "h2").each do |p|
|
42
40
|
style = check_style(p)
|
43
41
|
text = parse_formatting(p.inner_html)
|
44
42
|
|
@@ -63,6 +61,7 @@ module Parser
|
|
63
61
|
text.gsub!(/<strong.*?>(.+?)<\/strong>/) { "<text:span text:style-name=\"bold\">#{$1}<\/text:span>" }
|
64
62
|
text.gsub!(/<em.*?>(.+?)<\/em>/) { "<text:span text:style-name=\"italic\">#{$1}<\/text:span>" }
|
65
63
|
text.gsub!(/<u.*?>(.+?)<\/u>/) { "<text:span text:style-name=\"underline\">#{$1}<\/text:span>" }
|
64
|
+
text.gsub!("<br\/?>", "<text:line-break/>")
|
66
65
|
text.gsub!("\n", "")
|
67
66
|
text
|
68
67
|
end
|
data/lib/odf-report/section.rb
CHANGED
@@ -26,11 +26,11 @@ module ODFReport
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def find_section_node(doc)
|
29
|
-
@section_node = doc.
|
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)).
|
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
|
data/lib/odf-report/table.rb
CHANGED
@@ -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.
|
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)).
|
78
|
+
Nokogiri::XML(wrap_with_ns(node)).at_xpath("//table:table-row")
|
80
79
|
end
|
81
80
|
|
82
81
|
end
|
data/lib/odf-report/version.rb
CHANGED
data/odf-report.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.add_development_dependency "launchy"
|
26
26
|
|
27
27
|
s.add_runtime_dependency('rubyzip', ">= 1.3.0")
|
28
|
-
s.add_runtime_dependency('nokogiri', ">= 1.
|
28
|
+
s.add_runtime_dependency('nokogiri', ">= 1.12.0")
|
29
29
|
s.add_runtime_dependency('mime-types')
|
30
30
|
|
31
31
|
end
|
data/spec/images_spec.rb
CHANGED
@@ -116,8 +116,8 @@ RSpec.describe "Images" do
|
|
116
116
|
end
|
117
117
|
|
118
118
|
it "removes nil images in report" do
|
119
|
-
expect(@data.xml.
|
120
|
-
expect(@data.xml.
|
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
|
121
121
|
end
|
122
122
|
|
123
123
|
it "removes nil images in tables" do
|
data/spec/sections_spec.rb
CHANGED
@@ -38,12 +38,12 @@ RSpec.describe "Sections" do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should remove section with empty collection" do
|
41
|
-
section = @data.xml.
|
41
|
+
section = @data.xml.at_xpath("//text:section[@text:name='SECTION_02']")
|
42
42
|
expect(section).to be_nil
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should remove section with nil collection" do
|
46
|
-
section = @data.xml.
|
46
|
+
section = @data.xml.at_xpath("//text:section[@text:name='SECTION_03']")
|
47
47
|
expect(section).to be_nil
|
48
48
|
end
|
49
49
|
|
data/spec/templates/specs.odt
CHANGED
Binary file
|
data/spec/texts_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
RSpec.describe "Texts" do
|
2
|
+
before(:context) do
|
3
|
+
|
4
|
+
@text1 = <<-HTML
|
5
|
+
<p>This is some text in a paragraph</p>
|
6
|
+
HTML
|
7
|
+
|
8
|
+
@text2 = <<-HTML
|
9
|
+
<p>Text before line break <br> text after line break</p>
|
10
|
+
HTML
|
11
|
+
|
12
|
+
@text3 = <<-HTML
|
13
|
+
<p>Text before entities
|
14
|
+
Maurício
|
15
|
+
Text after entities</p>
|
16
|
+
HTML
|
17
|
+
|
18
|
+
|
19
|
+
report = ODFReport::Report.new("spec/templates/specs.odt") do |r|
|
20
|
+
|
21
|
+
r.add_text(:text1, @text1)
|
22
|
+
r.add_text(:text2, @text2)
|
23
|
+
r.add_text(:text3, @text3)
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
report.generate("spec/result/specs.odt")
|
28
|
+
|
29
|
+
@data = Inspector.new("spec/result/specs.odt")
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
it "simple text replacement" do
|
34
|
+
expect(@data.text).to include "This is some text in a paragraph"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "text replacement with <br>" do
|
38
|
+
expect(@data.text).to include "Text before line break"
|
39
|
+
expect(@data.text).to include "text after line break"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "text replacement with html entities" do
|
43
|
+
expect(@data.text).to include "Text before entities"
|
44
|
+
expect(@data.text).to include "Maurício"
|
45
|
+
expect(@data.text).to include "Text after entities"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
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.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Duarte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.
|
103
|
+
version: 1.12.0
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.
|
110
|
+
version: 1.12.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: mime-types
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +130,7 @@ executables:
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
+
- ".github/stale.yml"
|
133
134
|
- ".github/workflows/gem-push.yml"
|
134
135
|
- ".gitignore"
|
135
136
|
- ".rspec"
|
@@ -168,6 +169,7 @@ files:
|
|
168
169
|
- spec/template_spec.rb
|
169
170
|
- spec/templates/images.odt
|
170
171
|
- spec/templates/specs.odt
|
172
|
+
- spec/texts_spec.rb
|
171
173
|
- test/fields_inside_text_test.rb
|
172
174
|
- test/images_test.rb
|
173
175
|
- test/nested_tables_test.rb
|
@@ -210,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
212
|
- !ruby/object:Gem::Version
|
211
213
|
version: '0'
|
212
214
|
requirements: []
|
213
|
-
rubygems_version: 3.
|
215
|
+
rubygems_version: 3.4.19
|
214
216
|
signing_key:
|
215
217
|
specification_version: 4
|
216
218
|
summary: Generates ODF files, given a template (.odt) and data, replacing tags
|
@@ -229,6 +231,7 @@ test_files:
|
|
229
231
|
- spec/template_spec.rb
|
230
232
|
- spec/templates/images.odt
|
231
233
|
- spec/templates/specs.odt
|
234
|
+
- spec/texts_spec.rb
|
232
235
|
- test/fields_inside_text_test.rb
|
233
236
|
- test/images_test.rb
|
234
237
|
- test/nested_tables_test.rb
|