lm_docstache 1.2.2.1 → 1.3.2
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/CHANGELOG.md +14 -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 +3 -3
- data/spec/example_input/ExampleTemplate2.docx +0 -0
- data/spec/integration_spec.rb +11 -3
- metadata +16 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5fc07cb8e83945cfdf666da91c1128736fe04b268f6650a5e5f7362e73138f1
|
4
|
+
data.tar.gz: 2d9d44dd5fe120c422689218367d811c081f1cf30e7aa30221875ee008134418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d84deb7909e533b9af7ee3f70ec2201ee95a55d4bc8069b811c3650411ff4a8e0d3ddf9f9007dcb72b9c6b4dcb8aabe05a64d33557879426f98253fb4af1270
|
7
|
+
data.tar.gz: cf3cc3249c5f6e6b70a4d3121993e0cccd09472a08e61e57c33f71266d1b1b8bf52032cfd99a6b97c4957a08e6d8e8661faf93f8512ce30215b8559c5ed8d61c
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
# Changelog
|
2
|
+
## 1.3.2
|
3
|
+
* Fix bug replacing signature tags accross xml nodes.
|
4
|
+
|
5
|
+
## 1.3.1
|
6
|
+
* Fix bug searching accross xml nodes for e-signature tags.
|
7
|
+
|
8
|
+
## 1.3.0
|
9
|
+
* Add support for e-signature tags
|
10
|
+
|
11
|
+
## 1.2.4
|
12
|
+
* Add support for pipe character in merge tags so we can use as a modifier for the context of merge tag.
|
13
|
+
|
14
|
+
## 1.2.3
|
15
|
+
* 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
16
|
|
3
17
|
## 1.2.2
|
4
18
|
* 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|p').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.}
|
@@ -22,5 +22,5 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.0'
|
24
24
|
s.add_development_dependency 'pry-byebug', '~> 1'
|
25
|
-
s.add_development_dependency 'activesupport', '~>
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roey Chasman
|
8
|
+
- Frederico Assunção
|
8
9
|
- Jonathan Stevens
|
9
10
|
- Will Cosgrove
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2020-
|
14
|
+
date: 2020-09-17 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: nokogiri
|
@@ -44,22 +45,22 @@ dependencies:
|
|
44
45
|
name: rspec
|
45
46
|
requirement: !ruby/object:Gem::Requirement
|
46
47
|
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 3.1.0
|
50
48
|
- - "~>"
|
51
49
|
- !ruby/object:Gem::Version
|
52
50
|
version: '3.1'
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.1.0
|
53
54
|
type: :development
|
54
55
|
prerelease: false
|
55
56
|
version_requirements: !ruby/object:Gem::Requirement
|
56
57
|
requirements:
|
57
|
-
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: 3.1.0
|
60
58
|
- - "~>"
|
61
59
|
- !ruby/object:Gem::Version
|
62
60
|
version: '3.1'
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 3.1.0
|
63
64
|
- !ruby/object:Gem::Dependency
|
64
65
|
name: pry-byebug
|
65
66
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,18 +81,19 @@ dependencies:
|
|
80
81
|
requirements:
|
81
82
|
- - "~>"
|
82
83
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
84
|
+
version: '3'
|
84
85
|
type: :development
|
85
86
|
prerelease: false
|
86
87
|
version_requirements: !ruby/object:Gem::Requirement
|
87
88
|
requirements:
|
88
89
|
- - "~>"
|
89
90
|
- !ruby/object:Gem::Version
|
90
|
-
version: '
|
91
|
+
version: '3'
|
91
92
|
description: Integrates data into MS Word docx template files. Processing supports
|
92
93
|
loops and replacement of strings of data both outside and within loops.
|
93
94
|
email:
|
94
95
|
- roey@lawmatics.com
|
96
|
+
- fred@lawmatics.com
|
95
97
|
- jonathan@lawmatics.com
|
96
98
|
- will@willcosgrove.com
|
97
99
|
executables: []
|
@@ -116,6 +118,7 @@ files:
|
|
116
118
|
- spec/data_scope_spec.rb
|
117
119
|
- spec/empty_data_scope_spec.rb
|
118
120
|
- spec/example_input/ExampleTemplate.docx
|
121
|
+
- spec/example_input/ExampleTemplate2.docx
|
119
122
|
- spec/example_input/blank.docx
|
120
123
|
- spec/example_input/word/document.xml
|
121
124
|
- spec/integration_spec.rb
|
@@ -140,7 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
143
|
- !ruby/object:Gem::Version
|
141
144
|
version: '0'
|
142
145
|
requirements: []
|
143
|
-
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.7.6
|
144
148
|
signing_key:
|
145
149
|
specification_version: 4
|
146
150
|
summary: Merges Hash of Data into Word docx template files using mustache syntax
|
@@ -149,6 +153,7 @@ test_files:
|
|
149
153
|
- spec/data_scope_spec.rb
|
150
154
|
- spec/empty_data_scope_spec.rb
|
151
155
|
- spec/example_input/ExampleTemplate.docx
|
156
|
+
- spec/example_input/ExampleTemplate2.docx
|
152
157
|
- spec/example_input/blank.docx
|
153
158
|
- spec/example_input/word/document.xml
|
154
159
|
- spec/integration_spec.rb
|