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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f0de4c805cae97f7a2a68f2b82d081c7f5a6aac
4
- data.tar.gz: 7083c6d868050f33ef08de6c0c698f9fdece86f8
3
+ metadata.gz: 45490341d42142a355c3fbf6f5aa00c30d801acc
4
+ data.tar.gz: bdf40b4c70137309609cfa3472f634619c13605c
5
5
  SHA512:
6
- metadata.gz: da8799eeef32b9142c69edd505a9609b57097306f0f2e452a5e541d31bbcaad7e16c28ffee420ac18d646ec46ab67cd323b7b8b7e72876372f1f408cd0cd0fce
7
- data.tar.gz: 42f093e8db992ceff780d931a3cd7170349f3498c2c81de58539492253207eb7e4d747fb888ada796279dfe1982e261f852be8c88574a914f7588490a6254b49
6
+ metadata.gz: 38aa0a39b40f1219f8bafe6d80072d08f1da5c7825ee9270ba0bc0e5aec23adcba531bd39829c2d05d85fec57162161591b7202366902724b7d389d0b4f0f440
7
+ data.tar.gz: 79c63b61bdb204e436c53450327465f60af6a3a4083f9907b604b737c4f7e1622f67aa65a57718d9043b807322768469096728f427ccb4d4721503b2bf538e87
@@ -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]
@@ -1,3 +1,3 @@
1
1
  module Sablon
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -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>
@@ -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.6
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-05 00:00:00.000000000 Z
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