txbr 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/txbr/template.rb +6 -5
- data/lib/txbr/version.rb +1 -1
- data/spec/template_spec.rb +11 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76cd2b1c7f112ffc17ecc1c94b5554a6f317e30052aabb0a8e5c6166cc85c329
|
4
|
+
data.tar.gz: be7802bd15965b7123abb22bf3e27fbccfe62660eaac9738c55a8e35cfd24f9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb9e39e6d90512286d9f48f83b70cda2bfdcfeebbf4021c970e171a00ca20a7afdd32729c5470c650b31f3fe15b61634f65b162d85a60cab74beaf46ef13657c
|
7
|
+
data.tar.gz: 5d97695feea4607cf5746af8ea7f3cb30bd60d3e385104d3ea2d32b8aa67c17271c9af79d35631bc05e52818eb6375979bb581ac256de1772ac50c9c82dbf170
|
data/lib/txbr/template.rb
CHANGED
@@ -63,12 +63,13 @@ module Txbr
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
# Designed to replace special Braze variables like {{campaign.${api_id}}}
|
67
|
-
# which Liquid can't natively handle. If the variable
|
68
|
-
# variables hash, replace it with the value directly.
|
69
|
-
# the var into something Liquid-friendly so it
|
66
|
+
# Designed to replace special Braze variables like {{campaign.${api_id}}}
|
67
|
+
# and ${first_name}, which Liquid can't natively handle. If the variable
|
68
|
+
# exists in the given variables hash, replace it with the value directly.
|
69
|
+
# Otherwise, transform the var into something Liquid-friendly so it
|
70
|
+
# doesn't jam up the parser.
|
70
71
|
def prerender(source, variables)
|
71
|
-
source.gsub(/\{\{[\w\-\.\[\]]
|
72
|
+
source.gsub(/\{\{\s*(?:[\w\-\.\[\]]+\.)?\$\{\s*[\w\-\.\[\]]+\s*\}\s*\}\s*\}/) do |orig|
|
72
73
|
orig = orig[2..-3] # remove curlies
|
73
74
|
next variables[orig] if variables.include?(orig)
|
74
75
|
"{{#{normalize_braze_var(orig)}}}"
|
data/lib/txbr/version.rb
CHANGED
data/spec/template_spec.rb
CHANGED
@@ -8,14 +8,23 @@ describe Txbr::Template do
|
|
8
8
|
let(:source) do
|
9
9
|
<<~SRC
|
10
10
|
<h1>Braze campaign is {{campaign.${api_id}}}</h1>
|
11
|
+
<h2>Hello, {{${first_name}}}</h2>
|
11
12
|
SRC
|
12
13
|
end
|
13
14
|
|
14
15
|
context 'with a direct variable replacement' do
|
15
|
-
let(:prerender_variables)
|
16
|
+
let(:prerender_variables) do
|
17
|
+
{
|
18
|
+
'campaign.${api_id}' => 'abc123',
|
19
|
+
'${first_name}' => 'Dwight'
|
20
|
+
}
|
21
|
+
end
|
16
22
|
|
17
23
|
it 'prerenders correctly' do
|
18
|
-
expect(subject.render
|
24
|
+
expect(subject.render).to eq(<<~TEXT)
|
25
|
+
<h1>Braze campaign is abc123</h1>
|
26
|
+
<h2>Hello, Dwight</h2>
|
27
|
+
TEXT
|
19
28
|
end
|
20
29
|
end
|
21
30
|
|