padrino-mailer 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/padrino-mailer/base.rb +38 -24
- data/lib/padrino-mailer/delivery.rb +3 -3
- data/lib/padrino-mailer/mail_object.rb +38 -21
- data/lib/padrino-mailer.rb +11 -2
- data/padrino-mailer.gemspec +5 -5
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.6
|
data/lib/padrino-mailer/base.rb
CHANGED
@@ -1,49 +1,54 @@
|
|
1
|
-
=begin
|
2
|
-
|
3
|
-
This is the abstract class that other mailers will inherit from in order to send mail
|
4
|
-
|
5
|
-
You can set the default delivery settings through:
|
6
|
-
|
7
|
-
Padrino::Mailer::Base.smtp_settings = {
|
8
|
-
:host => 'smtp.yourserver.com',
|
9
|
-
:port => '25',
|
10
|
-
:user => 'user',
|
11
|
-
:pass => 'pass',
|
12
|
-
:auth => :plain # :plain, :login, :cram_md5, no auth by default
|
13
|
-
:domain => "localhost.localdomain" # the HELO domain provided by the client to the server
|
14
|
-
}
|
15
|
-
|
16
|
-
and then all delivered mail will use these settings unless otherwise specified.
|
17
|
-
|
18
|
-
=end
|
19
|
-
|
20
1
|
module Padrino
|
21
2
|
module Mailer
|
3
|
+
##
|
4
|
+
# This is the abstract class that other mailers will inherit from in order to send mail
|
5
|
+
#
|
6
|
+
# You can set the default delivery settings through:
|
7
|
+
#
|
8
|
+
# Padrino::Mailer::Base.smtp_settings = {
|
9
|
+
# :host => 'smtp.yourserver.com',
|
10
|
+
# :port => '25',
|
11
|
+
# :user => 'user',
|
12
|
+
# :pass => 'pass',
|
13
|
+
# :auth => :plain # :plain, :login, :cram_md5, no auth by default
|
14
|
+
# :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
|
15
|
+
# }
|
16
|
+
#
|
17
|
+
# and then all delivered mail will use these settings unless otherwise specified.
|
18
|
+
#
|
22
19
|
class Base
|
20
|
+
##
|
23
21
|
# Returns the available mail fields when composing a message
|
22
|
+
#
|
24
23
|
def self.mail_fields
|
25
24
|
[:to, :from, :subject, :type, :charset, :via, :attachments]
|
26
25
|
end
|
27
26
|
|
28
27
|
attr_accessor :mail_attributes
|
29
28
|
|
30
|
-
def initialize(mail_name=nil)
|
29
|
+
def initialize(mail_name=nil) #:nodoc:
|
31
30
|
@mail_name = mail_name
|
32
31
|
@mail_attributes = {}
|
33
32
|
end
|
34
33
|
|
34
|
+
##
|
35
35
|
# Defines a method allowing mail attributes to be set into a hash for use when delivering
|
36
|
+
#
|
36
37
|
self.mail_fields.each do |field|
|
37
38
|
define_method(field) { |value| @mail_attributes[field] = value }
|
38
39
|
end
|
39
40
|
|
41
|
+
##
|
40
42
|
# Assigns the body key to the mail attributes either with the rendered body from a template or the given string value
|
43
|
+
#
|
41
44
|
def body(body_value)
|
42
45
|
@mail_attributes[:body] = Tilt.new(template_path).render(self, body_value.symbolize_keys) if body_value.is_a?(Hash)
|
43
46
|
@mail_attributes[:body] = body_value if body_value.is_a?(String)
|
44
47
|
end
|
45
48
|
|
49
|
+
##
|
46
50
|
# Returns the path to the email template searched for using glob pattern
|
51
|
+
#
|
47
52
|
def template_path
|
48
53
|
Dir[File.join(self.views_path, self.class.name.underscore.split("/").last, "#{@mail_name}.*")].first
|
49
54
|
end
|
@@ -51,25 +56,34 @@ module Padrino
|
|
51
56
|
cattr_accessor :smtp_settings
|
52
57
|
cattr_accessor :views_path
|
53
58
|
|
59
|
+
##
|
54
60
|
# Delivers the specified message for mail_name to the intended recipients
|
55
61
|
# mail_name corresponds to the name of a defined method within the mailer class
|
56
|
-
#
|
62
|
+
#
|
63
|
+
# ==== Examples
|
64
|
+
#
|
65
|
+
# SampleMailer.deliver(:birthday_message)
|
66
|
+
#
|
57
67
|
def self.deliver(mail_name, *args)
|
58
68
|
mail_object = self.new(mail_name)
|
59
69
|
mail_object.method(mail_name).call(*args)
|
60
70
|
MailObject.new(mail_object.mail_attributes, self.smtp_settings).deliver
|
61
71
|
end
|
62
72
|
|
73
|
+
##
|
63
74
|
# Returns true if a mail exists with the name being delivered
|
75
|
+
#
|
64
76
|
def self.respond_to?(method_sym, include_private = false)
|
65
77
|
method_sym.to_s =~ /deliver_(.*)/ ? self.method_defined?($1) : super
|
66
78
|
end
|
67
79
|
|
80
|
+
##
|
68
81
|
# Handles method missing for a mailer class. Delivers a message based on the method
|
69
82
|
# being called i.e #deliver_birthday_message(22) invokes #birthday_message(22) to setup mail object
|
83
|
+
#
|
70
84
|
def self.method_missing(method_sym, *arguments, &block)
|
71
85
|
method_sym.to_s =~ /deliver_(.*)/ ? self.deliver($1, *arguments) : super
|
72
86
|
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
87
|
+
end # Base
|
88
|
+
end # Mailer
|
89
|
+
end # Padrino
|
@@ -1,16 +1,34 @@
|
|
1
|
-
# This represents a particular mail object which will need to be sent
|
2
|
-
# A mail_object requires the mail attributes and the delivery_settings
|
3
|
-
|
4
1
|
module Padrino
|
5
2
|
module Mailer
|
3
|
+
##
|
4
|
+
# This represents a particular mail object which will need to be sent
|
5
|
+
# A mail_object requires the mail attributes and the delivery_settings
|
6
|
+
#
|
6
7
|
class MailObject
|
8
|
+
##
|
9
|
+
# Initialize a new MailObject
|
10
|
+
#
|
11
|
+
# ==== Examples
|
12
|
+
#
|
13
|
+
# Padrino::Mailer::MailObject.new(
|
14
|
+
# :subject => "Hey this is my subject",
|
15
|
+
# :to => "info@padrinorb.org",
|
16
|
+
# :from => "foo@bar.com",
|
17
|
+
# :body => "This is my body"
|
18
|
+
# ).deliver
|
19
|
+
#
|
7
20
|
def initialize(mail_attributes={}, smtp_settings={})
|
8
21
|
@mail_attributes = mail_attributes.dup
|
9
22
|
@smtp_settings = smtp_settings.dup if smtp_settings.present?
|
10
23
|
end
|
11
24
|
|
25
|
+
##
|
12
26
|
# Constructs the delivery attributes for the message and then sends the mail
|
13
|
-
#
|
27
|
+
#
|
28
|
+
# ==== Examples
|
29
|
+
#
|
30
|
+
# @mail_object.deliver
|
31
|
+
#
|
14
32
|
def deliver
|
15
33
|
@mail_attributes.reverse_merge!(:via => self.delivery_method.to_sym)
|
16
34
|
@mail_attributes.reverse_merge!(:smtp => @smtp_settings) if using_smtp?
|
@@ -18,22 +36,21 @@ module Padrino
|
|
18
36
|
end
|
19
37
|
|
20
38
|
protected
|
39
|
+
# Returns the delivery method to use for this mail object
|
40
|
+
# @mo.delivery_method => :smtp || :sendmail
|
41
|
+
def delivery_method
|
42
|
+
@mail_attributes[:via] || (@smtp_settings.present? ? :smtp : :sendmail)
|
43
|
+
end
|
21
44
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
45
|
+
# Returns true if the mail object is going to be delivered using smtp
|
46
|
+
def using_smtp?
|
47
|
+
delivery_method.to_s =~ /smtp/
|
48
|
+
end
|
27
49
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Delivery.mail(delivery_attributes) && true
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
50
|
+
# Performs the actual email sending
|
51
|
+
def send_mail(delivery_attributes)
|
52
|
+
Delivery.mail(delivery_attributes) && true
|
53
|
+
end
|
54
|
+
end # MailObject
|
55
|
+
end # Mailer
|
56
|
+
end # Padrino
|
data/lib/padrino-mailer.rb
CHANGED
@@ -4,9 +4,18 @@ require 'padrino-core/support_lite'
|
|
4
4
|
Dir[File.dirname(__FILE__) + '/padrino-mailer/**/*.rb'].each { |file| require file }
|
5
5
|
|
6
6
|
module Padrino
|
7
|
+
##
|
8
|
+
# This component uses an enhanced version of the excellent pony library (vendored) for a powerful but simple mailer
|
9
|
+
# system within Padrino (and Sinatra).
|
10
|
+
# There is full support for using an html content type as well as for file attachments.
|
11
|
+
# The MailerPlugin has many similarities to ActionMailer but is much lighterweight and (arguably) easier to use.
|
12
|
+
#
|
7
13
|
module Mailer
|
14
|
+
##
|
15
|
+
# Used Padrino::Application for register Padrino::Mailer::Base::views_path
|
16
|
+
#
|
8
17
|
def self.registered(app)
|
9
18
|
Padrino::Mailer::Base::views_path = app.views
|
10
19
|
end
|
11
|
-
end
|
12
|
-
end
|
20
|
+
end # Mailer
|
21
|
+
end # Padrino
|
data/padrino-mailer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-mailer}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-10}
|
13
13
|
s.description = %q{Mailer system for padrino allowing easy delivery of application emails}
|
14
14
|
s.email = %q{padrinorb@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
|
|
49
49
|
|
50
50
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
51
|
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
|
52
|
-
s.add_runtime_dependency(%q<padrino-core>, ["= 0.7.
|
52
|
+
s.add_runtime_dependency(%q<padrino-core>, ["= 0.7.6"])
|
53
53
|
s.add_runtime_dependency(%q<tilt>, [">= 0.2"])
|
54
54
|
s.add_runtime_dependency(%q<tmail>, [">= 1.2"])
|
55
55
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
@@ -59,7 +59,7 @@ Gem::Specification.new do |s|
|
|
59
59
|
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
60
60
|
else
|
61
61
|
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
62
|
-
s.add_dependency(%q<padrino-core>, ["= 0.7.
|
62
|
+
s.add_dependency(%q<padrino-core>, ["= 0.7.6"])
|
63
63
|
s.add_dependency(%q<tilt>, [">= 0.2"])
|
64
64
|
s.add_dependency(%q<tmail>, [">= 1.2"])
|
65
65
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
@@ -70,7 +70,7 @@ Gem::Specification.new do |s|
|
|
70
70
|
end
|
71
71
|
else
|
72
72
|
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
73
|
-
s.add_dependency(%q<padrino-core>, ["= 0.7.
|
73
|
+
s.add_dependency(%q<padrino-core>, ["= 0.7.6"])
|
74
74
|
s.add_dependency(%q<tilt>, [">= 0.2"])
|
75
75
|
s.add_dependency(%q<tmail>, [">= 1.2"])
|
76
76
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2010-02-
|
15
|
+
date: 2010-02-10 00:00:00 +01:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
requirements:
|
34
34
|
- - "="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 0.7.
|
36
|
+
version: 0.7.6
|
37
37
|
version:
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: tilt
|