sablon 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -3
- data/lib/sablon/parser/mail_merge.rb +10 -1
- data/lib/sablon/version.rb +1 -1
- data/test/mail_merge_parser_test.rb +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c89f16491fe648434fab084af48d3d0892cfe60
|
4
|
+
data.tar.gz: 3676259e88c5f7a1b9daa6e1deddc1f01d5f2d43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e16c0f9ff697f9ec35a724c5787c9e68070dd7be4b30f290cd14d8a3952d072c4b173acbe2a6f03c82933d5ef230c18d47cfe777e383477bab489992fe431ee8
|
7
|
+
data.tar.gz: d9b4409319a19998fc719d00319676ba1cd5e409d04e42471d7b20704ef4597f848d63a59f09249bd893a17fff52b02d0f21d3b5f52e2dde753b95f1c9638e6a
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sablon (0.0.
|
4
|
+
sablon (0.0.15)
|
5
5
|
nokogiri (>= 1.6.0)
|
6
6
|
redcarpet (>= 3.2)
|
7
7
|
rubyzip (>= 1.1)
|
@@ -10,11 +10,11 @@ GEM
|
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
12
|
mini_portile (0.6.2)
|
13
|
-
minitest (5.
|
13
|
+
minitest (5.7.0)
|
14
14
|
nokogiri (1.6.6.2)
|
15
15
|
mini_portile (~> 0.6.0)
|
16
16
|
rake (10.4.2)
|
17
|
-
redcarpet (3.
|
17
|
+
redcarpet (3.3.2)
|
18
18
|
rubyzip (1.1.7)
|
19
19
|
xml-simple (1.1.5)
|
20
20
|
|
@@ -27,3 +27,6 @@ DEPENDENCIES
|
|
27
27
|
rake (~> 10.0)
|
28
28
|
sablon!
|
29
29
|
xml-simple
|
30
|
+
|
31
|
+
BUNDLED WITH
|
32
|
+
1.10.6
|
@@ -3,6 +3,11 @@ module Sablon
|
|
3
3
|
class MailMerge
|
4
4
|
class MergeField
|
5
5
|
KEY_PATTERN = /^\s*MERGEFIELD\s+([^ ]+)\s+\\\*\s+MERGEFORMAT\s*$/
|
6
|
+
|
7
|
+
def valid?
|
8
|
+
expression
|
9
|
+
end
|
10
|
+
|
6
11
|
def expression
|
7
12
|
$1 if @raw_expression =~ KEY_PATTERN
|
8
13
|
end
|
@@ -22,6 +27,10 @@ module Sablon
|
|
22
27
|
@raw_expression = @nodes.flat_map {|n| n.search(".//w:instrText").map(&:content) }.join
|
23
28
|
end
|
24
29
|
|
30
|
+
def valid?
|
31
|
+
separate_node && expression
|
32
|
+
end
|
33
|
+
|
25
34
|
def replace(content)
|
26
35
|
replace_field_display(pattern_node, content)
|
27
36
|
(@nodes - [pattern_node]).each(&:remove)
|
@@ -65,7 +74,7 @@ module Sablon
|
|
65
74
|
elsif node.name == "fldChar" && node["w:fldCharType"] == "begin"
|
66
75
|
field = build_complex_field(node)
|
67
76
|
end
|
68
|
-
fields << field if field && field.
|
77
|
+
fields << field if field && field.valid?
|
69
78
|
end
|
70
79
|
fields
|
71
80
|
end
|
data/lib/sablon/version.rb
CHANGED
@@ -119,6 +119,33 @@ xml
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
+
class InvalidFldCharTest < Sablon::TestCase
|
123
|
+
include SharedBehavior
|
124
|
+
|
125
|
+
def test_is_ignored
|
126
|
+
assert_equal [], fields.map(&:class)
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
def xml
|
131
|
+
xml = <<-xml.strip
|
132
|
+
<w:p><w:r w:rsidR="00BE47B1" w:rsidRPr="00BE47B1">
|
133
|
+
<w:rPr><w:b/></w:rPr>
|
134
|
+
<w:fldChar w:fldCharType="begin"/>
|
135
|
+
</w:r>
|
136
|
+
<w:r w:rsidR="00BE47B1" w:rsidRPr="00BE47B1">
|
137
|
+
<w:rPr><w:b/></w:rPr>
|
138
|
+
<w:instrText xml:space="preserve"> MERGEFIELD =last_name \\* MERGEFORMAT </w:instrText>
|
139
|
+
</w:r>
|
140
|
+
<w:r w:rsidR="00BE47B1" w:rsidRPr="00BE47B1">
|
141
|
+
<w:rPr><w:b/></w:rPr>
|
142
|
+
<w:fldChar w:fldCharType="end"/>
|
143
|
+
</w:r></w:p>
|
144
|
+
xml
|
145
|
+
wrap(xml)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
122
149
|
class NonSablonFieldTest < Sablon::TestCase
|
123
150
|
include SharedBehavior
|
124
151
|
|
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.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yves Senn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|