txbr 2.5.1 → 2.5.2

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
  SHA256:
3
- metadata.gz: 76cd2b1c7f112ffc17ecc1c94b5554a6f317e30052aabb0a8e5c6166cc85c329
4
- data.tar.gz: be7802bd15965b7123abb22bf3e27fbccfe62660eaac9738c55a8e35cfd24f9e
3
+ metadata.gz: af6782638d9d86f0593f7d1bd4066684dcb447f805e5c324fa1471e8f28bc3bc
4
+ data.tar.gz: 565be3c3aba1c78725433ab38d54bfb6930bd05afb40e385157e14a4233d1855
5
5
  SHA512:
6
- metadata.gz: eb9e39e6d90512286d9f48f83b70cda2bfdcfeebbf4021c970e171a00ca20a7afdd32729c5470c650b31f3fe15b61634f65b162d85a60cab74beaf46ef13657c
7
- data.tar.gz: 5d97695feea4607cf5746af8ea7f3cb30bd60d3e385104d3ea2d32b8aa67c17271c9af79d35631bc05e52818eb6375979bb581ac256de1772ac50c9c82dbf170
6
+ metadata.gz: 2945218cdb7970b015336e857d4cd766ffdbc9bc25459c27bd2c69fc630c3df00368c24c2584bd762f9e50535b4e479738492d5876e42b7c272dc96db4285a52
7
+ data.tar.gz: 6a1cb78704a76414ce698a637e9f80e65577c4d85baa024ea49f22bcea71b15203f048931c91c110c2b7f7253483a57b715e5fd294dd7a64281348f5bf43478d
@@ -69,10 +69,24 @@ module Txbr
69
69
  # Otherwise, transform the var into something Liquid-friendly so it
70
70
  # doesn't jam up the parser.
71
71
  def prerender(source, variables)
72
- source.gsub(/\{\{\s*(?:[\w\-\.\[\]]+\.)?\$\{\s*[\w\-\.\[\]]+\s*\}\s*\}\s*\}/) do |orig|
73
- orig = orig[2..-3] # remove curlies
74
- next variables[orig] if variables.include?(orig)
75
- "{{#{normalize_braze_var(orig)}}}"
72
+ source.gsub(/\{\s*\{\s*(?:[\w\-\_\.\[\]]+\.)?\$\{\s*[\w\-\.\[\]]+\s*\}?\s*\}?\s*\}?/) do |orig|
73
+ plain = orig.sub(/\A\{\{/, '').sub(/\}\}\z/, '')
74
+
75
+ result = if val = variables[plain]
76
+ "\"#{val}\""
77
+ else
78
+ normalize_braze_var(orig)
79
+ end
80
+
81
+ if orig.tr(' ', '').start_with?('{{')
82
+ result = "{{#{result}"
83
+ end
84
+
85
+ if orig.tr(' ', '').end_with?('}}')
86
+ result << '}}'
87
+ end
88
+
89
+ result
76
90
  end
77
91
  end
78
92
 
@@ -1,3 +1,3 @@
1
1
  module Txbr
2
- VERSION = '2.5.1'
2
+ VERSION = '2.5.2'
3
3
  end
@@ -9,6 +9,7 @@ describe Txbr::Template do
9
9
  <<~SRC
10
10
  <h1>Braze campaign is {{campaign.${api_id}}}</h1>
11
11
  <h2>Hello, {{${first_name}}}</h2>
12
+ <h3>I speak {{custom_attributes.${preferred_language} | default: 'en'}}</h3>
12
13
  SRC
13
14
  end
14
15
 
@@ -24,13 +25,18 @@ describe Txbr::Template do
24
25
  expect(subject.render).to eq(<<~TEXT)
25
26
  <h1>Braze campaign is abc123</h1>
26
27
  <h2>Hello, Dwight</h2>
28
+ <h3>I speak en</h3>
27
29
  TEXT
28
30
  end
29
31
  end
30
32
 
31
33
  context 'with no variable replacements' do
32
34
  it 'renders without erroring' do
33
- expect { subject.render }.to_not raise_error
35
+ expect(subject.render).to eq(<<~TEXT)
36
+ <h1>Braze campaign is </h1>
37
+ <h2>Hello, </h2>
38
+ <h3>I speak en</h3>
39
+ TEXT
34
40
  end
35
41
  end
36
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: txbr
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-25 00:00:00.000000000 Z
11
+ date: 2019-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abroad