idlemailer 0.0.3 → 1.0.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
2
  SHA1:
3
- metadata.gz: 8d819328c9078fad1d2b23bb0e41f82ea045a6ed
4
- data.tar.gz: 69e86a4d70cd73d3b111a6453b1ea99417404310
3
+ metadata.gz: 347bc7e19b8427031ed9246730a710ca7ad8893f
4
+ data.tar.gz: 4e44c6a7525787ab0576655f863fa31b5d1359ff
5
5
  SHA512:
6
- metadata.gz: 097584f74932d8ffd5a20bf50e461615db4620add820db67a80ad9c3c37bd26fb9bc0c9b669cb521f09e7ea8077ed6b4949e9c76c3b9b9961ecc58123d2c1d7a
7
- data.tar.gz: 35786b42c65c99b839bdee043439acfda4a92e5d58388fa31b8dd234b715a9278587419e04490886702ac076fee6402f6cac0d4b7bcdcc5d21368944a7e31ba8
6
+ metadata.gz: 707144b2594688f8b838dc2eb3aa35f553c2f9bc188a0be8f6f812ccc7e801005a1068691ca8cf54d699564037e4a5fe0bb0f8e4c491425915dedc3e2ae8ef28
7
+ data.tar.gz: a349486802b1245cf60dd885b85dfbbb74ea266ee077a0ff0f1b366d864fb2004fd7718ecac63d674ce2bf667d8c2f64dced20935c78aae4f9371fd8a1f931e2
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # IdleMailer
2
2
 
