lm_docstache 1.2.4 → 1.3.5
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 +15 -0
- data/lib/lm_docstache/document.rb +45 -5
- data/lib/lm_docstache/renderer.rb +17 -1
- data/lib/lm_docstache/version.rb +1 -1
- data/lm_docstache.gemspec +2 -2
- data/spec/example_input/ExampleTemplate2.docx +0 -0
- data/spec/example_input/~$ampleTemplate2.docx +0 -0
- data/spec/integration_spec.rb +15 -3
- metadata +15 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6ab6dff16fa851d40af9c350e4be33c01536dc9a8a9df53f7fd543cb81a9b31
|
4
|
+
data.tar.gz: 92514737372741fdadd2fbf84ed8d00617a1d7ba0e07c54f9e0cb08c829c665e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5232508c9ddd3eeaf52df714639d934baba80c613c35fa42239b242aad0243fff39f73b781b1392394cdb9c57bf702146a95d2456bc061382cd7f9d76b51385
|
7
|
+
data.tar.gz: c3a81aea4a97040b5f7157f727c4c616810a676e7d38038b50564bee3fbf8d4739b04f19310c2ccd78e7ff59e0d9eb3eb2a09d1d127931f98344787e9ea7025b
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
# Changelog
|
2
|
+
## 1.3.5
|
3
|
+
* Replace signatures by roles. Add unique roles name collector.
|
4
|
+
|
5
|
+
## 1.3.4
|
6
|
+
* Change signature signs identifiers to be braces instead of brackets.
|
7
|
+
|
8
|
+
## 1.3.2
|
9
|
+
* Fix bug replacing signature tags accross xml nodes.
|
10
|
+
|
11
|
+
## 1.3.1
|
12
|
+
* Fix bug searching accross xml nodes for e-signature tags.
|
13
|
+
|
14
|
+
## 1.3.0
|
15
|
+
* Add support for e-signature tags
|
16
|
+
|
2
17
|
## 1.2.4
|
3
18
|
* Add support for pipe character in merge tags so we can use as a modifier for the context of merge tag.
|
4
19
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module LMDocstache
|
2
2
|
class Document
|
3
|
+
TAGS_REGEXP = /\{\{.+?\}\}/
|
4
|
+
ROLES_REGEXP = /(\{\{(sig|sigfirm|date|check|text|initial)\|(req|noreq)\|(.+?)\}\})/
|
3
5
|
def initialize(*paths)
|
4
6
|
raise ArgumentError if paths.empty?
|
5
7
|
@path = paths.shift
|
@@ -15,17 +17,55 @@ module LMDocstache
|
|
15
17
|
find_documents_to_interpolate
|
16
18
|
end
|
17
19
|
|
20
|
+
def role_tags
|
21
|
+
@documents.values.flat_map do |document|
|
22
|
+
document.text.strip.scan(ROLES_REGEXP)
|
23
|
+
.map {|r| r.first }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def usable_role_tags
|
28
|
+
@documents.values.flat_map do |document|
|
29
|
+
document.css('w|p')
|
30
|
+
.select { |tag| tag.text =~ ROLES_REGEXP }
|
31
|
+
.flat_map { |tag|
|
32
|
+
tag.text.scan(ROLES_REGEXP)
|
33
|
+
.map {|r| r.first }
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def unique_role_tag_names
|
39
|
+
@documents.values.flat_map do |document|
|
40
|
+
document.css('w|p')
|
41
|
+
.select { |tag| tag.text =~ ROLES_REGEXP }
|
42
|
+
.flat_map { |tag|
|
43
|
+
tag.text.scan(ROLES_REGEXP).map {|r| r[3].strip }
|
44
|
+
}.compact.uniq
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def unusable_role_tags
|
49
|
+
unusable_signature_tags = role_tags
|
50
|
+
unusable_signature_tags.each do |usable_tag|
|
51
|
+
index = unusable_signature_tags.index(usable_tag)
|
52
|
+
unusable_signature_tags.delete_at(index) if index
|
53
|
+
end
|
54
|
+
return unusable_signature_tags
|
55
|
+
end
|
56
|
+
|
18
57
|
def tags
|
19
58
|
@documents.values.flat_map do |document|
|
20
|
-
document.text.strip.scan(
|
59
|
+
document.text.strip.scan(TAGS_REGEXP)
|
60
|
+
.select {|t| !(t =~ ROLES_REGEXP)}
|
21
61
|
end
|
22
62
|
end
|
23
63
|
|
24
64
|
def usable_tags
|
25
65
|
@documents.values.flat_map do |document|
|
26
66
|
document.css('w|t')
|
27
|
-
.select { |tag| tag.text =~
|
28
|
-
.flat_map { |tag| tag.text.scan(
|
67
|
+
.select { |tag| tag.text =~ TAGS_REGEXP && !(tag.text =~ ROLES_REGEXP) }
|
68
|
+
.flat_map { |tag| tag.text.scan(TAGS_REGEXP) }
|
29
69
|
end
|
30
70
|
end
|
31
71
|
|
@@ -58,10 +98,10 @@ module LMDocstache
|
|
58
98
|
File.open(path, "w") { |f| f.write buffer.string }
|
59
99
|
end
|
60
100
|
|
61
|
-
def render_file(output, data={})
|
101
|
+
def render_file(output, data={}, remove_signature_tags = false)
|
62
102
|
rendered_documents = Hash[
|
63
103
|
@documents.map do |(path, document)|
|
64
|
-
[path, LMDocstache::Renderer.new(document.dup, data).render]
|
104
|
+
[path, LMDocstache::Renderer.new(document.dup, data, remove_signature_tags).render]
|
65
105
|
end
|
66
106
|
]
|
67
107
|
buffer = zip_buffer(rendered_documents)
|
@@ -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
|
|
@@ -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.}
|
Binary file
|
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,23 @@ 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 role tags' do
|
71
|
+
expect(document.role_tags.count).to be(6)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'has the expected amount of uniq role tags' do
|
75
|
+
expect(document.unique_role_tag_names.count).to be(5)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'has the expected amount of usable roles tags' do
|
79
|
+
expect(document.usable_role_tags.count).to be(6)
|
68
80
|
end
|
69
81
|
|
70
82
|
it 'has the expected amount of unique tag names' do
|
71
|
-
expect(document.usable_tag_names.count).to be(
|
83
|
+
expect(document.usable_tag_names.count).to be(18)
|
72
84
|
end
|
73
85
|
|
74
86
|
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.5
|
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-11-03 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
|
@@ -92,6 +93,7 @@ description: Integrates data into MS Word docx template files. Processing suppor
|
|
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,8 +118,10 @@ 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
|
124
|
+
- spec/example_input/~$ampleTemplate2.docx
|
121
125
|
- spec/integration_spec.rb
|
122
126
|
- spec/spec_helper.rb
|
123
127
|
- spec/template_processor_spec.rb
|
@@ -140,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
144
|
- !ruby/object:Gem::Version
|
141
145
|
version: '0'
|
142
146
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
147
|
+
rubygems_version: 3.1.2
|
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,8 +153,10 @@ 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
|
159
|
+
- spec/example_input/~$ampleTemplate2.docx
|
154
160
|
- spec/integration_spec.rb
|
155
161
|
- spec/spec_helper.rb
|
156
162
|
- spec/template_processor_spec.rb
|