sablon 0.0.20 → 0.0.21

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
  SHA1:
3
- metadata.gz: 698e85a00ad9dace7dd51e7cf8887d59612edf60
4
- data.tar.gz: 06fefc2d6ae9d747ca0d5cad4aca1cef80036cbd
3
+ metadata.gz: b83974c57d78d5a2b9ae7f1fc15f8527b3d349bf
4
+ data.tar.gz: 1d8283d8c781bb7e3810316cd71ef60f4e53cf70
5
5
  SHA512:
6
- metadata.gz: f86083620b300bd83e48721ba92cd9909556692bec0362990997c8f1f9c7b78155929628a104995ba8c586e90afce5c8505eedeb3cc84ac6e23c347afae02c09
7
- data.tar.gz: 4c2320a98d95071d4ea0ee3d9ec88f3cd7ba93f6618b016c3a97eb94339d7850561bf51bba5e1821b0d2f93d06123de06f41d1a35e381f240875416e46f47c05
6
+ metadata.gz: aacf3306315f9d9cc76c82de9a43cbf491ffccc5af4434e1409c6a7f513ef13133868201ba5cf702c478c585182fd46d8232a2c8e45ae3b50675cdc957f4b7a6
7
+ data.tar.gz: bf82feaafe41009c8f1e4b95a3dbbf31159da473fcfda2cad055c37bfe3ba600d7529aabba8bf3574353bbb81be9f9e9b751b7aa8e5e93b8ef8df740790db6e6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sablon (0.0.20)
4
+ sablon (0.0.21)
5
5
  nokogiri (>= 1.6.0)
6
6
  rubyzip (>= 1.1)
7
7
 
@@ -10,12 +10,10 @@ GEM
10
10
  specs:
11
11
  mini_portile2 (2.1.0)
12
12
  minitest (5.8.0)
13
- nokogiri (1.6.8)
13
+ nokogiri (1.7.1)
14
14
  mini_portile2 (~> 2.1.0)
15
- pkg-config (~> 1.1.7)
16
- pkg-config (1.1.7)
17
15
  rake (10.4.2)
18
- rubyzip (1.2.0)
16
+ rubyzip (1.2.1)
19
17
  xml-simple (1.1.5)
20
18
 
21
19
  PLATFORMS
@@ -29,4 +27,4 @@ DEPENDENCIES
29
27
  xml-simple
30
28
 
31
29
  BUNDLED WITH
32
- 1.12.5
30
+ 1.14.5
data/README.md CHANGED
@@ -36,6 +36,8 @@ Sablon templates are normal Word documents (`.docx`) sprinkled with MailMerge fi
36
36
  to perform operations. The following section uses the notation `«=title»` to
