padrino-mailer 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -33,6 +33,7 @@ Next, we should define a custom mailer extended from <tt>Padrino::Mailer::Base</
33
33
  type 'html' # optional, defaults to plain/text
34
34
  charset 'windows-1252' # optional, defaults to utf-8
35
35
  via :sendmail # optional, to smtp if defined otherwise sendmail
36
+ template 'sample_mailer/foo' # optional, defaults to views/sample_mailer/registration_email.erb
36
37
  end
37
38
  end
38
39
 
@@ -55,7 +56,7 @@ or if you like the method_missing approach:
55
56
  And that will then deliver the email according the the configured options. This is really all you need to send emails.
56
57
 
57
58
  Be sure to check out the
58
- {Padrino Mailer}[http://wiki.github.com/padrino/padrino-framework/padrino-mailer] guide for more details on usage.
59
+ {Padrino Mailer}[http://www.padrinorb.com/guides/padrino-mailer] guide for more details on usage.
59
60
 
60
61
  == Copyright
61
62
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- GEM_VERSION = File.read(File.dirname(__FILE__) + '/VERSION')
4
+ require File.expand_path("../../padrino-core/lib/padrino-core/version.rb", __FILE__)
5
5
 
6
6
  begin
7
7
  require 'jeweler'
@@ -13,7 +13,8 @@ begin
13
13
  gem.homepage = "http://github.com/padrino/padrino-framework/tree/master/padrino-mailer"
14
14
  gem.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
15
15
  gem.rubyforge_project = 'padrino-mailer'
16
- gem.add_runtime_dependency "padrino-core", "= #{GEM_VERSION}"
16
+ gem.version = Padrino.version
17
+ gem.add_runtime_dependency "padrino-core", "= #{Padrino.version}"
17
18
  gem.add_runtime_dependency "tmail", ">= 1.2"
18
19
  gem.add_development_dependency "shoulda", ">= 2.10.3"
19
20
  gem.add_development_dependency "haml", ">= 2.2.1"
@@ -49,16 +50,4 @@ rescue LoadError
49
50
  end
50
51
  end
51
52
 
52
- # task :test => :check_dependencies
53
-
54
- task :default => :test
55
-
56
- require 'rake/rdoctask'
57
- Rake::RDocTask.new do |rdoc|
58
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
59
-
60
- rdoc.rdoc_dir = 'rdoc'
61
- rdoc.title = "padrino-mailer #{version}"
62
- rdoc.rdoc_files.include('README*')
63
- rdoc.rdoc_files.include('lib/**/*.rb')
64
- end
53
+ task :default => :test
@@ -21,7 +21,7 @@ module Padrino
21
21
  # Returns the available mail fields when composing a message
22
22
  #
23
23
  def self.mail_fields
24
- [:to, :cc, :bcc, :reply_to, :from, :subject, :content_type, :charset, :via, :attachments]
24
+ [:to, :cc, :bcc, :reply_to, :from, :subject, :content_type, :charset, :via, :attachments, :template]
25
25
  end
26
26
 
27
27
  @@views_path = []
@@ -45,9 +45,9 @@ module Padrino
45
45
  # Assigns the body key to the mail attributes either with the rendered body from a template or the given string value
46
46
  #
47
47
  def body(body_value)
48
- template = template_path
49
- raise "Template for '#{@mail_name}' could not be located in views path!" unless template
50
- @mail_attributes[:body] = Tilt.new(template).render(self, body_value.symbolize_keys) if body_value.is_a?(Hash)
48
+ final_template = template_path
49
+ raise "Template for '#{@mail_name}' could not be located in views path!" unless final_template
50
+ @mail_attributes[:body] = Tilt.new(final_template).render(self, body_value.symbolize_keys) if body_value.is_a?(Hash)
51
51
  @mail_attributes[:body] = body_value if body_value.is_a?(String)
52
52
  end
53
53
 
@@ -55,8 +55,8 @@ module Padrino
55
55
  # Returns the path to the email template searched for using glob pattern
56
56
  #
57
57
  def template_path
58
- self.views_path.each do |path|
59
- template = Dir[File.join(path, self.class.name.underscore.split("/").last, "#{@mail_name}.*")].first
58
+ self.views_path.each do |view_path|
59
+ template = Dir[File.join(view_path, template_pattern)].first
60
60
  return template if template
61
61
  end
62
62
  end
@@ -89,6 +89,14 @@ module Padrino
89
89
  def self.method_missing(method_sym, *arguments, &block)
90
90
  method_sym.to_s =~ /deliver_(.*)/ ? self.deliver($1, *arguments) : super(method_sym, *arguments, &block)
91
91
  end
92
+
93
+ private
94
+
95
+ # Returns the glob pattern of the template file to locate and render
96
+ def template_pattern
97
+ @_pattern ||= (@mail_attributes[:template].present? ? "#{@mail_attributes[:template]}.*" :
98
+ File.join(self.class.name.underscore.split("/").last, "#{@mail_name}.*"))
99
+ end
92
100
  end # Base
93
101
  end # Mailer
94
- end # Padrino
102
+ end # Padrino
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-mailer}
8
- s.version = "0.9.9"
8
+ s.version = "0.9.10"
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-03-29}
12
+ s.date = %q{2010-04-22}
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 = [
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
21
21
  "LICENSE",
22
22
  "README.rdoc",
23
23
  "Rakefile",
24
- "VERSION",
25
24
  "lib/padrino-mailer.rb",
26
25
  "lib/padrino-mailer/base.rb",
27
26
  "lib/padrino-mailer/delivery.rb",
@@ -31,6 +30,7 @@ Gem::Specification.new do |s|
31
30
  "test/fixtures/mailer_app/views/demo_mailer/sample_mail.erb",
32
31
  "test/fixtures/mailer_app/views/sample_mailer/anniversary_message.erb",
33
32
  "test/fixtures/mailer_app/views/sample_mailer/birthday_message.erb",
33
+ "test/fixtures/mailer_app/views/sample_mailer/foo_message.erb",
34
34
  "test/helper.rb",
35
35
  "test/test_base.rb",
36
36
  "test/test_mail_object.rb",
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
48
48
  s.specification_version = 3
49
49
 
50
50
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
- s.add_runtime_dependency(%q<padrino-core>, ["= 0.9.9"])
51
+ s.add_runtime_dependency(%q<padrino-core>, ["= 0.9.10"])
52
52
  s.add_runtime_dependency(%q<tmail>, [">= 1.2"])
53
53
  s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
54
54
  s.add_development_dependency(%q<haml>, [">= 2.2.1"])
@@ -56,7 +56,7 @@ Gem::Specification.new do |s|
56
56
  s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
57
57
  s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
58
58
  else
59
- s.add_dependency(%q<padrino-core>, ["= 0.9.9"])
59
+ s.add_dependency(%q<padrino-core>, ["= 0.9.10"])
60
60
  s.add_dependency(%q<tmail>, [">= 1.2"])
61
61
  s.add_dependency(%q<shoulda>, [">= 2.10.3"])
62
62
  s.add_dependency(%q<haml>, [">= 2.2.1"])
@@ -65,7 +65,7 @@ Gem::Specification.new do |s|
65
65
  s.add_dependency(%q<webrat>, [">= 0.5.1"])
66
66
  end
67
67
  else
68
- s.add_dependency(%q<padrino-core>, ["= 0.9.9"])
68
+ s.add_dependency(%q<padrino-core>, ["= 0.9.10"])
69
69
  s.add_dependency(%q<tmail>, [">= 1.2"])
70
70
  s.add_dependency(%q<shoulda>, [">= 2.10.3"])
71
71
  s.add_dependency(%q<haml>, [">= 2.2.1"])
@@ -17,7 +17,6 @@ class MailerDemo < Sinatra::Base
17
17
  register Padrino::Mailer
18
18
 
19
19
  class SampleMailer < Padrino::Mailer::Base
20
-
21
20
  def birthday_message(name, age)
22
21
  subject "Happy Birthday!"
23
22
  to 'john@fake.com'
@@ -33,6 +32,15 @@ class MailerDemo < Sinatra::Base
33
32
  body 'names' => names, 'years_married' => years_married
34
33
  content_type 'text/html'
35
34
  end
35
+
36
+ def welcome_message(name)
37
+ template 'sample_mailer/foo_message'
38
+ subject "Welcome Message!"
39
+ to 'john@fake.com'
40
+ from 'noreply@custom.com'
41
+ body 'name' => name
42
+ via :smtp
43
+ end
36
44
  end
37
45
 
38
46
  post "/deliver/plain" do
@@ -40,6 +48,11 @@ class MailerDemo < Sinatra::Base
40
48
  result ? "mail delivered" : 'mail not delivered'
41
49
  end
42
50
 
51
+ post "/deliver/custom" do
52
+ result = SampleMailer.deliver_welcome_message("Bobby")
53
+ result ? "mail delivered" : 'mail not delivered'
54
+ end
55
+
43
56
  post "/deliver/html" do
44
57
  result = SampleMailer.deliver_anniversary_message("Joey & Charlotte", 16)
45
58
  result ? "mail delivered" : 'mail not delivered'
@@ -0,0 +1 @@
1
+ Hello to <%= name %>
@@ -19,8 +19,17 @@ class TestPadrinoMailer < Test::Unit::TestCase
19
19
  assert_equal 'mail delivered', last_response.body
20
20
  end
21
21
 
22
+ should 'be able to deliver emails with custom view' do
23
+ assert_email_sent(:template => 'sample_mailer/foo_message', :to => 'john@fake.com',
24
+ :from => 'noreply@custom.com', :via => :smtp,
25
+ :subject => "Welcome Message!", :body => "Hello to Bobby")
26
+ visit '/deliver/custom', :post
27
+ assert_equal 'mail delivered', last_response.body
28
+ end
29
+
22
30
  should 'be able to deliver html emails' do
23
- assert_email_sent(:to => 'julie@fake.com', :from => 'noreply@anniversary.com', :content_type => 'text/html', :via => :smtp,
31
+ assert_email_sent(:to => 'julie@fake.com', :from => 'noreply@anniversary.com',
32
+ :content_type => 'text/html', :via => :smtp,
24
33
  :subject => "Happy anniversary!", :body => "<p>Yay Joey & Charlotte!</p>\n<p>You have been married 16 years</p>")
25
34
  visit '/deliver/html', :post
26
35
  assert_equal 'mail delivered', last_response.body
@@ -29,8 +38,8 @@ class TestPadrinoMailer < Test::Unit::TestCase
29
38
 
30
39
  protected
31
40
 
32
- def assert_email_sent(mail_attributes)
33
- delivery_attributes = mail_attributes.merge(:smtp => MailerDemo.smtp_settings)
34
- Padrino::Mailer::MailObject.any_instance.expects(:send_mail).with(delivery_attributes).once.returns(true)
35
- end
41
+ def assert_email_sent(mail_attributes)
42
+ delivery_attributes = mail_attributes.merge(:smtp => MailerDemo.smtp_settings)
43
+ Padrino::Mailer::MailObject.any_instance.expects(:send_mail).with(delivery_attributes).once.returns(true)
44
+ end
36
45
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 9
9
- version: 0.9.9
8
+ - 10
9
+ version: 0.9.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - Padrino Team
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-03-29 00:00:00 -07:00
20
+ date: 2010-04-22 00:00:00 +02:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -30,8 +30,8 @@ dependencies:
30
30
  segments:
31
31
  - 0
32
32
  - 9
33
- - 9
34
- version: 0.9.9
33
+ - 10
34
+ version: 0.9.10
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -131,7 +131,6 @@ files:
131
131
  - LICENSE
132
132
  - README.rdoc
133
133
  - Rakefile
134
- - VERSION
135
134
  - lib/padrino-mailer.rb
136
135
  - lib/padrino-mailer/base.rb
137
136
  - lib/padrino-mailer/delivery.rb
@@ -141,6 +140,7 @@ files:
141
140
  - test/fixtures/mailer_app/views/demo_mailer/sample_mail.erb
142
141
  - test/fixtures/mailer_app/views/sample_mailer/anniversary_message.erb
143
142
  - test/fixtures/mailer_app/views/sample_mailer/birthday_message.erb
143
+ - test/fixtures/mailer_app/views/sample_mailer/foo_message.erb
144
144
  - test/helper.rb
145
145
  - test/test_base.rb
146
146
  - test/test_mail_object.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.9.9