lm_docstache 1.2.3 → 1.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c16a6e73e07d070f2c486647c784c04627d746849481c145d66f6735780c65bb
4
- data.tar.gz: 2fa52f69ea406bfe221bccff2a599af568ea9e0d6c21ab20500d06ad0dbfaeb4
3
+ metadata.gz: 3268400635c8fd94b49786b4509b78f3acc649e8fb1bea2b65ba4a7f520b6b22
4
+ data.tar.gz: 19a429793e0699e2026a726c73d8c579f3644b4f88425ef57944dada31e878cc
5
5
  SHA512:
6
- metadata.gz: '0096916f50745ca968b0a2d365a0d279aae3007c4d7e5e6376c87b1d512f082d0646e064d5a84bef9be1b33e53eb3d81d33122a6e868c2e389f67aecfbe00662'
7
- data.tar.gz: 0723cefa1931bbc2d8b7ab513d1af844f43d05ff4d61fa04d73ad772cbd8a81dea29319a72403b6657ae49688026edc6ace60dc5a0b32a85ed8223c003820901
6
+ metadata.gz: a902c19fa827102d3396d317e977031db56071d3bead3900f83f67583f41e96bca042c4f9ab54d215058c0af3d76ff492bc059d17d22c3c710a6ee7aa637492d
7
+ data.tar.gz: deb3bda8b3ce6ea84f6334197bf93fd7e10950e84386731ad9426f9f746ab1967485b54b312160c98bae2eac7a1752b0c35e65e36c54208ea8177af03db730ec
@@ -1,4 +1,21 @@
1
1
  # Changelog
2
+ ## 1.3.4
3
+ * Change signature signs identifiers to be braces instead of brackets.
4
+
5
+ ## 1.3.2
6
+ * Fix bug replacing signature tags accross xml nodes.
7
+
8
+ ## 1.3.1
9
+ * Fix bug searching accross xml nodes for e-signature tags.
10
+
11
+ ## 1.3.0
12
+ * Add support for e-signature tags
13
+
14
+ ## 1.2.4
15
+ * Add support for pipe character in merge tags so we can use as a modifier for the context of merge tag.
16
+
17
+ ## 1.2.3
18
+ * 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
19
 
3
20
  ## 1.2.2
4
21
  * Remove uneccessary runtime dependency on active support.
@@ -1,5 +1,7 @@
1
1
  module LMDocstache
2
2
  class Document
3
+ TAGS_REGEXP = /\{\{.+?\}\}/
4
+ SIGNATURE_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,52 @@ module LMDocstache
15
17
  find_documents_to_interpolate
16
18
  end
17
19
 
20
+ def signature_tags
21
+ @documents.values.flat_map do |document|
22
+ document.text.strip.scan(SIGNATURE_REGEXP)
23
+ .map {|r| r.first }
24
+ end
25
+ end
26
+
27
+ def usable_signature_tags
28
+ @documents.values.flat_map do |document|
29
+ document.css('w|p')
30
+ .select { |tag| tag.text =~ SIGNATURE_REGEXP }
31
+ .flat_map { |tag|
32
+ tag.text.scan(SIGNATURE_REGEXP)
33
+ .map {|r| r.first }
34
+ }
35
+ end
36
+ end
37
+
38
+ def usable_signature_tag_names
39
+ self.usable_signature_tags.map do |tag|
40
+ tag.scan(SIGNATURE_REGEXP)
41
+ .map {|r| r.first }
42
+ end.compact.uniq
43
+ end
44
+
45
+ def unusable_signature_tags
46
+ unusable_signature_tags = signature_tags
47
+ unusable_signature_tags.each do |usable_tag|
48
+ index = unusable_signature_tags.index(usable_tag)
49
+ unusable_signature_tags.delete_at(index) if index
50
+ end
51
+ return unusable_signature_tags
52
+ end
53
+
18
54
  def tags
19
55
  @documents.values.flat_map do |document|
20
- document.text.strip.scan(/\{\{.+?\}\}/)
56
+ document.text.strip.scan(TAGS_REGEXP)
57
+ .select {|t| !(t =~ SIGNATURE_REGEXP)}
21
58
  end
22
59
  end
23
60
 
24
61
  def usable_tags
25
62
  @documents.values.flat_map do |document|
26
63
  document.css('w|t')
27
- .select { |tag| tag.text =~ /\{\{.+?\}\}/ }
28
- .flat_map { |tag| tag.text.scan(/\{\{.+?\}\}/) }
64
+ .select { |tag| tag.text =~ TAGS_REGEXP && !(tag.text =~ SIGNATURE_REGEXP) }
65
+ .flat_map { |tag| tag.text.scan(TAGS_REGEXP) }
29
66
  end
30
67
  end
31
68
 
@@ -58,10 +95,10 @@ module LMDocstache
58
95
  File.open(path, "w") { |f| f.write buffer.string }
59
96
  end
60
97
 
61
- def render_file(output, data={})
98
+ def render_file(output, data={}, remove_signature_tags = false)
62
99
  rendered_documents = Hash[
63
100
  @documents.map do |(path, document)|
64
- [path, LMDocstache::Renderer.new(document.dup, data).render]
101
+ [path, LMDocstache::Renderer.new(document.dup, data, remove_signature_tags).render]
65
102
  end
66
103
  ]
67
104
  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
 
@@ -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\.]+)\}\}/).flatten).empty?
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)
@@ -1,3 +1,3 @@
1
1
  module LMDocstache
2
- VERSION = "1.2.3"
2
+ VERSION = "1.3.4"
3
3
  end
@@ -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.}
@@ -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}/ExampleTemplate.docx" }
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(27)
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(16)
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.2.3
4
+ version: 1.3.4
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-07-28 00:00:00.000000000 Z
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,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,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
143
  - !ruby/object:Gem::Version
141
144
  version: '0'
142
145
  requirements: []
143
- rubygems_version: 3.0.3
146
+ rubygems_version: 3.1.2
144
147
  signing_key:
145
148
  specification_version: 4
146
149
  summary: Merges Hash of Data into Word docx template files using mustache syntax
@@ -149,6 +152,7 @@ test_files:
149
152
  - spec/data_scope_spec.rb
150
153
  - spec/empty_data_scope_spec.rb
151
154
  - spec/example_input/ExampleTemplate.docx
155
+ - spec/example_input/ExampleTemplate2.docx
152
156
  - spec/example_input/blank.docx
153
157
  - spec/example_input/word/document.xml
154
158
  - spec/integration_spec.rb