37
37
  refer to [Word MailMerge](http://en.wikipedia.org/wiki/Mail_merge) fields.
38
38
 
39
+ A detailed description about how to create a template can be found [here](misc/TEMPLATE.md)
40
+
39
41
  #### Content Insertion
40
42
 
41
43
  The most basic operation is to insert content. The contents of a context
@@ -4,7 +4,7 @@ module Sablon
4
4
  class Insertion < Struct.new(:expr, :field)
5
5
  def evaluate(context)
6
6
  if content = expr.evaluate(context)
7
- field.replace(Sablon::Content.wrap(expr.evaluate(context)))
7
+ field.replace(Sablon::Content.wrap(content))
8
8
  else
9
9
  field.remove
10
10
  end
@@ -111,6 +111,7 @@ module Sablon
111
111
  end
112
112
 
113
113
  private
114
+
114
115
  def build_complex_field(node)
115
116
  possible_field_node = node.parent
116
117
  field_nodes = [possible_field_node]
@@ -118,7 +119,8 @@ module Sablon
118
119
  possible_field_node = possible_field_node.next_element
119
120
  field_nodes << possible_field_node
120
121
  end
121
- ComplexField.new(field_nodes)
122
+ # skip instantiation if no end tag
123
+ ComplexField.new(field_nodes) if field_nodes.last
122
124
  end
123
125
  end
124
126
  end
@@ -1,3 +1,3 @@
1
1
  module Sablon
2
- VERSION = "0.0.20"
2
+ VERSION = "0.0.21"
3
3
  end
data/misc/TEMPLATE.md ADDED
@@ -0,0 +1,44 @@
1
+ ### Creating a Simple Template
2
+ Creating a template is as easy as creating a normal Word document (`.docx`). Yet it could be confusing to people who haven't used the [Mail Merge](https://support.office.com/en-us/article/Use-mail-merge-to-send-bulk-email-messages-0f123521-20ce-4aa8-8b62-ac211dedefa4) feature in Microsoft Word. The steps are as follows:
3
+
4
+ - Create a new word document
5
+
6
+ ![Step 1](/misc/step_1.png)
7
+
8
+ - Create your template
9
+
10
+ ![Step 2](/misc/step_2.png)
11
+
12
+ - Add mail merge fields
13
+
14
+ - Click the `Insert` tab on the ribbon
15
+
16
+ ![Step 3.1](/misc/step_3_1.png)
17
+
18
+ - Click the `Quick Parts` dropdown and select `Field...`
19
+
20
+ ![Step 3.2](/misc/step_3_2.png)
21
+
22
+ - On the dialog, scroll down and select `MergeField`
23
+
24
+ ![Step 3.3a](/misc/step_3_3_a.png)
25
+
26
+ - Select `Field Codes`
27
+
28
+ ![Step 3.3b](/misc/step_3_3_b.png)
29
+
30
+ ![Step 4](/misc/step_4.png)
31
+
32
+ - In the `Field codes` input box, enter your variable in front of the `MERGEFIELD`. Notice the space between the `MERGEFIELD` and the variable
33
+
34
+ ![Step 5](/misc/step_5.png)
35
+
36
+ - You should then have something like this:
37
+
38
+ ![Step 6](/misc/step_6.png)
39
+
40
+ - A complete template might look like this:
41
+
42
+ ![Step 7](/misc/step_7.png)
43
+
44
+ NOTE: When adding variables, those that display a value are preceded with an equals sign `=`. Those that just perform logics, such as loops and conditionals, do not need a preceding equals sign.
data/misc/step_1.png ADDED
Binary file
data/misc/step_2.png ADDED
Binary file
data/misc/step_3_1.png ADDED
Binary file
data/misc/step_3_2.png ADDED
Binary file
Binary file
Binary file
data/misc/step_4.png ADDED
Binary file
data/misc/step_5.png ADDED
Binary file
data/misc/step_6.png ADDED
Binary file
data/misc/step_7.png ADDED
Binary file
@@ -0,0 +1,35 @@
1
+ <w:p w14:paraId="2A8BFD66" w14:textId="77777777" w:rsidR="006F0A69" w:rsidRDefault="00E40CBA" w:rsidP="00670731">
2
+ <w:r>
3
+ <w:fldChar w:fldCharType="begin"/>
4
+ </w:r>
5
+ <w:r>
6
+ <w:instrText xml:space="preserve"> AUTOTEXT Header:Date \* MERGEFORMAT </w:instrText>
7
+ </w:r>
8
+ <w:r>
9
+ <w:fldChar w:fldCharType="separate"/>
10
+ </w:r>
11
+ <w:r w:rsidR="006F0A69" w:rsidRPr="009A09E3">
12
+ <w:t>Day Month Year</w:t>
13
+ </w:r>
14
+ </w:p>
15
+
16
+ <w:p w14:paraId="71B65E52" w14:textId="613138CB" w:rsidR="001D1AF8" w:rsidRDefault="00E40CBA" w:rsidP="006C34C3">
17
+ <w:pPr>
18
+ <w:pStyle w:val="Address"/>
19
+ </w:pPr>
20
+ <w:r>
21
+ <w:fldChar w:fldCharType="end"/>
22
+ </w:r>
23
+ <w:bookmarkEnd w:id="0"/>
24
+ </w:p>
25
+
26
+ <w:p w14:paraId="7C3EB778" w14:textId="78AB4714" w:rsidR="001D1AF8" w:rsidRPr="000C6261" w:rsidRDefault="00A35B65" w:rsidP="001D1AF8">
27
+ <w:fldSimple w:instr=" MERGEFIELD =current_time \* MERGEFORMAT ">
28
+ <w:r>
29
+ <w:rPr>
30
+ <w:noProof/>
31
+ </w:rPr>
32
+ <w:t>«=current_time»</w:t>
33
+ </w:r>
34
+ </w:fldSimple>
35
+ </w:p>
@@ -384,6 +384,48 @@ class ProcessorDocumentTest < Sablon::TestCase
384
384
  assert_equal "ParagraphBefore Before Content After ParagraphAfter", text(with_true)
385
385
  end
386
386
 
387
+ def test_ignore_complex_field_spanning_multiple_paragraphs
388
+ result = process(snippet("test_ignore_complex_field_spanning_multiple_paragraphs"),
389
+ {"current_time" => '14:53'})
390
+
391
+ assert_equal "AUTOTEXT Header:Date \\* MERGEFORMAT Day Month Year 14:53", text(result)
392
+ assert_xml_equal <<-document, result
393
+ <w:p w14:paraId="2A8BFD66" w14:textId="77777777" w:rsidR="006F0A69" w:rsidRDefault="00E40CBA" w:rsidP="00670731">
394
+ <w:r>
395
+ <w:fldChar w:fldCharType="begin"/>
396
+ </w:r>
397
+ <w:r>
398
+ <w:instrText xml:space="preserve"> AUTOTEXT Header:Date \\* MERGEFORMAT </w:instrText>
399
+ </w:r>
400
+ <w:r>
401
+ <w:fldChar w:fldCharType="separate"/>
402
+ </w:r>
403
+ <w:r w:rsidR="006F0A69" w:rsidRPr="009A09E3">
404
+ <w:t>Day Month Year</w:t>
405
+ </w:r>
406
+ </w:p>
407
+
408
+ <w:p w14:paraId="71B65E52" w14:textId="613138CB" w:rsidR="001D1AF8" w:rsidRDefault="00E40CBA" w:rsidP="006C34C3">
409
+ <w:pPr>
410
+ <w:pStyle w:val="Address"/>
411
+ </w:pPr>
412
+ <w:r>
413
+ <w:fldChar w:fldCharType="end"/>
414
+ </w:r>
415
+ <w:bookmarkEnd w:id="0"/>
416
+ </w:p>
417
+
418
+ <w:p w14:paraId="7C3EB778" w14:textId="78AB4714" w:rsidR="001D1AF8" w:rsidRPr="000C6261" w:rsidRDefault="00A35B65" w:rsidP="001D1AF8">
419
+ <w:r>
420
+ <w:rPr>
421
+ <w:noProof/>
422
+ </w:rPr>
423
+ <w:t>14:53</w:t>
424
+ </w:r>
425
+ </w:p>
426
+ document
427
+ end
428
+
387
429
  def test_conditional_with_predicate
388
430
  result = process(snippet("conditional_with_predicate"), {"body" => ""})
389
431
  assert_equal "some content", text(result)
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.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yves Senn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-03 00:00:00.000000000 Z
11
+ date: 2017-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -128,10 +128,21 @@ files:
128
128
  - lib/sablon/test.rb
129
129
  - lib/sablon/test/assertions.rb
130
130
  - lib/sablon/version.rb
131
+ - misc/TEMPLATE.md
131
132
  - misc/cv_sample.png
132
133
  - misc/cv_template.png
133
134
  - misc/recipe_sample.png
134
135
  - misc/recipe_template.png
136
+ - misc/step_1.png
137
+ - misc/step_2.png
138
+ - misc/step_3_1.png
139
+ - misc/step_3_2.png
140
+ - misc/step_3_3_a.png
141
+ - misc/step_3_3_b.png
142
+ - misc/step_4.png
143
+ - misc/step_5.png
144
+ - misc/step_6.png
145
+ - misc/step_7.png
135
146
  - sablon.gemspec
136
147
  - test/content_test.rb
137
148
  - test/context_test.rb
@@ -165,6 +176,7 @@ files:
165
176
  - test/fixtures/xml/simple_fields.xml
166
177
  - test/fixtures/xml/table_multi_row_loop.xml
167
178
  - test/fixtures/xml/table_row_loop.xml
179
+ - test/fixtures/xml/test_ignore_complex_field_spanning_multiple_paragraphs.xml
168
180
  - test/html/converter_test.rb
169
181
  - test/html_test.rb
170
182
  - test/mail_merge_parser_test.rb
@@ -195,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
207
  version: '0'
196
208
  requirements: []
197
209
  rubyforge_project:
198
- rubygems_version: 2.5.1
210
+ rubygems_version: 2.6.11
199
211
  signing_key:
200
212
  specification_version: 4
201
213
  summary: docx tempalte processor
@@ -232,6 +244,7 @@ test_files:
232
244
  - test/fixtures/xml/simple_fields.xml
233
245
  - test/fixtures/xml/table_multi_row_loop.xml
234
246
  - test/fixtures/xml/table_row_loop.xml
247
+ - test/fixtures/xml/test_ignore_complex_field_spanning_multiple_paragraphs.xml
235
248
  - test/html/converter_test.rb
236
249
  - test/html_test.rb
237
250
  - test/mail_merge_parser_test.rb