lm_docstache 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/lm_docstache/hide_custom_tags.rb +9 -6
- data/lib/lm_docstache/parser.rb +1 -1
- data/lib/lm_docstache/version.rb +1 -1
- data/spec/example_input/sample-signature-blue.docx +0 -0
- data/spec/hide_custom_tags_spec.rb +28 -9
- data/spec/integration_spec.rb +37 -9
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6065b961f3d05db1773c70c088a67909755b633a3f412eec7f73cc76992a6a19
|
4
|
+
data.tar.gz: 808ce002e3bd777efc705851f610a1a26df183e81784e51cb28915a375f7f4cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41a377be982d11259c4a6a7f362d01e23a800e23203d3114a81b064ee158527a40f2a9a0ad6883923583c661c7e7d712945e894f68ba1e72afd0299b1bc10ed8
|
7
|
+
data.tar.gz: b8a49a51ab46335fac6c862f1a26b2a23f557d6e007a741cf7f3093891a8e1d696514b55597eee08c3734d2117fe98dd76030827f9a4c02a9af04cb7818dea76
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module LMDocstache
|
2
2
|
class HideCustomTags
|
3
|
-
HIDDEN_FONT_COLOR = 'FFFFFF'
|
4
|
-
|
5
3
|
attr_reader :document, :hide_custom_tags
|
6
4
|
|
7
5
|
# The +hide_custom_tags+ options is an +Array+ of +Regexp+ or +String+ representing
|
@@ -9,14 +7,14 @@ module LMDocstache
|
|
9
7
|
#
|
10
8
|
# You have to remember is not acceptable to have capture groups in your +Regexp's+.
|
11
9
|
# We don't accept because we need to find all parts of your text, split it in multiple runs
|
12
|
-
# and add
|
10
|
+
# and add document background color or white font color to matching custom tags.
|
13
11
|
def initialize(document:, hide_custom_tags: [])
|
14
12
|
@document = document
|
15
13
|
@hide_custom_tags = hide_custom_tags
|
16
14
|
end
|
17
15
|
|
18
16
|
# Find all run nodes matching hide custom tags +Regexp's+ options you defined, split it
|
19
|
-
# in multiple runs and replace font color to white in the matching tag run node.
|
17
|
+
# in multiple runs and replace font color to document background color or white in the matching tag run node.
|
20
18
|
def hide_custom_tags!
|
21
19
|
hide_custom_tags.each do |full_pattern|
|
22
20
|
paragraphs = document.css('w|p')
|
@@ -47,6 +45,11 @@ module LMDocstache
|
|
47
45
|
end
|
48
46
|
|
49
47
|
private
|
48
|
+
|
49
|
+
def font_color
|
50
|
+
@font_color ||= document.at_css('w|background')&.attr('w:color') || 'FFFFFF'
|
51
|
+
end
|
52
|
+
|
50
53
|
def split_tag_content(text, full_pattern)
|
51
54
|
content_list = text.split(full_pattern)
|
52
55
|
content_list = content_list.empty? ? [''] : content_list
|
@@ -59,9 +62,9 @@ module LMDocstache
|
|
59
62
|
if style
|
60
63
|
w_color = style.at_css('w|color')
|
61
64
|
w_color.unlink if w_color
|
62
|
-
style << "<w:color w:val=\"#{
|
65
|
+
style << "<w:color w:val=\"#{font_color}\"/>"
|
63
66
|
else
|
64
|
-
run_node << "<w:rPr><w:color w:val=\"#{
|
67
|
+
run_node << "<w:rPr><w:color w:val=\"#{font_color}\"/></w:rPr>"
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
data/lib/lm_docstache/parser.rb
CHANGED
@@ -39,7 +39,7 @@ module LMDocstache
|
|
39
39
|
#
|
40
40
|
# You have to remember is not acceptable to have capture groups in your +Regexp's+.
|
41
41
|
# We don't accept because we need to find all parts of your text, split it in multiple runs
|
42
|
-
# and add
|
42
|
+
# and add document background color or white font color to matching custom tags.
|
43
43
|
def initialize(document, data, options = {})
|
44
44
|
@document = document
|
45
45
|
@data = data.transform_keys(&:to_s)
|
data/lib/lm_docstache/version.rb
CHANGED
Binary file
|
@@ -5,6 +5,7 @@ describe LMDocstache::HideCustomTags do
|
|
5
5
|
context '#example' do
|
6
6
|
let(:output_dir) { "#{base_path}/tmp/" }
|
7
7
|
let(:output_file) { File.new("#{output_dir}/BlankTestOutput.docx", 'w') }
|
8
|
+
|
8
9
|
before do
|
9
10
|
FileUtils.rm_rf(output_dir) if File.exist?(output_dir)
|
10
11
|
Dir.mkdir(output_dir)
|
@@ -15,20 +16,38 @@ describe LMDocstache::HideCustomTags do
|
|
15
16
|
end
|
16
17
|
|
17
18
|
let(:base_path) { SPEC_BASE_PATH.join('example_input') }
|
18
|
-
let(:input_file) { "#{base_path}/sample-signature.docx" }
|
19
|
-
|
20
19
|
let(:document) { LMDocstache::Document.new(input_file).instance_variable_get(:@document) }
|
21
20
|
let(:regexp_tag) { /{{(?:sig|sigfirm|date|check|text|initial)\|(?:req|noreq)\|.+?}}/ }
|
22
21
|
let(:hide_custom_tags) {
|
23
22
|
LMDocstache::HideCustomTags.new(document: document, hide_custom_tags: [ regexp_tag ])
|
24
23
|
}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
|
25
|
+
context "giving a document with blue background" do
|
26
|
+
let(:input_file) { "#{base_path}/sample-signature-blue.docx" }
|
27
|
+
|
28
|
+
it 'expect to have a blue color on all hide custom tags matching' do
|
29
|
+
hide_custom_tags.hide_custom_tags!
|
30
|
+
d = hide_custom_tags.document
|
31
|
+
run_nodes = d.css('w|p w|r')
|
32
|
+
while run_node = run_nodes.shift
|
33
|
+
if run_node.text =~ regexp_tag
|
34
|
+
expect(run_node.at_css('w|rPr w|color').first[1]).to eq('4472C4')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'giving a document with white background' do
|
41
|
+
let(:input_file) { "#{base_path}/sample-signature.docx" }
|
42
|
+
|
43
|
+
it 'expect to have a white color on all hide custom tags matching' do
|
44
|
+
hide_custom_tags.hide_custom_tags!
|
45
|
+
d = hide_custom_tags.document
|
46
|
+
run_nodes = d.css('w|p w|r')
|
47
|
+
while run_node = run_nodes.shift
|
48
|
+
if run_node.text =~ regexp_tag
|
49
|
+
expect(run_node.at_css('w|rPr w|color').first[1]).to eq('FFFFFF')
|
50
|
+
end
|
32
51
|
end
|
33
52
|
end
|
34
53
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -35,15 +35,18 @@ end
|
|
35
35
|
describe 'integration test', integration: true do
|
36
36
|
let(:base_path) { SPEC_BASE_PATH.join('example_input') }
|
37
37
|
let(:output_dir) { "#{base_path}/tmp" }
|
38
|
+
|
38
39
|
context 'should process that incoming docx' do
|
39
40
|
let(:data) { LMDocstache::TestData::DATA }
|
40
41
|
let(:input_file) { "#{base_path}/ExampleTemplate.docx" }
|
41
42
|
let(:output_file) { "#{output_dir}/IntegrationTestOutput.docx" }
|
42
43
|
let(:document) { LMDocstache::Document.new(input_file) }
|
44
|
+
|
43
45
|
before do
|
44
46
|
FileUtils.rm_rf(output_dir) if File.exist?(output_dir)
|
45
47
|
Dir.mkdir(output_dir)
|
46
48
|
end
|
49
|
+
|
47
50
|
it 'loads the input file' do
|
48
51
|
expect(document).to_not be_nil
|
49
52
|
end
|
@@ -89,19 +92,43 @@ describe 'integration test', integration: true do
|
|
89
92
|
Dir.mkdir(output_dir)
|
90
93
|
end
|
91
94
|
|
92
|
-
let(:input_file) { "#{base_path}/sample-signature.docx" }
|
93
95
|
let(:render_options) {
|
94
96
|
{
|
95
|
-
hide_custom_tags: ['(?:sig|sigfirm|date|check|text|initial)\|(?:req|noreq)
|
97
|
+
hide_custom_tags: ['(?:sig|sigfirm|date|check|text|initial)\|(?:req|noreq)\|.+?']
|
96
98
|
}
|
97
99
|
}
|
98
100
|
let(:document) { LMDocstache::Document.new(input_file) }
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
101
|
+
|
102
|
+
context "witth document with blue background" do
|
103
|
+
let(:input_file) { "#{base_path}/sample-signature-blue.docx" }
|
104
|
+
|
105
|
+
it 'should have content replacement aligned with hide custom tags' do
|
106
|
+
doc = document
|
107
|
+
doc.fix_errors
|
108
|
+
noko = doc.render_xml({}, render_options)
|
109
|
+
output = noko['word/document.xml'].to_xml
|
110
|
+
expect(output).to include('<w:r>
|
111
|
+
<w:rPr>
|
112
|
+
<w:rFonts w:cstheme="minorHAnsi"/>
|
113
|
+
<w:lang w:val="en-US"/>
|
114
|
+
<w:color w:val="4472C4"/>
|
115
|
+
</w:rPr>
|
116
|
+
<w:t xml:space="preserve">{{sig|req|client}}</w:t>
|
117
|
+
</w:r>')
|
118
|
+
expect(output).to include('<w:t xml:space="preserve">Test Multiple text in the same line </w:t>')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "with document without backgorund" do
|
123
|
+
let(:input_file) { "#{base_path}/sample-signature.docx" }
|
124
|
+
let(:document) { LMDocstache::Document.new(input_file) }
|
125
|
+
|
126
|
+
it 'should have content replacement aligned with hide custom tags' do
|
127
|
+
doc = document
|
128
|
+
doc.fix_errors
|
129
|
+
noko = doc.render_xml({}, render_options)
|
130
|
+
output = noko['word/document.xml'].to_xml
|
131
|
+
expect(output).to include('<w:r>
|
105
132
|
<w:rPr>
|
106
133
|
<w:rFonts w:cstheme="minorHAnsi"/>
|
107
134
|
<w:lang w:val="en-US"/>
|
@@ -109,7 +136,8 @@ describe 'integration test', integration: true do
|
|
109
136
|
</w:rPr>
|
110
137
|
<w:t xml:space="preserve">{{sig|req|client}}</w:t>
|
111
138
|
</w:r>')
|
112
|
-
|
139
|
+
expect(output).to include('<w:t xml:space="preserve">Test Multiple text in the same line </w:t>')
|
140
|
+
end
|
113
141
|
end
|
114
142
|
end
|
115
143
|
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: 2.1.
|
4
|
+
version: 2.1.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-03-
|
15
|
+
date: 2021-03-18 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: nokogiri
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- spec/conditional_block_spec.rb
|
122
122
|
- spec/example_input/ExampleTemplate.docx
|
123
123
|
- spec/example_input/blank.docx
|
124
|
+
- spec/example_input/sample-signature-blue.docx
|
124
125
|
- spec/example_input/sample-signature.docx
|
125
126
|
- spec/hide_custom_tags_spec.rb
|
126
127
|
- spec/integration_spec.rb
|
@@ -153,6 +154,7 @@ test_files:
|
|
153
154
|
- spec/conditional_block_spec.rb
|
154
155
|
- spec/example_input/ExampleTemplate.docx
|
155
156
|
- spec/example_input/blank.docx
|
157
|
+
- spec/example_input/sample-signature-blue.docx
|
156
158
|
- spec/example_input/sample-signature.docx
|
157
159
|
- spec/hide_custom_tags_spec.rb
|
158
160
|
- spec/integration_spec.rb
|