idlemailer 2.0.0 → 2.1.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 +5 -5
- data/README.md +7 -2
- data/lib/idlemailer/config.rb +1 -1
- data/lib/idlemailer/mailer.rb +3 -0
- data/lib/idlemailer/template_manager.rb +17 -7
- data/lib/idlemailer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad91007cd0d5f336f443b3107e150dc865e52cd7048642a388e9d3b476fd180c
|
4
|
+
data.tar.gz: 822bbb3f19ffb0878d568574672fca4a6ad531c9b73f51935ce1ecae9ff77a7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc64bf86b25a4fc15d99d9d3a38b99c48a759816ed73e90182169236de159e003a2e44b473c09d079ad4f06eb0ba5fcf2b3c980c3cb7630585a3c7139c7a2f14
|
7
|
+
data.tar.gz: 2291ccedc03e3d310c59eda8e98d153560221ef22d71e47898942e7b9d3adef053c5a235a41f3a58eb26ef2b0fbcc01b4665f2df2887b111db3b2a807c2fd4b1
|
data/README.md
CHANGED
@@ -21,6 +21,8 @@ class WidgetMailer
|
|
21
21
|
@widget = widget
|
22
22
|
mail.to = user.email
|
23
23
|
mail.subject = "Widget #{widget.sku}"
|
24
|
+
# 'mail' is just a Mail object from the mail gem, so you can use the
|
25
|
+
# full Mail api here, e.g. to, subject, attachments, etc.
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -33,12 +35,15 @@ WidgetMailer.new(current_user, widget).deliver
|
|
33
35
|
|
34
36
|
### Inline templates
|
35
37
|
|
36
|
-
|
38
|
+
If you prefer, you can embed your ERB templates right inside your Ruby class, instead of making separate template files. Slick amiright?
|
37
39
|
|
38
40
|
```ruby
|
39
41
|
class WidgetMailer
|
40
42
|
include IdleMailer::Mailer
|
41
43
|
|
44
|
+
# optionally override the default layout
|
45
|
+
self.layout = "widget_layout"
|
46
|
+
|
42
47
|
def initialize(user, widget)
|
43
48
|
@widget = widget
|
44
49
|
mail.to = user.email
|
@@ -71,7 +76,7 @@ IdleMailer.config do |config|
|
|
71
76
|
# Pre-cache all templates and layouts (instead of re-loading them on each delivery)
|
72
77
|
config.cache_templates = true
|
73
78
|
|
74
|
-
# Name of the layout template. Here, the file(s) would be named
|
79
|
+
# Name of the default layout template. Here, the file(s) would be named
|
75
80
|
# mailer_layout.html.erb and/or mailer_layout.text.erb.
|
76
81
|
config.layout = 'mailer_layout'
|
77
82
|
|
data/lib/idlemailer/config.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module IdleMailer
|
2
2
|
# Struct for holding IdleMailer config
|
3
3
|
# templates A Pathname object pointing to the mail templates directory (defaults to ./templates)
|
4
|
-
# layout Name of layout file, minus extention (defaults to mailer_layout)
|
4
|
+
# layout Name of default layout file, minus extention (defaults to mailer_layout)
|
5
5
|
# delivery_method Symbol like :smtp or :test (see the mail gem for all options)
|
6
6
|
# delivery_options Hash of delivery options (see the mail gem for all options)
|
7
7
|
# default_from Default "from" address if it's left blank
|
data/lib/idlemailer/mailer.rb
CHANGED
@@ -6,7 +6,7 @@ module IdleMailer
|
|
6
6
|
class << self
|
7
7
|
attr_reader :layouts, :templates
|
8
8
|
end
|
9
|
-
@layouts, @templates = {}, {}
|
9
|
+
@custom_layout, @layouts, @templates = nil, {}, {}
|
10
10
|
end
|
11
11
|
klass.cache_templates! if IdleMailer.config.cache_templates
|
12
12
|
end
|
@@ -24,7 +24,13 @@ module IdleMailer
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def layout(type)
|
27
|
-
layouts[type] || ERB.new(template_path(
|
27
|
+
layouts[type] || ERB.new(template_path(layout_name, type).read.chomp)
|
28
|
+
end
|
29
|
+
|
30
|
+
def layout=(new_name)
|
31
|
+
@custom_layout = new_name
|
32
|
+
layouts.clear
|
33
|
+
cache_templates! if IdleMailer.config.cache_templates
|
28
34
|
end
|
29
35
|
|
30
36
|
def has_template?(type)
|
@@ -32,7 +38,7 @@ module IdleMailer
|
|
32
38
|
end
|
33
39
|
|
34
40
|
def has_layout?(type)
|
35
|
-
layouts.has_key?(type) || template_path(
|
41
|
+
layouts.has_key?(type) || template_path(layout_name, type).exist?
|
36
42
|
end
|
37
43
|
|
38
44
|
def template_name
|
@@ -43,15 +49,19 @@ module IdleMailer
|
|
43
49
|
downcase
|
44
50
|
end
|
45
51
|
|
52
|
+
def layout_name
|
53
|
+
@custom_layout || IdleMailer.config.layout
|
54
|
+
end
|
55
|
+
|
46
56
|
def template_path(name, type)
|
47
57
|
IdleMailer.config.templates.join("#{name}.#{type}.erb")
|
48
58
|
end
|
49
59
|
|
50
60
|
def cache_templates!
|
51
|
-
layouts['text']
|
52
|
-
layouts['html']
|
53
|
-
templates['text']
|
54
|
-
templates['html']
|
61
|
+
layouts['text'] ||= layout 'text' if has_layout? 'text'
|
62
|
+
layouts['html'] ||= layout 'html' if has_layout? 'html'
|
63
|
+
templates['text'] ||= template 'text' if has_template? 'text'
|
64
|
+
templates['html'] ||= template 'html' if has_template? 'html'
|
55
65
|
end
|
56
66
|
end
|
57
67
|
end
|
data/lib/idlemailer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idlemailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
version: '0'
|
61
61
|
requirements: []
|
62
62
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.7.6
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: A lightweight alternative to ActionMailer
|