lm_docstache 1.2.2 → 1.3.1
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/.gitignore +1 -0
- data/CHANGELOG.md +11 -0
- data/lib/lm_docstache/document.rb +37 -2
- data/lib/lm_docstache/renderer.rb +18 -2
- data/lib/lm_docstache/version.rb +1 -1
- data/lm_docstache.gemspec +5 -5
- data/spec/example_input/ExampleTemplate2.docx +0 -0
- data/spec/integration_spec.rb +11 -3
- metadata +21 -12
- data/Gemfile.lock +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ab76fe58e63d2b57612f1b63cde29861a5552f08549dfdef6487127d63ee30c
|
4
|
+
data.tar.gz: 397def49df4c8a2fcb5688c5b52ca2d1b2940b9efebf37747ff745b33b4561d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55ab02fac2c3e0033522d89d739be8fb16c2431952dea35485c9f1d6aca2264c6d8bb06ab2fb0e9a491f03077e54c870802c77ff51888a03a53208dc86d2bcbc
|
7
|
+
data.tar.gz: 0b9ac7bfac5f4a106d12da49a75291f1a5740a154e64641db1d93caa9187089c028de6e12648b074079867750b65fbced6de6cff48b7bad64d2acbea1cfaccb9
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
# Changelog
|
2
|
+
## 1.3.1
|
3
|
+
* Fix bug searching accross xml nodes for e-signature tags.
|
4
|
+
|
5
|
+
## 1.3.0
|
6
|
+
* Add support for e-signature tags
|
7
|
+
|
8
|
+
## 1.2.4
|
9
|
+
* Add support for pipe character in merge tags so we can use as a modifier for the context of merge tag.
|
10
|
+
|
11
|
+
## 1.2.3
|
12
|
+
* Fix issue where some paragraphs do not contain text as their first block. If this is the case, we just use the first block that does contain text.
|
2
13
|
|
3
14
|
## 1.2.2
|
4
15
|
* Remove uneccessary runtime dependency on active support.
|
@@ -15,6 +15,36 @@ module LMDocstache
|
|
15
15
|
find_documents_to_interpolate
|
16
16
|
end
|
17
17
|
|
18
|
+
def signature_tags
|
19
|
+
@documents.values.flat_map do |document|
|
20
|
+
document.text.strip.scan(/\[\[sig_.+?\]\]/)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def usable_signature_tags
|
25
|
+
@documents.values.flat_map do |document|
|
26
|
+
document.css('w|p')
|
27
|
+
.select { |tag| tag.text =~ /\[\[sig_.+?\]\]/ }
|
28
|
+
.flat_map { |tag| tag.text.scan(/\[\[sig_.+?\]\]/) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def usable_signature_tag_names
|
33
|
+
self.usable_signature_tags.map do |tag|
|
34
|
+
tag.scan(/\[\[sig_(.+?)\]\]/)
|
35
|
+
$1
|
36
|
+
end.compact.uniq
|
37
|
+
end
|
38
|
+
|
39
|
+
def unusable_signature_tags
|
40
|
+
unusable_signature_tags = signature_tags
|
41
|
+
unusable_signature_tags.each do |usable_tag|
|
42
|
+
index = unusable_signature_tags.index(usable_tag)
|
43
|
+
unusable_signature_tags.delete_at(index) if index
|
44
|
+
end
|
45
|
+
return unusable_signature_tags
|
46
|
+
end
|
47
|
+
|
18
48
|
def tags
|
19
49
|
@documents.values.flat_map do |document|
|
20
50
|
document.text.strip.scan(/\{\{.+?\}\}/)
|
@@ -58,10 +88,10 @@ module LMDocstache
|
|
58
88
|
File.open(path, "w") { |f| f.write buffer.string }
|
59
89
|
end
|
60
90
|
|
61
|
-
def render_file(output, data={})
|
91
|
+
def render_file(output, data={}, remove_signature_tags = false)
|
62
92
|
rendered_documents = Hash[
|
63
93
|
@documents.map do |(path, document)|
|
64
|
-
[path, LMDocstache::Renderer.new(document.dup, data).render]
|
94
|
+
[path, LMDocstache::Renderer.new(document.dup, data, remove_signature_tags).render]
|
65
95
|
end
|
66
96
|
]
|
67
97
|
buffer = zip_buffer(rendered_documents)
|
@@ -111,7 +141,12 @@ module LMDocstache
|
|
111
141
|
|
112
142
|
def flatten_paragraph(p)
|
113
143
|
runs = p.css('w|r')
|
144
|
+
|
114
145
|
host_run = runs.shift
|
146
|
+
until host_run.at_css('w|t').present? || runs.size == 0 do
|
147
|
+
host_run = runs.shift
|
148
|
+
end
|
149
|
+
|
115
150
|
runs.each do |run|
|
116
151
|
host_run.at_css('w|t').content += run.text
|
117
152
|
run.unlink
|
@@ -2,14 +2,16 @@ module LMDocstache
|
|
2
2
|
class Renderer
|
3
3
|
BLOCK_REGEX = /\{\{([\#\^])([\w\.]+)(?:(\s(?:==|~=)\s?.+?))?\}\}.+?\{\{\/\k<2>\}\}/m
|
4
4
|
|
5
|
-
def initialize(xml, data)
|
5
|
+
def initialize(xml, data, remove_signature_tags = false)
|
6
6
|
@content = xml
|
7
7
|
@data = DataScope.new(data)
|
8
|
+
@remove_signature_tags = remove_signature_tags
|
8
9
|
end
|
9
10
|
|
10
11
|
def render
|
11
12
|
find_and_expand_blocks
|
12
13
|
replace_tags(@content, @data)
|
14
|
+
remove_signature_tags(@content) if @remove_signature_tags
|
13
15
|
return @content
|
14
16
|
end
|
15
17
|
|
@@ -106,7 +108,7 @@ module LMDocstache
|
|
106
108
|
|
107
109
|
def replace_tags(elements, data)
|
108
110
|
elements.css('w|t').each do |text_el|
|
109
|
-
if !(results = text_el.text.scan(/\{\{([\w
|
111
|
+
if !(results = text_el.text.scan(/\{\{([\w\.\|]+)\}\}/).flatten).empty?
|
110
112
|
rendered_string = text_el.text
|
111
113
|
results.each do |r|
|
112
114
|
rendered_string.gsub!("{{#{r}}}", data.get(r).to_s)
|
@@ -117,6 +119,20 @@ module LMDocstache
|
|
117
119
|
return elements
|
118
120
|
end
|
119
121
|
|
122
|
+
def remove_signature_tags(elements)
|
123
|
+
elements.css('w|t').each do |text_el|
|
124
|
+
if !(results = text_el.text.scan(/\[\[sig_(.+?)\]\]/).flatten).empty?
|
125
|
+
rendered_string = text_el.text
|
126
|
+
results.each do |r|
|
127
|
+
padding = "".ljust(r.length + 8, " ")
|
128
|
+
rendered_string.gsub!("[[sig_#{r}]]", padding)
|
129
|
+
end
|
130
|
+
text_el.content = rendered_string
|
131
|
+
end
|
132
|
+
end
|
133
|
+
return elements
|
134
|
+
end
|
135
|
+
|
120
136
|
private
|
121
137
|
|
122
138
|
def get_condition(name, condition, inverted = false)
|
data/lib/lm_docstache/version.rb
CHANGED
data/lm_docstache.gemspec
CHANGED
@@ -5,8 +5,8 @@ require "lm_docstache/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "lm_docstache"
|
7
7
|
s.version = LMDocstache::VERSION
|
8
|
-
s.authors = ["Roey Chasman", "Jonathan Stevens", "Will Cosgrove"]
|
9
|
-
s.email = ["roey@lawmatics.com", "jonathan@lawmatics.com", "will@willcosgrove.com"]
|
8
|
+
s.authors = ["Roey Chasman", "Frederico Assunção", "Jonathan Stevens", "Will Cosgrove"]
|
9
|
+
s.email = ["roey@lawmatics.com", "fred@lawmatics.com", "jonathan@lawmatics.com", "will@willcosgrove.com"]
|
10
10
|
s.homepage = "https://www.lawmatics.com"
|
11
11
|
s.summary = %q{Merges Hash of Data into Word docx template files using mustache syntax}
|
12
12
|
s.description = %q{Integrates data into MS Word docx template files. Processing supports loops and replacement of strings of data both outside and within loops.}
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_runtime_dependency 'nokogiri', '~> 1.6'
|
21
21
|
s.add_runtime_dependency 'rubyzip', '~> 1.1'
|
22
22
|
|
23
|
-
s.add_development_dependency 'rspec', '>= 3.1.0'
|
24
|
-
s.add_development_dependency 'pry-byebug', '
|
25
|
-
s.add_development_dependency 'activesupport', '
|
23
|
+
s.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.0'
|
24
|
+
s.add_development_dependency 'pry-byebug', '~> 1'
|
25
|
+
s.add_development_dependency 'activesupport', '~> 3'
|
26
26
|
end
|
Binary file
|
data/spec/integration_spec.rb
CHANGED
@@ -35,7 +35,7 @@ end
|
|
35
35
|
describe 'integration test', integration: true do
|
36
36
|
let(:data) { LMDocstache::TestData::DATA }
|
37
37
|
let(:base_path) { SPEC_BASE_PATH.join('example_input') }
|
38
|
-
let(:input_file) { "#{base_path}/
|
38
|
+
let(:input_file) { "#{base_path}/ExampleTemplate2.docx" }
|
39
39
|
let(:output_dir) { "#{base_path}/tmp" }
|
40
40
|
let(:output_file) { "#{output_dir}/IntegrationTestOutput.docx" }
|
41
41
|
let(:document) { LMDocstache::Document.new(input_file) }
|
@@ -64,11 +64,19 @@ describe 'integration test', integration: true do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'has the expected amount of usable tags' do
|
67
|
-
expect(document.usable_tags.count).to be(
|
67
|
+
expect(document.usable_tags.count).to be(30)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'has the expected amount of signature tags' do
|
71
|
+
expect(document.signature_tags.count).to be(6)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'has the expected amount of usable signature tags' do
|
75
|
+
expect(document.usable_signature_tags.count).to be(6)
|
68
76
|
end
|
69
77
|
|
70
78
|
it 'has the expected amount of unique tag names' do
|
71
|
-
expect(document.usable_tag_names.count).to be(
|
79
|
+
expect(document.usable_tag_names.count).to be(18)
|
72
80
|
end
|
73
81
|
|
74
82
|
it 'renders file using data' do
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lm_docstache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roey Chasman
|
8
|
+
- Frederico Assunção
|
8
9
|
- Jonathan Stevens
|
9
10
|
- Will Cosgrove
|
10
|
-
autorequire:
|
11
|
+
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2020-
|
14
|
+
date: 2020-09-16 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: nokogiri
|
@@ -47,6 +48,9 @@ dependencies:
|
|
47
48
|
- - ">="
|
48
49
|
- !ruby/object:Gem::Version
|
49
50
|
version: 3.1.0
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.1'
|
50
54
|
type: :development
|
51
55
|
prerelease: false
|
52
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -54,38 +58,42 @@ dependencies:
|
|
54
58
|
- - ">="
|
55
59
|
- !ruby/object:Gem::Version
|
56
60
|
version: 3.1.0
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.1'
|
57
64
|
- !ruby/object:Gem::Dependency
|
58
65
|
name: pry-byebug
|
59
66
|
requirement: !ruby/object:Gem::Requirement
|
60
67
|
requirements:
|
61
|
-
- - "
|
68
|
+
- - "~>"
|
62
69
|
- !ruby/object:Gem::Version
|
63
70
|
version: '1'
|
64
71
|
type: :development
|
65
72
|
prerelease: false
|
66
73
|
version_requirements: !ruby/object:Gem::Requirement
|
67
74
|
requirements:
|
68
|
-
- - "
|
75
|
+
- - "~>"
|
69
76
|
- !ruby/object:Gem::Version
|
70
77
|
version: '1'
|
71
78
|
- !ruby/object:Gem::Dependency
|
72
79
|
name: activesupport
|
73
80
|
requirement: !ruby/object:Gem::Requirement
|
74
81
|
requirements:
|
75
|
-
- -
|
82
|
+
- - "~>"
|
76
83
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
84
|
+
version: '3'
|
78
85
|
type: :development
|
79
86
|
prerelease: false
|
80
87
|
version_requirements: !ruby/object:Gem::Requirement
|
81
88
|
requirements:
|
82
|
-
- -
|
89
|
+
- - "~>"
|
83
90
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
91
|
+
version: '3'
|
85
92
|
description: Integrates data into MS Word docx template files. Processing supports
|
86
93
|
loops and replacement of strings of data both outside and within loops.
|
87
94
|
email:
|
88
95
|
- roey@lawmatics.com
|
96
|
+
- fred@lawmatics.com
|
89
97
|
- jonathan@lawmatics.com
|
90
98
|
- will@willcosgrove.com
|
91
99
|
executables: []
|
@@ -96,7 +104,6 @@ files:
|
|
96
104
|
- ".gitignore"
|
97
105
|
- CHANGELOG.md
|
98
106
|
- Gemfile
|
99
|
-
- Gemfile.lock
|
100
107
|
- LICENSE.txt
|
101
108
|
- README.md
|
102
109
|
- Rakefile
|
@@ -111,6 +118,7 @@ files:
|
|
111
118
|
- spec/data_scope_spec.rb
|
112
119
|
- spec/empty_data_scope_spec.rb
|
113
120
|
- spec/example_input/ExampleTemplate.docx
|
121
|
+
- spec/example_input/ExampleTemplate2.docx
|
114
122
|
- spec/example_input/blank.docx
|
115
123
|
- spec/example_input/word/document.xml
|
116
124
|
- spec/integration_spec.rb
|
@@ -120,7 +128,7 @@ homepage: https://www.lawmatics.com
|
|
120
128
|
licenses:
|
121
129
|
- MIT
|
122
130
|
metadata: {}
|
123
|
-
post_install_message:
|
131
|
+
post_install_message:
|
124
132
|
rdoc_options: []
|
125
133
|
require_paths:
|
126
134
|
- lib
|
@@ -136,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
144
|
version: '0'
|
137
145
|
requirements: []
|
138
146
|
rubygems_version: 3.0.3
|
139
|
-
signing_key:
|
147
|
+
signing_key:
|
140
148
|
specification_version: 4
|
141
149
|
summary: Merges Hash of Data into Word docx template files using mustache syntax
|
142
150
|
test_files:
|
@@ -144,6 +152,7 @@ test_files:
|
|
144
152
|
- spec/data_scope_spec.rb
|
145
153
|
- spec/empty_data_scope_spec.rb
|
146
154
|
- spec/example_input/ExampleTemplate.docx
|
155
|
+
- spec/example_input/ExampleTemplate2.docx
|
147
156
|
- spec/example_input/blank.docx
|
148
157
|
- spec/example_input/word/document.xml
|
149
158
|
- spec/integration_spec.rb
|
data/Gemfile.lock
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
lm_docstache (1.2.1)
|
5
|
-
nokogiri (~> 1.6)
|
6
|
-
rubyzip (~> 1.1)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activesupport (6.0.3.2)
|
12
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
-
i18n (>= 0.7, < 2)
|
14
|
-
minitest (~> 5.1)
|
15
|
-
tzinfo (~> 1.1)
|
16
|
-
zeitwerk (~> 2.2, >= 2.2.2)
|
17
|
-
byebug (11.1.3)
|
18
|
-
coderay (1.1.3)
|
19
|
-
concurrent-ruby (1.1.6)
|
20
|
-
diff-lcs (1.4.4)
|
21
|
-
i18n (1.8.3)
|
22
|
-
concurrent-ruby (~> 1.0)
|
23
|
-
method_source (1.0.0)
|
24
|
-
mini_portile2 (2.4.0)
|
25
|
-
minitest (5.14.1)
|
26
|
-
nokogiri (1.10.10)
|
27
|
-
mini_portile2 (~> 2.4.0)
|
28
|
-
pry (0.13.1)
|
29
|
-
coderay (~> 1.1)
|
30
|
-
method_source (~> 1.0)
|
31
|
-
pry-byebug (3.9.0)
|
32
|
-
byebug (~> 11.0)
|
33
|
-
pry (~> 0.13.0)
|
34
|
-
rspec (3.9.0)
|
35
|
-
rspec-core (~> 3.9.0)
|
36
|
-
rspec-expectations (~> 3.9.0)
|
37
|
-
rspec-mocks (~> 3.9.0)
|
38
|
-
rspec-core (3.9.2)
|
39
|
-
rspec-support (~> 3.9.3)
|
40
|
-
rspec-expectations (3.9.2)
|
41
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.9.0)
|
43
|
-
rspec-mocks (3.9.1)
|
44
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.9.0)
|
46
|
-
rspec-support (3.9.3)
|
47
|
-
rubyzip (1.3.0)
|
48
|
-
thread_safe (0.3.6)
|
49
|
-
tzinfo (1.2.7)
|
50
|
-
thread_safe (~> 0.1)
|
51
|
-
zeitwerk (2.4.0)
|
52
|
-
|
53
|
-
PLATFORMS
|
54
|
-
ruby
|
55
|
-
|
56
|
-
DEPENDENCIES
|
57
|
-
activesupport (= 6.0.3.2)
|
58
|
-
lm_docstache!
|
59
|
-
pry-byebug (>= 1)
|
60
|
-
rspec (>= 3.1.0)
|
61
|
-
|
62
|
-
BUNDLED WITH
|
63
|
-
1.17.2
|