odf-report 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8d30a8580192ffaf7fa4908a5b674e69ecef19a5c3fe054baeaf1e72c3770ad
4
- data.tar.gz: e402b3a61216a3070cdfcc0799930038ed9cd37687c7a844eaf76ead2b55a704
3
+ metadata.gz: 14183fe9ba54b5f98cd72cd48aa1277aa9d5b576c7980ae2bbfeef2346c9c49d
4
+ data.tar.gz: dcf77b2934897f3b490effdd62a1ee1effc2d13898523249b81b4be62be1eea9
5
5
  SHA512:
6
- metadata.gz: 72e8c9581c0f655dd1ba4ef5dcfd11706f36a2e69d810261fb7f233d72f0cb982a298da7f24055d7561551f3ac737abf018809ea982d495661e0386895ee75bf
7
- data.tar.gz: 9113f76a643655aa46227a0390c425cca828ba2c05835eb33d3894c7cb2219253bda16c109bf885148e63736671be3389abe804782a196ca860fb958b786ecf5
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@v2
14
- - name: Set up Ruby 2.6
15
- uses: actions/setup-ruby@v1
16
+ - uses: actions/checkout@v4
17
+ - uses: ruby/setup-ruby@v1
16
18
  with:
17
- version: 2.6.x
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", @list_of_itens, :header=>true) do |t|
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 `@list_of_itens`, it will create one row for each item in the collection, and the replacement will take place accordingly.
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.
@@ -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
 
@@ -34,11 +34,9 @@ module Parser
34
34
  end
35
35
 
36
36
  def parse
37
+ html = Nokogiri::HTML5.fragment(@text)
37
38
 
38
- xml = @template_node.parse(@text)
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ODFReport
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
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.10.0")
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.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
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
@@ -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.at_css("text|section[@text|name='SECTION_02']")
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.at_css("text|section[@text|name='SECTION_03']")
46
+ section = @data.xml.at_xpath("//text:section[@text:name='SECTION_03']")
47
47
  expect(section).to be_nil
48
48
  end
49
49
 
Binary file
@@ -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&iacute;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.7.2
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: 2020-06-02 00:00:00.000000000 Z
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.10.0
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.10.0
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.0.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