3
- A lightweight alternative to ActionMailer for hipsters who use Ruby but not Rails. Powered by [mail](http://www.rubydoc.info/gems/mail). Great for API-only backends that need to send email.
3
+ A lightweight (~100 line) alternative to ActionMailer for hipsters who use Ruby but not Rails. Powered by [mail](http://www.rubydoc.info/gems/mail). Great for API-only backends that need to send email.
4
4
 
5
5
  ## Installation
6
6
 
@@ -11,68 +11,81 @@ A lightweight alternative to ActionMailer for hipsters who use Ruby but not Rail
11
11
 
12
12
  IdleMailer is all about providing mailer classes and templates. But [the mail gem](http://www.rubydoc.info/gems/mail) has a great API, so you have unfettered access to it in your mailers through the "mail" object.
13
13
 
14
- # Define your mailer class
15
- class WidgetMailer
16
- include IdleMailer::Mailer
14
+ ```ruby
15
+ # Define your mailer class
16
+ class WidgetMailer
17
+ include IdleMailer::Mailer
17
18
 
18
- def initialize(user, widget)
19
- mail.to = user.email
20
- mail.subject = "Widget #{widget.sku}"
21
- @widget = widget
22
- end
23
- end
19
+ def initialize(user, widget)
20
+ mail.to = user.email
21
+ mail.subject = "Widget #{widget.sku}"
22
+ @widget = widget
23
+ end
24
+ end
24
25
 
25
- # Create widget.html.erb and/or widget.text.erb templates.
26
- # They'll have access to instance variables like @widget above.
26
+ # Create widget.html.erb and/or widget.text.erb templates.
27
+ # They'll have access to instance variables like @widget above.
27
28
 
28
- # Send your mail
29
- mailer = WidgetMailer.new(current_user, widget)
30
- mailer.deliver
29
+ # Send your mail
30
+ mailer = WidgetMailer.new(current_user, widget)
31
+ mailer.deliver
32
+ ```
31
33
 
32
34
  ## Configure
33
35
 
34
36
  These are the default options. Salt to taste.
35
37
 
36
- IdleMailer.config do |config|
37
- # Directory containing the mailer templates
38
- config.templates = Pathname.new(Dir.getwd).join('templates')
39
-
40
- # Name of the layout template. Here, the file(s) would be named
41
- # mailer_layout.html.erb and/or mailer_layout.text.erb.
42
- config.layout = 'mailer_layout'
43
-
44
- # Email delivery method (mail gem). Set to :test when testing or when developing locally
45
- config.delivery_method = :smtp
46
-
47
- # Delivery options (mail gem)
48
- config.delivery_options = {
49
- user_name: ENV['MAIL_USER'],
50
- password: ENV['MAIL_PASSWORD'],
51
- domain: ENV['MAIL_DOMAIN'],
52
- address: ENV['MAIL_ADDRESS'],
53
- port: ENV['MAIL_PORT'] || 587,
54
- authentication: ENV['MAIL_AUTHENTICATION'] || 'plain',
55
- enable_starttls_auto: (ENV['MAIL_TLS'] ? true : false)
56
- }
57
-
58
- # Default "from" address for all mailers
59
- config.default_from = nil
60
-
61
- # Write all deliveries to $stdout
62
- config.log = false
63
- end
38
+ ```ruby
39
+ IdleMailer.config do |config|
40
+ # Directory containing the mailer templates
41
+ config.templates = Pathname.new(Dir.getwd).join('templates')
42
+
43
+ # Name of the layout template. Here, the file(s) would be named
44
+ # mailer_layout.html.erb and/or mailer_layout.text.erb.
45
+ config.layout = 'mailer_layout'
46
+
47
+ # Email delivery method (mail gem). Set to :test when testing or when developing locally
48
+ config.delivery_method = :smtp
49
+
50
+ # Delivery options (mail gem)
51
+ config.delivery_options = {
52
+ user_name: ENV['MAIL_USER'],
53
+ password: ENV['MAIL_PASSWORD'],
54
+ domain: ENV['MAIL_DOMAIN'],
55
+ address: ENV['MAIL_ADDRESS'],
56
+ port: ENV['MAIL_PORT'] || 587,
57
+ authentication: ENV['MAIL_AUTHENTICATION'] || 'plain',
58
+ enable_starttls_auto: (ENV['MAIL_TLS'] ? true : false)
59
+ }
60
+
61
+ # Default "from" address for all mailers
62
+ config.default_from = nil
63
+
64
+ # Log sent emails (require 'logger')
65
+ # config.logger = Logger.new($stdout)
66
+ # config.logger = Logger.new('log/mailers.log')
67
+ config.logger = nil
68
+
69
+ # Write full message body to log (if enabled). Otherwise, only message headers are logged.
70
+ config.log_body = false
71
+ end
72
+ ```
64
73
 
65
74
  ## Testing
66
75
 
67
76
  Put the mailer in testing mode:
68
77
 
69
- IdleMailer.config do |config|
70
- config.delivery_method = :test
71
- end
78
+ ```ruby
79
+ IdleMailer.config do |config|
80
+ config.delivery_method = :test
81
+ end
82
+ ```
72
83
 
73
84
  Then use mail gem's built in testing helpers in your specs:
74
85
 
75
- sent = Mail::TestMailer.deliveries.any? { |mail| mail.to.include? @user.email }
86
+ ```ruby
87
+ sent = Mail::TestMailer.deliveries.any? { |mail| mail.to.include? @user.email }
88
+ ```
76
89
 
77
90
  ## License
78
91
 
@@ -5,8 +5,9 @@ module IdleMailer
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
8
- # log When true, writes delivered messages to $stdout (default false)
9
- Config = Struct.new(:templates, :layout, :delivery_method, :delivery_options, :default_from, :log)
8
+ # logger a Logger object for logging email
9
+ # log_body if true, the entire message body will be logged (instead of just the headers) (default false)
10
+ Config = Struct.new(:templates, :layout, :delivery_method, :delivery_options, :default_from, :logger, :log_body)
10
11
  @config = Config.new
11
12
 
12
13
  # Takes a block and hands it an IdleMailer::Config object
@@ -12,5 +12,6 @@ IdleMailer.config do |config|
12
12
  enable_starttls_auto: (ENV['MAIL_TLS'] ? true : false)
13
13
  }
14
14
  config.default_from = nil
15
- config.log = false
15
+ config.logger = nil
16
+ config.log_body = false
16
17
  end
@@ -8,13 +8,11 @@ module IdleMailer
8
8
 
9
9
  # Initialize a new message
10
10
  def initialize(mail, mailer)
11
- @mail = mail
12
- @mailer = mailer
11
+ @mail, @mailer = mail, mailer
13
12
  end
14
13
 
15
14
  # Deliver mail
16
15
  def deliver!
17
- mail.from IdleMailer.config.default_from if mail.from.nil?
18
16
  if has_template? 'html'
19
17
  html_body = layout('html') { body('html') }
20
18
  mail.html_part do
@@ -26,9 +24,11 @@ module IdleMailer
26
24
  text_body = layout('text') { body('text') }
27
25
  mail.text_part { body text_body }
28
26
  end
29
- mail.delivery_method IdleMailer.config.delivery_method, IdleMailer.config.delivery_options
27
+ config = IdleMailer.config
28
+ mail.from config.default_from if mail.from.nil?
29
+ mail.delivery_method config.delivery_method, config.delivery_options
30
30
  message = mail.deliver
31
- $stdout.puts message if IdleMailer.config.log
31
+ config.logger.info(config.log_body ? message.to_s : message) if config.logger
32
32
  message
33
33
  end
34
34
 
@@ -55,7 +55,11 @@ module IdleMailer
55
55
  end
56
56
 
57
57
  def template_name
58
- @name ||= mailer.class.name.sub(/Mailer$/, '').gsub(/([a-z])([A-Z])/, "\\1_\\2").downcase
58
+ @name ||= mailer.class.name.
59
+ gsub(/::/, File::SEPARATOR).
60
+ sub(/Mailer$/, '').
61
+ gsub(/([a-z])([A-Z])/, "\\1_\\2").
62
+ downcase
59
63
  end
60
64
 
61
65
  def template_path(name, type)
@@ -1,5 +1,5 @@
1
1
  # IdleMailer module
2
2
  module IdleMailer
3
3
  # Version number
4
- VERSION = '0.0.3'
4
+ VERSION = '1.0.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: 0.0.3
4
+ version: 1.0.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: 2015-05-11 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -58,8 +58,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 2.4.5
61
+ rubygems_version: 2.4.5.1
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: A lightweight alternative to ActionMailer
65
65
  test_files: []
66
+ has_rdoc: