courrier 0.8.2 → 0.9.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +33 -0
- data/lib/courrier/email/provider.rb +14 -4
- data/lib/courrier/email.rb +21 -1
- data/lib/courrier/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8a3d93b4337d15e066ffa7ed4626dd254231ee744940de07b7b76be8714afbde
|
|
4
|
+
data.tar.gz: d7ef7a3ed1a8600581b6bdf13f63072c49ad138ad52384e1c358dbcd8f8a45b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32d2fba728012eb703ca67044484a2f0caf0177ee0f341b6973566a50136f6531dfc37edfe7347511b4de67291af0364f6f03ad4c22247f5bbd72ca306e13455
|
|
7
|
+
data.tar.gz: 5a3ea2ea5fb0637f025a3577d6e1004a66478e0929b96752b0fdea302af95f6c88af3bed801265dc14f6645a8014adb781cd1cc04ee1809bedf76ca892f4c4f0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -256,6 +256,39 @@ end
|
|
|
256
256
|
```
|
|
257
257
|
|
|
258
258
|
|
|
259
|
+
### Template files
|
|
260
|
+
|
|
261
|
+
Instead of defining `text` and `html` methods, you can create ERB template files:
|
|
262
|
+
```ruby
|
|
263
|
+
class OrderEmail < Courrier::Email
|
|
264
|
+
def subject = "Your order is ready!"
|
|
265
|
+
# text and html content will be loaded from template files
|
|
266
|
+
end
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Create template files alongside your email class:
|
|
270
|
+
- `app/emails/order_email.text.erb`
|
|
271
|
+
- `app/emails/order_email.html.erb`
|
|
272
|
+
|
|
273
|
+
Templates have access to all context options and instance variables:
|
|
274
|
+
```erb
|
|
275
|
+
<!-- app/emails/order_email.html.erb -->
|
|
276
|
+
<h1>Hello <%= name %>!</h1>
|
|
277
|
+
<p>Your order #<%= order_id %> is ready for pickup.</p>
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Method definitions take precedence over template files when both exist. You can mix approaches. For example, define text in a method and use a template for the html:
|
|
281
|
+
```ruby
|
|
282
|
+
class OrderEmail < Courrier::Email
|
|
283
|
+
def subject = "Your order is ready!"
|
|
284
|
+
|
|
285
|
+
def text = "Hello #{name}! Your order ##{order_id} is ready."
|
|
286
|
+
|
|
287
|
+
# html will be loaded from app/emails/order_email.html.erb
|
|
288
|
+
end
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
|
|
259
292
|
### Auto-generate text from HTML
|
|
260
293
|
|
|
261
294
|
Automatically generate plain text versions from your HTML emails:
|
|
@@ -40,8 +40,8 @@ module Courrier
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def deliver
|
|
43
|
-
raise Courrier::ConfigurationError, "
|
|
44
|
-
raise Courrier::ConfigurationError, "
|
|
43
|
+
raise Courrier::ConfigurationError, "Unknown provider. Choose one of `#{comma_separated_providers}` or provide your own." if provider_invalid?
|
|
44
|
+
raise Courrier::ConfigurationError, "API key must be configured for #{@provider} provider in production environment" if configuration_missing_in_production?
|
|
45
45
|
|
|
46
46
|
provider_class.new(
|
|
47
47
|
api_key: @api_key,
|
|
@@ -53,8 +53,12 @@ module Courrier
|
|
|
53
53
|
|
|
54
54
|
private
|
|
55
55
|
|
|
56
|
+
def provider_invalid?
|
|
57
|
+
@provider.nil? || @provider.to_s.strip.empty?
|
|
58
|
+
end
|
|
59
|
+
|
|
56
60
|
def configuration_missing_in_production?
|
|
57
|
-
production? &&
|
|
61
|
+
production? && api_key_required_providers? && api_key_blank?
|
|
58
62
|
end
|
|
59
63
|
|
|
60
64
|
def comma_separated_providers = PROVIDERS.keys.join(", ")
|
|
@@ -65,7 +69,13 @@ module Courrier
|
|
|
65
69
|
Object.const_get(@provider)
|
|
66
70
|
end
|
|
67
71
|
|
|
68
|
-
def
|
|
72
|
+
def api_key_required_providers?
|
|
73
|
+
!%w[logger inbox].include?(@provider.to_s)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def api_key_blank?
|
|
77
|
+
@api_key.nil? || @api_key.to_s.strip.empty?
|
|
78
|
+
end
|
|
69
79
|
|
|
70
80
|
def production?
|
|
71
81
|
defined?(Rails) && Rails.env.production?
|
data/lib/courrier/email.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "erb"
|
|
4
|
+
|
|
3
5
|
require "courrier/email/address"
|
|
4
6
|
require "courrier/jobs/email_delivery_job" if defined?(Rails)
|
|
5
7
|
require "courrier/email/layouts"
|
|
@@ -133,7 +135,25 @@ module Courrier
|
|
|
133
135
|
ENV["COURRIER_EMAIL_DISABLED"] == "true" || ENV["COURRIER_EMAIL_ENABLED"] == "false"
|
|
134
136
|
end
|
|
135
137
|
|
|
136
|
-
def method_missing(name, *)
|
|
138
|
+
def method_missing(name, *)
|
|
139
|
+
if name == :text || name == :html
|
|
140
|
+
render_template(name.to_s)
|
|
141
|
+
else
|
|
142
|
+
@context_options[name]
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def render_template(format)
|
|
147
|
+
template_path = template_file_path(format)
|
|
148
|
+
|
|
149
|
+
File.exist?(template_path) ? ERB.new(File.read(template_path)).result(binding) : nil
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def template_file_path(format)
|
|
153
|
+
class_path = self.class.name.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
|
|
154
|
+
|
|
155
|
+
File.join(Courrier.configuration&.email_path, "#{class_path}.#{format}.erb")
|
|
156
|
+
end
|
|
137
157
|
|
|
138
158
|
def respond_to_missing?(name, include_private = false) = true
|
|
139
159
|
end
|
data/lib/courrier/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: courrier
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rails Designer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-02-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: launchy
|