lm_docstache 1.2.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/lm_docstache/document.rb +32 -2
- data/lib/lm_docstache/renderer.rb +17 -1
- data/lib/lm_docstache/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ae5d34672eaa5bce54718805fd2984f6a016b258f0376f3aa6707bb7c04d701
|
4
|
+
data.tar.gz: d9aacd28e9f78e7b194e6fd32fa9948d997b171427f8e425f376214eda044602
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea353f13320611862bb5081806a05320b99d76fb1ae4cdc5693af1d75c9419d997458b0319142825fc76f302c19613aafc7e232cd506b9ba1134570317db7b5f
|
7
|
+
data.tar.gz: fbbb70c2866c3c344efeb5c99ff748d7b53c51796512c0e485718523f1894aa7dff40a03f5a4fc3b4c9f3cff1f87ec082b3f3d1ad2159acb43d3b907d14441c7
|
data/CHANGELOG.md
CHANGED
@@ -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|t')
|
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)
|
@@ -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|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
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: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roey Chasman
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-09-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|