lm_docstache 2.0.0 → 2.0.1

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: 805d05c9872a3562ac59527ada43842f4f28412d4a273d3010986f1182ee8421
4
- data.tar.gz: 1c0ecd9d43788420553310cefcba6bcca8fe24cd6dc14ff3cbac27f2cfb8ac8f
3
+ metadata.gz: e91a22653fad2e7b3afb24e170d5c8ccc8d7c5153b2a8b7cdc8caae19643e158
4
+ data.tar.gz: 9225014ab71170af0d2cfba5050d1202a531daf125a56b7c921b9beaeb3e2fa4
5
5
  SHA512:
6
- metadata.gz: 66881d21495aa30890ebfc392e4292bfd6ef0bccb9b31d147381b606478996707d82cb745d3dd387f98a793b743f54d695be7149282add2b4707438262bc1a0e
7
- data.tar.gz: 0a75364125a98fbd22150cbcde7e3826ab2a8d28705e321e0a471290838867d211ebda8a9181fcf7bf4a1428c6351fa1e93fc0ad33c200f850ae71bed3a0808d
6
+ metadata.gz: 2fa5b87cddcbb5e3d6c43dc8f0f4a27f2b3f0a192c9a8dd8973ea7107d69ed53959d95c8d17dc422360e225b3c3943519a46491988e03c64da494c01da4b801c
7
+ data.tar.gz: fb75e6b190061328b857a82a967514fe4ba28a8ff983ad314d3f6fcebd2c3135b3700cc28a8353fcbad0eddcb488806fcd78ea8c51bafe0d3ee28ad5447d10ab
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1
4
+
5
+ ### Improvements and bugfixes
6
+
7
+ * Improve the approach on fixing errors around paragraphs that have tags through
8
+ multiple `w:r` elements, by merging only `w:r` that have same styles.
9
+
3
10
  ## 2.0.0
4
11
 
5
12
  ### Breaking changes
@@ -1,7 +1,7 @@
1
1
  module LMDocstache
2
2
  class Document
3
3
  TAGS_REGEXP = /{{.+?}}/
4
- ROLES_REGEXP = /(\{\{(sig|sigfirm|date|check|text|initial)\|(req|noreq)\|(.+?)\}\})/
4
+ ROLES_REGEXP = /({{(sig|sigfirm|date|check|text|initial)\|(req|noreq)\|(.+?)}})/
5
5
 
6
6
  def initialize(*paths)
7
7
  raise ArgumentError if paths.empty?
@@ -65,7 +65,7 @@ module LMDocstache
65
65
  end
66
66
 
67
67
  def fix_errors
68
- problem_paragraphs.each { |p| flatten_paragraph(p) if p.present? }
68
+ problem_paragraphs.each { |pg| flatten_paragraph(pg) if pg }
69
69
  end
70
70
 
71
71
  def errors?
@@ -125,15 +125,21 @@ module LMDocstache
125
125
  end
126
126
 
127
127
  def flatten_paragraph(paragraph)
128
- run_nodes = paragraph.css('w|r')
129
- host_run_node = run_nodes.shift
128
+ return if (run_nodes = paragraph.css('w|r')).size < 2
130
129
 
131
- until host_run_node.at_css('w|t') || run_nodes.size == 0
132
- host_run_node = run_nodes.shift
133
- end
130
+ while run_node = run_nodes.pop
131
+ next if run_nodes.empty?
132
+
133
+ style_node = run_node.at_css('w|rPr')
134
+ style_html = style_node ? style_node.inner_html : ''
135
+ previous_run_node = run_nodes.last
136
+ previous_style_node = previous_run_node.at_css('w|rPr')
137
+ previous_style_html = previous_style_node ? previous_style_node.inner_html : ''
138
+
139
+ next if style_html != previous_style_html
134
140
 
135
- run_nodes.each do |run_node|
136
- host_run_node.at_css('w|t').content += run_node.text
141
+ previous_text_node = previous_run_node.at_css('w|t')
142
+ previous_text_node.content = previous_text_node.text + run_node.text
137
143
  run_node.unlink
138
144
  end
139
145
  end
@@ -1,3 +1,3 @@
1
1
  module LMDocstache
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -58,22 +58,26 @@ describe 'integration test', integration: true do
58
58
  end
59
59
 
60
60
  it 'fixes nested xml errors breaking tags' do
61
- expect(document.send(:problem_paragraphs)).to_not be_empty
62
- document.fix_errors
63
- expect(document.send(:problem_paragraphs)).to be_empty
61
+ expect { document.fix_errors }.to change {
62
+ document.send(:problem_paragraphs).size
63
+ }.from(6).to(1)
64
+
65
+ expect(document.send(:problem_paragraphs).first.text).to eq(
66
+ '{{TAG123-\\-//WITH WE👻IRD CHARS}}'
67
+ )
64
68
  end
65
69
 
66
70
  it 'has the expected amount of usable tags' do
67
- expect(document.usable_tags.count).to be(30)
71
+ expect(document.usable_tags.count).to eq(43)
68
72
  end
69
73
 
70
74
  it 'has the expected amount of usable roles tags' do
71
75
  document.fix_errors
72
- expect(document.usable_role_tags.count).to be(6)
76
+ expect(document.usable_role_tags.count).to eq(6)
73
77
  end
74
78
 
75
79
  it 'has the expected amount of unique tag names' do
76
- expect(document.usable_tag_names.count).to be(18)
80
+ expect(document.usable_tag_names.count).to eq(19)
77
81
  end
78
82
 
79
83
  it 'renders file using data' do
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: 2.0.0
4
+ version: 2.0.1
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-02-17 00:00:00.000000000 Z
15
+ date: 2021-03-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: nokogiri