lm_docstache 3.0.2 → 3.0.3

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: e8db9e1f7f1a534059ed080bfd89005372b334cc203b66cfbb45323b8116b980
4
- data.tar.gz: 4af011e633d34a62fcc0ed24fa639e04ce88937423b8570ae4f3a8fd4ff8fe70
3
+ metadata.gz: 233db6459ecd3c23c9d566659730ce1e4f2fcfb11b0ad4054dd83631375587ec
4
+ data.tar.gz: 344689f276e851c835b550f6197cc11dc2c698842b57efc29fc981fbb0026238
5
5
  SHA512:
6
- metadata.gz: e3c0630c4472b5d5b8f2a479a7b201411a817069221026778f86581146f4ef797dd586d2a0b299df4281394edf7878f1536ceda0d59f766a737255960a07d450
7
- data.tar.gz: df59e4c7c9750e75f976d47ee6d8d632c795702863cdb332627497f88026efa70a2eac2b01520c615a8faf042f677e547d3fec8ae09dc470d50383e1e5ed5548
6
+ metadata.gz: 342e46c6da0b34131af9cabd468fcae78e1dd272a8e08f4b395abfa2343f51b592d88ada3885c0c7db13d1ef89b66df30f49ff7237c1fba6f61356d5130e3e52
7
+ data.tar.gz: 03f3a44bf4a93b5d066cb141fabb9a2d6317940f9705213183ece98cdc2861bb41e7a0d12f399b80d4f6217f92be72bf96ca62a91ddbc790d9ccb57f4bf8d25c
data/CHANGELOG.md CHANGED
@@ -1,12 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.3
4
+
5
+ ### Bugfix
6
+
7
+ * Hide custom tags arguments was pushing blocks tags to end of paragraph. There are cases this approach
8
+ doesn't work. I changed to be an ordered replacement when we match hide tags.
9
+ * Avoid to merge Tab tags on fix errors methods. This was causing unexpected document changes.
10
+
3
11
  ## 3.0.2
4
12
 
5
13
  ### Bugfix
6
14
 
7
15
  * Fix replacing tags related to hidden custom tags regexp formats. E.g. tab characters.
8
16
 
9
-
10
17
  ## 3.0.1
11
18
 
12
19
  ### Bugfix
@@ -138,6 +138,10 @@ module LMDocstache
138
138
  previous_text_node = previous_run_node.at_css('w|t')
139
139
  current_text_node = run_node.at_css('w|t')
140
140
 
141
+ # avoid to merge blocks with tabs
142
+ next if run_node.at_css('w|tab')
143
+ next if previous_run_node.at_css('w|tab')
144
+
141
145
  next if style_html != previous_style_html
142
146
  next if current_text_node.nil? || previous_text_node.nil?
143
147
 
@@ -30,15 +30,15 @@ module LMDocstache
30
30
  while run_node = run_nodes.shift
31
31
  next unless run_node.at_css('w|t')
32
32
  next unless run_node.text =~ full_pattern
33
- remainder_run_node = run_node.clone
34
- run_node.unlink
35
- tag_contents = split_tag_content(remainder_run_node.text, full_pattern)
33
+ tag_contents = split_tag_content(run_node.text, full_pattern)
34
+ replacement_nodes = []
36
35
  tag_contents[:content_list].each_with_index do |content, idx|
36
+ remainder_run_node = run_node.clone
37
37
  replace_content(remainder_run_node, content)
38
38
  matched_tag = tag_contents[:matched_tags][idx]
39
- nodes_list = [remainder_run_node]
39
+ replacement_nodes << remainder_run_node
40
40
  if matched_tag
41
- run_node_with_match = remainder_run_node.dup
41
+ run_node_with_match = run_node.clone
42
42
  replace_style(run_node_with_match)
43
43
  matched_content = matched_tag
44
44
  if value
@@ -47,11 +47,11 @@ module LMDocstache
47
47
  value.to_s
48
48
  end
49
49
  replace_content(run_node_with_match, matched_content)
50
- nodes_list << run_node_with_match
50
+ replacement_nodes << run_node_with_match
51
51
  end
52
- paragraph << Nokogiri::XML::NodeSet.new(document, nodes_list)
53
- remainder_run_node = remainder_run_node.clone
54
52
  end
53
+ run_node.add_next_sibling(Nokogiri::XML::NodeSet.new(document, replacement_nodes))
54
+ run_node.unlink
55
55
  end
56
56
  end
57
57
  end
@@ -1,3 +1,3 @@
1
1
  module LMDocstache
2
- VERSION = "3.0.2"
2
+ VERSION = "3.0.3"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'securerandom'
2
3
  require 'active_support/core_ext/object/blank.rb'
3
4
 
4
5
  module LMDocstache
@@ -139,5 +140,30 @@ describe 'integration test', integration: true do
139
140
  expect(output).to include('<w:t xml:space="preserve">Test Multiple text in the same line </w:t>')
140
141
  end
141
142
  end
143
+
144
+ context "yoooo" do
145
+ let(:input_file) { "#{base_path}/multi_o.docx" }
146
+ let(:render_options) {
147
+ {
148
+ special_variable_replacements: { "(date|sig|sigfirm|text|check|initial|initials)\\|(req|noreq)\\|(.+?)" => false }.freeze,
149
+ hide_custom_tags: ['(?:sig|sigfirm|date|check|text|initial)\|(?:req|noreq)\|.+?']
150
+ }
151
+ }
152
+ let(:document) { LMDocstache::Document.new(input_file) }
153
+
154
+ it 'should have content replacement aligned with hide custom tags' do
155
+ doc = document
156
+ doc.fix_errors
157
+ new_file_path = "#{Time.now.to_i}-#{SecureRandom.uuid}.docx"
158
+ n = doc.render_file(new_file_path, { 'full_name' => 'fred document01' }, render_options)
159
+ noko = doc.render_xml({ 'full_name' => 'fred document01' }, render_options)
160
+ output = noko['word/document.xml'].to_xml
161
+ #puts output
162
+ #doc.render_file(new_file_path, { 'full_name' => 'fred document01' }, render_options)
163
+ #noko = doc.render_xml({ 'full_name' => 'fred document01' }, render_options)
164
+ #output = noko['word/document.xml'].to_xml
165
+ #puts output
166
+ end
167
+ end
142
168
  end
143
169
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lm_docstache
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roey Chasman
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-04-08 00:00:00.000000000 Z
15
+ date: 2021-04-27 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: nokogiri