txbr 2.5.0 → 2.6.1.beta1

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
  SHA256:
3
- metadata.gz: 159bfa45f2d0f53ef30fe11e2bd6dfbf1b07b0ea0e19530ca3ac3d171308c4ac
4
- data.tar.gz: 15621955923af3e6aa17933faf75eb344e5be7a8bd34fe52ea526d1f88a01be3
3
+ metadata.gz: 97f7a283041d7fe496fe0eda6976ed22fe5a60a60b56eee4b3b07b62eb8b3753
4
+ data.tar.gz: 7440313a8d353ab7e4d9ae22c5dc5de59c5000d3dc33efdd3bd82eb5f55a7203
5
5
  SHA512:
6
- metadata.gz: 7247f257169835737f3d834d8afc0cba5930314e439a3629acfa526b4f3d7197eece08194c3f85a848a17932a3aea22540a9386a79699d286f860c140cd8f9c7
7
- data.tar.gz: 9416bc14041f5b8b261ecad1de0e8aa7ccaf61d3ddc11297cc6d3aa907cf14c029ae9c3e37b45d53325ed8c2bc6e87af44b580189fae59aa5f2cfb3dbddb70fc
6
+ metadata.gz: 7732388b13d226baaf99fa8f57a3cba3f5b5ce36b4a267bb3fc2aea94b27b072b2628e43298f7f67beadc70c2036e1647bb3a8b8db8e7c4e76da5bb8022a81fc
7
+ data.tar.gz: e83c060b3286af19562a6c19e321aa6c8afd7b11578b3cd1537952b7eba7792228f200e31a84882834098463e79d3681e64fa82f1d164de38b9c9a4062e2621c
@@ -15,7 +15,7 @@ module Txbr
15
15
  page = 0
16
16
 
17
17
  loop do
18
- campaigns = braze_api.get_json(CAMPAIGN_LIST_PATH, page: page)
18
+ campaigns = braze_api.get_json(CAMPAIGN_LIST_PATH, page: page, include_archived: false)
19
19
  campaigns['campaigns'].each(&block)
20
20
  break if campaigns['campaigns'].size < CAMPAIGN_BATCH_SIZE
21
21
  page += 1
data/lib/txbr/template.rb CHANGED
@@ -63,15 +63,30 @@ 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 exists in the given
68
- # variables hash, replace it with the value directly. Otherwise, transform
69
- # the var into something Liquid-friendly so it doesn't jam up the parser.
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\-\.\[\]]+\.\$\{[\w\-\.\[\]]+\}\}\}/) do |orig|
72
- orig = orig[2..-3] # remove curlies
73
- next variables[orig] if variables.include?(orig)
74
- "{{#{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
75
90
  end
76
91
  end
77
92
 
data/lib/txbr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Txbr
2
- VERSION = '2.5.0'
2
+ VERSION = '2.6.1.beta1'
3
3
  end
@@ -20,13 +20,13 @@ describe Txbr::CampaignsApi do
20
20
 
21
21
  let(:interactions) do
22
22
  [{
23
- request: { verb: 'get', url: described_class::CAMPAIGN_LIST_PATH, params: { page: 0 } },
23
+ request: { verb: 'get', url: described_class::CAMPAIGN_LIST_PATH, params: { page: 0, include_archived: false } },
24
24
  response: { status: 200, body: { campaigns: [{ id: '123abc' }] }.to_json }
25
25
  }, {
26
- request: { verb: 'get', url: described_class::CAMPAIGN_LIST_PATH, params: { page: 1 } },
26
+ request: { verb: 'get', url: described_class::CAMPAIGN_LIST_PATH, params: { page: 1, include_archived: false } },
27
27
  response: { status: 200, body: { campaigns: [{ id: '456def' }] }.to_json }
28
28
  }, {
29
- request: { verb: 'get', url: described_class::CAMPAIGN_LIST_PATH, params: { page: 2 } },
29
+ request: { verb: 'get', url: described_class::CAMPAIGN_LIST_PATH, params: { page: 2, include_archived: false } },
30
30
  response: { status: 200, body: { campaigns: [] }.to_json }
31
31
  }]
32
32
  end
@@ -8,20 +8,39 @@ 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>
12
+ <h3>I speak {{custom_attributes.${preferred_language} | default: 'en'}}</h3>
13
+ <h3>{{'foo bar ' | append: custom_attributes.${foobar}}}</h3>
11
14
  SRC
12
15
  end
13
16
 
14
17
  context 'with a direct variable replacement' do
15
- let(:prerender_variables) { { 'campaign.${api_id}' => 'abc123' } }
18
+ let(:prerender_variables) do
19
+ {
20
+ 'campaign.${api_id}' => 'abc123',
21
+ '${first_name}' => 'Dwight',
22
+ 'custom_attributes.${foobar}' => 'baz'
23
+ }
24
+ end
16
25
 
17
26
  it 'prerenders correctly' do
18
- expect(subject.render.strip).to eq("<h1>Braze campaign is abc123</h1>")
27
+ expect(subject.render).to eq(<<~TEXT)
28
+ <h1>Braze campaign is abc123</h1>
29
+ <h2>Hello, Dwight</h2>
30
+ <h3>I speak en</h3>
31
+ <h3>foo bar baz</h3>
32
+ TEXT
19
33
  end
20
34
  end
21
35
 
22
36
  context 'with no variable replacements' do
23
37
  it 'renders without erroring' do
24
- expect { subject.render }.to_not raise_error
38
+ expect(subject.render).to eq(<<~TEXT)
39
+ <h1>Braze campaign is </h1>
40
+ <h2>Hello, </h2>
41
+ <h3>I speak en</h3>
42
+ <h3>foo bar </h3>
43
+ TEXT
25
44
  end
26
45
  end
27
46
  end
data/txbr.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency 'liquid', '~> 4.0'
20
20
  s.add_dependency 'sinatra', '~> 1.4'
21
21
  s.add_dependency 'sinatra-contrib', '~> 1.4'
22
- s.add_dependency 'txgh', '~> 6.6'
22
+ s.add_dependency 'txgh', '~> 7.0'
23
23
 
24
24
  s.require_path = 'lib'
25
25
  s.files = Dir['{lib,spec}/**/*', 'README.md', 'txbr.gemspec', 'LICENSE']
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.0
4
+ version: 2.6.1.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-25 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abroad
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '6.6'
103
+ version: '7.0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '6.6'
110
+ version: '7.0'
111
111
  description: A library for syncing translation resources between Braze and Transifex.
112
112
  email:
113
113
  - camertron@gmail.com
@@ -162,7 +162,7 @@ files:
162
162
  homepage: https://github.com/lumoslabs/txbr
163
163
  licenses: []
164
164
  metadata: {}
165
- post_install_message:
165
+ post_install_message:
166
166
  rdoc_options: []
167
167
  require_paths:
168
168
  - lib
@@ -173,13 +173,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  requirements:
176
- - - ">="
176
+ - - ">"
177
177
  - !ruby/object:Gem::Version
178
- version: '0'
178
+ version: 1.3.1
179
179
  requirements: []
180
- rubyforge_project:
181
- rubygems_version: 2.7.6.2
182
- signing_key:
180
+ rubygems_version: 3.2.7
181
+ signing_key:
183
182
  specification_version: 4
184
183
  summary: A library for syncing translation resources between Braze and Transifex.
185
184
  test_files: []