idlemailer 2.0.0 → 2.1.0

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
- SHA1:
3
- metadata.gz: cc834e63c8ea6672e0994a01d0443523dafd5f27
4
- data.tar.gz: 756db93875c86f865d330f1eee5c6a1a1724f337
2
+ SHA256:
3
+ metadata.gz: ad91007cd0d5f336f443b3107e150dc865e52cd7048642a388e9d3b476fd180c
4
+ data.tar.gz: 822bbb3f19ffb0878d568574672fca4a6ad531c9b73f51935ce1ecae9ff77a7d
5
5
  SHA512:
6
- metadata.gz: 4726efb741bd15359ec79c3ae8825f05cfcf6cb5a0b3abac25e1bb05a78186725688479f1bc4d18ffb5d7f9a46dc9e90729e7718ca776ea1409788c44548e174
7
- data.tar.gz: 89679a1c6df53140a4e7e21011c8dd9d20cddab9ea641addfd21d92434b83e9d0c89faa6270e07324ca81c6dc240a4d199564c75d54e46ecd7ef7709fc9e5be7
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
- Instead of creating template files, you can embed your ERB templates right inside your Ruby class.
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
 
@@ -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
@@ -4,6 +4,9 @@ module IdleMailer
4
4
  # class WidgetMailer
5
5
  # include IdleMailer::Mailer
6
6
  #
7
+ # # optionally override the default layout
8
+ # self.layout = "widget_layout"
9
+ #
7
10
  # def initialize(address, widget)
8
11
  # mail.to = address
9
12
  # mail.subject = "Widget #{widget.sku}"
@@ -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(IdleMailer.config.layout, type).read.chomp)
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(IdleMailer.config.layout, type).exist?
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'] = layout 'text' if has_layout? 'text'
52
- layouts['html'] = layout 'html' if has_layout? 'html'
53
- templates['text'] = template 'text' if has_template? 'text'
54
- templates['html'] = template 'html' if has_template? '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
@@ -1,5 +1,5 @@
1
1
  # IdleMailer module
2
2
  module IdleMailer
3
3
  # Version number
4
- VERSION = '2.0.0'
4
+ VERSION = '2.1.0'
5
5
  end
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.0.0
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-04-29 00:00:00.000000000 Z
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.5.2
63
+ rubygems_version: 2.7.6
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: A lightweight alternative to ActionMailer