sablon 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sablon/processor.rb +12 -0
- data/lib/sablon/version.rb +1 -1
- data/test/fixtures/xml/corrupt_table.xml +42 -0
- data/test/processor_test.rb +67 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45490341d42142a355c3fbf6f5aa00c30d801acc
|
4
|
+
data.tar.gz: bdf40b4c70137309609cfa3472f634619c13605c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38aa0a39b40f1219f8bafe6d80072d08f1da5c7825ee9270ba0bc0e5aec23adcba531bd39829c2d05d85fec57162161591b7202366902724b7d389d0b4f0f440
|
7
|
+
data.tar.gz: 79c63b61bdb204e436c53450327465f60af6a3a4083f9907b604b737c4f7e1622f67aa65a57718d9043b807322768469096728f427ccb4d4721503b2bf538e87
|
data/lib/sablon/processor.rb
CHANGED
@@ -22,6 +22,7 @@ module Sablon
|
|
22
22
|
operations.each do |step|
|
23
23
|
step.evaluate context
|
24
24
|
end
|
25
|
+
cleanup(xml_node)
|
25
26
|
xml_node
|
26
27
|
end
|
27
28
|
|
@@ -37,6 +38,17 @@ module Sablon
|
|
37
38
|
OperationConstruction.new(fields).operations
|
38
39
|
end
|
39
40
|
|
41
|
+
def cleanup(xml_node)
|
42
|
+
fill_empty_table_cells xml_node
|
43
|
+
end
|
44
|
+
|
45
|
+
def fill_empty_table_cells(xml_node)
|
46
|
+
xml_node.xpath("//w:tc[count(*[name() = 'w:p'])=0 or not(*)]").each do |blank_cell|
|
47
|
+
filler = Nokogiri::XML::Node.new("w:p", xml_node.document)
|
48
|
+
blank_cell.add_child filler
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
40
52
|
class Block < Struct.new(:start_field, :end_field)
|
41
53
|
def self.enclosed_by(start_field, end_field)
|
42
54
|
@blocks ||= [RowBlock, ParagraphBlock]
|
data/lib/sablon/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
<w:tbl>
|
2
|
+
<w:tblGrid>
|
3
|
+
<w:gridCol w:w="2202"/>
|
4
|
+
</w:tblGrid>
|
5
|
+
<w:tr w:rsidR="00757DAD">
|
6
|
+
<w:tc>
|
7
|
+
<w:p>
|
8
|
+
Hans
|
9
|
+
</w:p>
|
10
|
+
</w:tc>
|
11
|
+
|
12
|
+
<w:tc>
|
13
|
+
<w:tcPr>
|
14
|
+
<w:tcW w:w="5635" w:type="dxa"/>
|
15
|
+
</w:tcPr>
|
16
|
+
</w:tc>
|
17
|
+
</w:tr>
|
18
|
+
|
19
|
+
<w:tr w:rsidR="00757DAD">
|
20
|
+
<w:tc>
|
21
|
+
<w:tcPr>
|
22
|
+
<w:tcW w:w="2202" w:type="dxa"/>
|
23
|
+
</w:tcPr>
|
24
|
+
<w:p>
|
25
|
+
<w:r>
|
26
|
+
<w:rPr><w:noProof/></w:rPr>
|
27
|
+
<w:t>1.</w:t>
|
28
|
+
</w:r>
|
29
|
+
</w:p>
|
30
|
+
</w:tc>
|
31
|
+
|
32
|
+
<w:tc>
|
33
|
+
<w:p>
|
34
|
+
</w:p><w:p>
|
35
|
+
<w:r w:rsidR="004B49F0">
|
36
|
+
<w:rPr><w:noProof/></w:rPr>
|
37
|
+
<w:t>Chef</w:t>
|
38
|
+
</w:r>
|
39
|
+
</w:p>
|
40
|
+
</w:tc>
|
41
|
+
</w:tr>
|
42
|
+
</w:tbl>
|
data/test/processor_test.rb
CHANGED
@@ -121,6 +121,73 @@ class ProcessorTest < Sablon::TestCase
|
|
121
121
|
document
|
122
122
|
end
|
123
123
|
|
124
|
+
def test_paragraph_block_within_empty_table_cell_and_blank_replacement
|
125
|
+
result = process(snippet("paragraph_loop_within_table_cell"), {"technologies" => []})
|
126
|
+
|
127
|
+
assert_equal "", text(result)
|
128
|
+
assert_xml_equal <<-document, result
|
129
|
+
<w:tbl>
|
130
|
+
<w:tblGrid>
|
131
|
+
<w:gridCol w:w="2202"/>
|
132
|
+
</w:tblGrid>
|
133
|
+
<w:tr w:rsidR="00757DAD">
|
134
|
+
<w:tc>
|
135
|
+
<w:p></w:p>
|
136
|
+
</w:tc>
|
137
|
+
</w:tr>
|
138
|
+
</w:tbl>
|
139
|
+
document
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_adds_blank_paragraph_to_empty_table_cells
|
143
|
+
result = process(snippet("corrupt_table"), {})
|
144
|
+
assert_xml_equal <<-document, result
|
145
|
+
<w:tbl>
|
146
|
+
<w:tblGrid>
|
147
|
+
<w:gridCol w:w="2202"/>
|
148
|
+
</w:tblGrid>
|
149
|
+
<w:tr w:rsidR="00757DAD">
|
150
|
+
<w:tc>
|
151
|
+
<w:p>
|
152
|
+
Hans
|
153
|
+
</w:p>
|
154
|
+
</w:tc>
|
155
|
+
|
156
|
+
<w:tc>
|
157
|
+
<w:tcPr>
|
158
|
+
<w:tcW w:w="5635" w:type="dxa"/>
|
159
|
+
</w:tcPr>
|
160
|
+
<w:p></w:p>
|
161
|
+
</w:tc>
|
162
|
+
</w:tr>
|
163
|
+
|
164
|
+
<w:tr w:rsidR="00757DAD">
|
165
|
+
<w:tc>
|
166
|
+
<w:tcPr>
|
167
|
+
<w:tcW w:w="2202" w:type="dxa"/>
|
168
|
+
</w:tcPr>
|
169
|
+
<w:p>
|
170
|
+
<w:r>
|
171
|
+
<w:rPr><w:noProof/></w:rPr>
|
172
|
+
<w:t>1.</w:t>
|
173
|
+
</w:r>
|
174
|
+
</w:p>
|
175
|
+
</w:tc>
|
176
|
+
|
177
|
+
<w:tc>
|
178
|
+
<w:p>
|
179
|
+
</w:p><w:p>
|
180
|
+
<w:r w:rsidR="004B49F0">
|
181
|
+
<w:rPr><w:noProof/></w:rPr>
|
182
|
+
<w:t>Chef</w:t>
|
183
|
+
</w:r>
|
184
|
+
</w:p>
|
185
|
+
</w:tc>
|
186
|
+
</w:tr>
|
187
|
+
</w:tbl>
|
188
|
+
document
|
189
|
+
end
|
190
|
+
|
124
191
|
def test_single_row_table_loop
|
125
192
|
item = Struct.new(:index, :label, :rating)
|
126
193
|
result = process(snippet("table_row_loop"), {"items" => [item.new("1.", "Milk", "***"), item.new("2.", "Sugar", "**")]})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sablon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yves Senn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- test/fixtures/xml/conditional.xml
|
134
134
|
- test/fixtures/xml/conditional_with_predicate.xml
|
135
135
|
- test/fixtures/xml/conditional_without_ending.xml
|
136
|
+
- test/fixtures/xml/corrupt_table.xml
|
136
137
|
- test/fixtures/xml/edited_complex_field.xml
|
137
138
|
- test/fixtures/xml/loop_without_ending.xml
|
138
139
|
- test/fixtures/xml/paragraph_loop.xml
|
@@ -185,6 +186,7 @@ test_files:
|
|
185
186
|
- test/fixtures/xml/conditional.xml
|
186
187
|
- test/fixtures/xml/conditional_with_predicate.xml
|
187
188
|
- test/fixtures/xml/conditional_without_ending.xml
|
189
|
+
- test/fixtures/xml/corrupt_table.xml
|
188
190
|
- test/fixtures/xml/edited_complex_field.xml
|
189
191
|
- test/fixtures/xml/loop_without_ending.xml
|
190
192
|
- test/fixtures/xml/paragraph_loop.xml
|