actionmailer 3.0.0.beta3 → 3.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionmailer might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ *Rails 3.0.0 [beta 4] (June 8th, 2010)*
2
+
3
+ * Changed encoding behaviour of mail, so updated tests in actionmailer and bumped mail version to 2.2.1 [ML]
4
+
5
+ * Added ability to pass Proc objects to the defaults hash [ML]
6
+
7
+
1
8
  *Rails 3.0.0 [beta 3] (April 13th, 2010)*
2
9
 
3
10
  * Removed all quoting.rb type files from ActionMailer and put Mail 2.2.0 in instead [ML]
@@ -27,7 +27,7 @@ $:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(
27
27
  require 'abstract_controller'
28
28
  require 'action_view'
29
29
 
30
- # Common ActiveSupport usage in ActionMailer
30
+ # Common Active Support usage in Action Mailer
31
31
  require 'active_support/core_ext/class'
32
32
  require 'active_support/core_ext/object/blank'
33
33
  require 'active_support/core_ext/array/uniq_by'
@@ -49,9 +49,3 @@ module ActionMailer
49
49
  autoload :TestCase
50
50
  autoload :TestHelper
51
51
  end
52
-
53
- module Text
54
- extend ActiveSupport::Autoload
55
-
56
- autoload :Format, 'text/format'
57
- end
@@ -3,6 +3,7 @@ require 'action_mailer/tmail_compat'
3
3
  require 'action_mailer/collector'
4
4
  require 'active_support/core_ext/array/wrap'
5
5
  require 'active_support/core_ext/object/blank'
6
+ require 'active_support/core_ext/proc'
6
7
 
7
8
  module ActionMailer #:nodoc:
8
9
  # Action Mailer allows you to send email from your application using a mailer model and views.
@@ -13,7 +14,7 @@ module ActionMailer #:nodoc:
13
14
  #
14
15
  # $ rails generate mailer Notifier
15
16
  #
16
- # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods
17
+ # The generated model inherits from <tt>ActionMailer::Base</tt>. Emails are defined by creating methods
17
18
  # within the model which are then used to set variables to be used in the mail template, to
18
19
  # change options on the mail, or to add attachments.
19
20
  #
@@ -22,19 +23,22 @@ module ActionMailer #:nodoc:
22
23
  # class Notifier < ActionMailer::Base
23
24
  # default :from => 'no-reply@example.com',
24
25
  # :return_path => 'system@example.com'
25
- #
26
+ #
26
27
  # def welcome(recipient)
27
28
  # @account = recipient
28
29
  # mail(:to => recipient.email_address_with_name,
29
30
  # :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"])
30
31
  # end
31
32
  # end
32
- #
33
+ #
33
34
  # Within the mailer method, you have access to the following methods:
34
- #
35
+ #
35
36
  # * <tt>attachments[]=</tt> - Allows you to add attachments to your email in an intuitive
36
37
  # manner; <tt>attachments['filename.png'] = File.read('path/to/filename.png')</tt>
37
38
  #
39
+ # * <tt>attachments.inline[]=</tt> - Allows you to add an inline attachment to your email
40
+ # in the same manner as <tt>attachments[]=</tt>
41
+ #
38
42
  # * <tt>headers[]=</tt> - Allows you to specify any header field in your email such
39
43
  # as <tt>headers['X-No-Spam'] = 'True'</tt>. Note, while most fields (like <tt>To:</tt>
40
44
  # <tt>From:</tt> can only appear once in an email header, other fields like <tt>X-Anything</tt>
@@ -46,16 +50,16 @@ module ActionMailer #:nodoc:
46
50
  # as <tt>headers({'X-No-Spam' => 'True', 'In-Reply-To' => '1234@message.id'})</tt>
47
51
  #
48
52
  # * <tt>mail</tt> - Allows you to specify your email to send.
49
- #
53
+ #
50
54
  # The hash passed to the mail method allows you to specify any header that a Mail::Message
51
55
  # will accept (any valid Email header including optional fields).
52
56
  #
53
57
  # The mail method, if not passed a block, will inspect your views and send all the views with
54
58
  # the same name as the method, so the above action would send the +welcome.text.plain.erb+ view
55
59
  # file as well as the +welcome.text.html.erb+ view file in a +multipart/alternative+ email.
56
- #
60
+ #
57
61
  # If you want to explicitly render only certain templates, pass a block:
58
- #
62
+ #
59
63
  # mail(:to => user.emai) do |format|
60
64
  # format.text
61
65
  # format.html
@@ -79,7 +83,7 @@ module ActionMailer #:nodoc:
79
83
  #
80
84
  # Like Action Controller, each mailer class has a corresponding view directory in which each
81
85
  # method of the class looks for a template with its name.
82
- #
86
+ #
83
87
  # To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same
84
88
  # name as the method in your mailer model. For example, in the mailer defined above, the template at
85
89
  # <tt>app/views/notifier/signup_notification.text.plain.erb</tt> would be used to generate the email.
@@ -104,7 +108,7 @@ module ActionMailer #:nodoc:
104
108
  #
105
109
  # = Generating URLs
106
110
  #
107
- # URLs can be generated in mailer views using <tt>url_for</tt> or named routes. Unlike controllers from
111
+ # URLs can be generated in mailer views using <tt>url_for</tt> or named routes. Unlike controllers from
108
112
  # Action Pack, the mailer instance doesn't have any context about the incoming request, so you'll need
109
113
  # to provide all of the details needed to generate a URL.
110
114
  #
@@ -172,44 +176,110 @@ module ActionMailer #:nodoc:
172
176
  #
173
177
  # class ApplicationMailer < ActionMailer::Base
174
178
  # def welcome(recipient)
175
- # attachments['free_book.pdf'] = { :data => File.read('path/to/file.pdf') }
179
+ # attachments['free_book.pdf'] = File.read('path/to/file.pdf')
176
180
  # mail(:to => recipient, :subject => "New account information")
177
181
  # end
178
182
  # end
179
- #
183
+ #
180
184
  # Which will (if it had both a <tt>welcome.text.plain.erb</tt> and <tt>welcome.text.html.erb</tt>
181
185
  # tempalte in the view directory), send a complete <tt>multipart/mixed</tt> email with two parts,
182
186
  # the first part being a <tt>multipart/alternative</tt> with the text and HTML email parts inside,
183
187
  # and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
184
188
  # with the filename +free_book.pdf+.
185
189
  #
186
- # = Observing and Intercepting Mails
190
+ # = Inline Attachments
187
191
  #
188
- # ActionMailer provides hooks into the Mail observer and interceptor methods. These allow you to
189
- # register objects that are called during the mail delivery life cycle.
192
+ # You can also specify that a file should be displayed inline with other HTML. For example a
193
+ # corporate logo or a photo or the like.
194
+ #
195
+ # To do this is simple, in the Mailer:
190
196
  #
197
+ # class ApplicationMailer < ActionMailer::Base
198
+ # def welcome(recipient)
199
+ # attachments.inline['photo.png'] = File.read('path/to/photo.png')
200
+ # mail(:to => recipient, :subject => "Here is what we look like")
201
+ # end
202
+ # end
203
+ #
204
+ # And then to reference the image in the view, you create a <tt>welcome.html.erb</tt> file and
205
+ # make a call to +image_tag+ passing in the attachment you want to display and then call
206
+ # +url+ on the attachment to get the relative content id path for the image source:
207
+ #
208
+ # <h1>Please Don't Cringe</h1>
209
+ #
210
+ # <%= image_tag attachments['photo.png'].url -%>
211
+ #
212
+ # As we are using ActionView's +image_tag+ method, you can pass in any other options you want:
213
+ #
214
+ # <h1>Please Don't Cringe</h1>
215
+ #
216
+ # <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%>
217
+ #
218
+ # = Observing and Intercepting Mails
219
+ #
220
+ # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to
221
+ # register objects that are called during the mail delivery life cycle.
222
+ #
191
223
  # An observer object must implement the <tt>:delivered_email(message)</tt> method which will be
192
224
  # called once for every email sent after the email has been sent.
193
- #
225
+ #
194
226
  # An interceptor object must implement the <tt>:delivering_email(message)</tt> method which will be
195
227
  # called before the email is sent, allowing you to make modifications to the email before it hits
196
228
  # the delivery agents. Your object should make and needed modifications directly to the passed
197
229
  # in Mail::Message instance.
198
230
  #
231
+ # = Default Hash
232
+ #
233
+ # Action Mailer provides some intelligent defaults for your emails, these are usually specified in a
234
+ # default method inside the class definition:
235
+ #
236
+ # class Notifier < ActionMailer::Base
237
+ # default :sender => 'system@example.com'
238
+ # end
239
+ #
240
+ # You can pass in any header value that a <tt>Mail::Message</tt>, out of the box, <tt>ActionMailer::Base</tt>
241
+ # sets the following:
242
+ #
243
+ # * <tt>:mime_version => "1.0"</tt>
244
+ # * <tt>:charset => "UTF-8",</tt>
245
+ # * <tt>:content_type => "text/plain",</tt>
246
+ # * <tt>:parts_order => [ "text/plain", "text/enriched", "text/html" ]</tt>
247
+ #
248
+ # <tt>parts_order</tt> and <tt>charset</tt> are not actually valid <tt>Mail::Message</tt> header fields,
249
+ # but Action Mailer translates them appropriately and sets the correct values.
250
+ #
251
+ # As you can pass in any header, you need to either quote the header as a string, or pass it in as
252
+ # an underscorised symbol, so the following will work:
253
+ #
254
+ # class Notifier < ActionMailer::Base
255
+ # default 'Content-Transfer-Encoding' => '7bit',
256
+ # :content_description => 'This is a description'
257
+ # end
258
+ #
259
+ # Finally, Action Mailer also supports passing <tt>Proc</tt> objects into the default hash, so you
260
+ # can define methods that evaluate as the message is being generated:
261
+ #
262
+ # class Notifier < ActionMailer::Base
263
+ # default 'X-Special-Header' => Proc.new { my_method }
264
+ #
265
+ # private
266
+ #
267
+ # def my_method
268
+ # 'some complex call'
269
+ # end
270
+ # end
271
+ #
272
+ # Note that the proc is evaluated right at the start of the mail message generation, so if you
273
+ # set something in the defaults using a proc, and then set the same thing inside of your
274
+ # mailer method, it will get over written by the mailer method.
275
+ #
199
276
  # = Configuration options
200
277
  #
201
- # These options are specified on the class level, like <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
278
+ # These options are specified on the class level, like
279
+ # <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
202
280
  #
203
- # * <tt>default</tt> - This is a class wide hash of <tt>:key => value</tt> pairs containing
204
- # default values for the specified header fields of the <tt>Mail::Message</tt>. You can
205
- # specify a default for any valid header for <tt>Mail::Message</tt> and it will be used if
206
- # you do not override it. You pass in the header value as a symbol, all lower case with under
207
- # scores instead of hyphens, so <tt>Content-Transfer-Encoding:</tt>
208
- # becomes <tt>:content_transfer_encoding</tt>. The defaults set by Action Mailer are:
209
- # * <tt>:mime_version => "1.0"</tt>
210
- # * <tt>:charset => "UTF-8",</tt>
211
- # * <tt>:content_type => "text/plain",</tt>
212
- # * <tt>:parts_order => [ "text/plain", "text/enriched", "text/html" ]</tt>
281
+ # * <tt>default</tt> - You can pass this in at a class level as well as within the class itself as
282
+ # per the above section.
213
283
  #
214
284
  # * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
215
285
  # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
@@ -250,16 +320,16 @@ module ActionMailer #:nodoc:
250
320
  # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with
251
321
  # <tt>delivery_method :test</tt>. Most useful for unit and functional testing.
252
322
  #
253
- # * <tt>default_charset</tt> - This is now deprecated, use the +default+ method above to
323
+ # * <tt>default_charset</tt> - This is now deprecated, use the +default+ method above to
254
324
  # set the default +:charset+.
255
325
  #
256
- # * <tt>default_content_type</tt> - This is now deprecated, use the +default+ method above
326
+ # * <tt>default_content_type</tt> - This is now deprecated, use the +default+ method above
257
327
  # to set the default +:content_type+.
258
328
  #
259
- # * <tt>default_mime_version</tt> - This is now deprecated, use the +default+ method above
329
+ # * <tt>default_mime_version</tt> - This is now deprecated, use the +default+ method above
260
330
  # to set the default +:mime_version+.
261
331
  #
262
- # * <tt>default_implicit_parts_order</tt> - This is now deprecated, use the +default+ method above
332
+ # * <tt>default_implicit_parts_order</tt> - This is now deprecated, use the +default+ method above
263
333
  # to set the default +:parts_order+. Parts Order is used when a message is built implicitly
264
334
  # (i.e. multiple parts are assembled from templates which specify the content type in their
265
335
  # filenames) this variable controls how the parts are ordered.
@@ -272,12 +342,13 @@ module ActionMailer #:nodoc:
272
342
  include AbstractController::Layouts
273
343
  include AbstractController::Helpers
274
344
  include AbstractController::Translation
345
+ include AbstractController::AssetPaths
275
346
 
276
347
  helper ActionMailer::MailHelper
277
348
 
278
349
  include ActionMailer::OldApi
279
350
  include ActionMailer::DeprecatedApi
280
-
351
+
281
352
  delegate :register_observer, :to => Mail
282
353
  delegate :register_interceptor, :to => Mail
283
354
 
@@ -291,8 +362,6 @@ module ActionMailer #:nodoc:
291
362
  :parts_order => [ "text/plain", "text/enriched", "text/html" ]
292
363
  }.freeze
293
364
 
294
- ActiveSupport.run_load_hooks(:action_mailer, self)
295
-
296
365
  class << self
297
366
 
298
367
  def mailer_name
@@ -318,7 +387,7 @@ module ActionMailer #:nodoc:
318
387
  # end
319
388
  # end
320
389
  def receive(raw_mail)
321
- ActiveSupport::Notifications.instrument("action_mailer.receive") do |payload|
390
+ ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
322
391
  mail = Mail.new(raw_mail)
323
392
  set_payload_for_mail(payload, mail)
324
393
  new.receive(mail)
@@ -330,7 +399,7 @@ module ActionMailer #:nodoc:
330
399
  # when you call <tt>:deliver</tt> on the Mail::Message, calling +deliver_mail+ directly
331
400
  # and passing a Mail::Message will do nothing except tell the logger you sent the email.
332
401
  def deliver_mail(mail) #:nodoc:
333
- ActiveSupport::Notifications.instrument("action_mailer.deliver") do |payload|
402
+ ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
334
403
  self.set_payload_for_mail(payload, mail)
335
404
  yield # Let Mail do the delivery actions
336
405
  end
@@ -382,17 +451,17 @@ module ActionMailer #:nodoc:
382
451
 
383
452
  # Allows you to pass random and unusual headers to the new +Mail::Message+ object
384
453
  # which will add them to itself.
385
- #
454
+ #
386
455
  # headers['X-Special-Domain-Specific-Header'] = "SecretValue"
387
- #
456
+ #
388
457
  # You can also pass a hash into headers of header field names and values, which
389
458
  # will then be set on the Mail::Message object:
390
- #
459
+ #
391
460
  # headers 'X-Special-Domain-Specific-Header' => "SecretValue",
392
461
  # 'In-Reply-To' => incoming.message_id
393
- #
462
+ #
394
463
  # The resulting Mail::Message will have the following in it's header:
395
- #
464
+ #
396
465
  # X-Special-Domain-Specific-Header: SecretValue
397
466
  def headers(args=nil)
398
467
  if args
@@ -403,46 +472,46 @@ module ActionMailer #:nodoc:
403
472
  end
404
473
 
405
474
  # Allows you to add attachments to an email, like so:
406
- #
475
+ #
407
476
  # mail.attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
408
- #
477
+ #
409
478
  # If you do this, then Mail will take the file name and work out the mime type
410
- # set the Content-Type, Content-Disposition, Content-Transfer-Encoding and
479
+ # set the Content-Type, Content-Disposition, Content-Transfer-Encoding and
411
480
  # base64 encode the contents of the attachment all for you.
412
- #
481
+ #
413
482
  # You can also specify overrides if you want by passing a hash instead of a string:
414
- #
483
+ #
415
484
  # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
416
485
  # :content => File.read('/path/to/filename.jpg')}
417
- #
486
+ #
418
487
  # If you want to use a different encoding than Base64, you can pass an encoding in,
419
488
  # but then it is up to you to pass in the content pre-encoded, and don't expect
420
489
  # Mail to know how to decode this data:
421
- #
490
+ #
422
491
  # file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
423
492
  # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
424
493
  # :encoding => 'SpecialEncoding',
425
494
  # :content => file_content }
426
- #
495
+ #
427
496
  # You can also search for specific attachments:
428
- #
497
+ #
429
498
  # # By Filename
430
499
  # mail.attachments['filename.jpg'] #=> Mail::Part object or nil
431
- #
500
+ #
432
501
  # # or by index
433
502
  # mail.attachments[0] #=> Mail::Part (first attachment)
434
- #
503
+ #
435
504
  def attachments
436
505
  @_message.attachments
437
506
  end
438
507
 
439
508
  # The main method that creates the message and renders the email templates. There are
440
509
  # two ways to call this method, with a block, or without a block.
441
- #
510
+ #
442
511
  # Both methods accept a headers hash. This hash allows you to specify the most used headers
443
512
  # in an email message, these are:
444
- #
445
- # * <tt>:subject</tt> - The subject of the message, if this is omitted, ActionMailer will
513
+ #
514
+ # * <tt>:subject</tt> - The subject of the message, if this is omitted, Action Mailer will
446
515
  # ask the Rails I18n class for a translated <tt>:subject</tt> in the scope of
447
516
  # <tt>[:actionmailer, mailer_scope, action_name]</tt> or if this is missing, will translate the
448
517
  # humanized version of the <tt>action_name</tt>
@@ -455,25 +524,25 @@ module ActionMailer #:nodoc:
455
524
  # addresses, or an array of addresses.
456
525
  # * <tt>:reply_to</tt> - Who to set the Reply-To header of the email to.
457
526
  # * <tt>:date</tt> - The date to say the email was sent on.
458
- #
459
- # You can set default values for any of the above headers (except :date) by using the <tt>default</tt>
527
+ #
528
+ # You can set default values for any of the above headers (except :date) by using the <tt>default</tt>
460
529
  # class method:
461
- #
530
+ #
462
531
  # class Notifier < ActionMailer::Base
463
532
  # self.default :from => 'no-reply@test.lindsaar.net',
464
533
  # :bcc => 'email_logger@test.lindsaar.net',
465
534
  # :reply_to => 'bounces@test.lindsaar.net'
466
535
  # end
467
- #
536
+ #
468
537
  # If you need other headers not listed above, use the <tt>headers['name'] = value</tt> method.
469
538
  #
470
539
  # When a <tt>:return_path</tt> is specified as header, that value will be used as the 'envelope from'
471
540
  # address for the Mail message. Setting this is useful when you want delivery notifications
472
- # sent to a different address than the one in <tt>:from</tt>. Mail will actually use the
541
+ # sent to a different address than the one in <tt>:from</tt>. Mail will actually use the
473
542
  # <tt>:return_path</tt> in preference to the <tt>:sender</tt> in preference to the <tt>:from</tt>
474
543
  # field for the 'envelope from' value.
475
544
  #
476
- # If you do not pass a block to the +mail+ method, it will find all templates in the
545
+ # If you do not pass a block to the +mail+ method, it will find all templates in the
477
546
  # view paths using by default the mailer name and the method name that it is being
478
547
  # called from, it will then create parts for each of these templates intelligently,
479
548
  # making educated guesses on correct content type and sequence, and return a fully
@@ -497,19 +566,19 @@ module ActionMailer #:nodoc:
497
566
  # And now it will look for all templates at "app/views/notifications" with name "another".
498
567
  #
499
568
  # If you do pass a block, you can render specific templates of your choice:
500
- #
569
+ #
501
570
  # mail(:to => 'mikel@test.lindsaar.net') do |format|
502
571
  # format.text
503
572
  # format.html
504
573
  # end
505
- #
574
+ #
506
575
  # You can even render text directly without using a template:
507
- #
576
+ #
508
577
  # mail(:to => 'mikel@test.lindsaar.net') do |format|
509
578
  # format.text { render :text => "Hello Mikel!" }
510
579
  # format.html { render :text => "<h1>Hello Mikel!</h1>" }
511
580
  # end
512
- #
581
+ #
513
582
  # Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
514
583
  # <tt>text/html</tt> parts.
515
584
  #
@@ -530,8 +599,13 @@ module ActionMailer #:nodoc:
530
599
  content_type = headers[:content_type]
531
600
  parts_order = headers[:parts_order]
532
601
 
602
+ # Call all the procs (if any)
603
+ default_values = self.class.default.merge(self.class.default) do |k,v|
604
+ v.respond_to?(:call) ? v.bind(self).call : v
605
+ end
606
+
533
607
  # Handle defaults
534
- headers = headers.reverse_merge(self.class.default)
608
+ headers = headers.reverse_merge(default_values)
535
609
  headers[:subject] ||= default_i18n_subject
536
610
 
537
611
  # Apply charset at the beginning so all fields are properly quoted
@@ -541,7 +615,7 @@ module ActionMailer #:nodoc:
541
615
  wrap_delivery_behavior!(headers.delete(:delivery_method))
542
616
 
543
617
  # Assign all headers except parts_order, content_type and body
544
- assignable = headers.except(:parts_order, :content_type, :body)
618
+ assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
545
619
  assignable.each { |k, v| m[k] = v }
546
620
 
547
621
  # Render the templates and blocks
@@ -569,7 +643,11 @@ module ActionMailer #:nodoc:
569
643
  when user_content_type.present?
570
644
  user_content_type
571
645
  when m.has_attachments?
572
- ["multipart", "mixed", params]
646
+ if m.attachments.detect { |a| a.inline? }
647
+ ["multipart", "related", params]
648
+ else
649
+ ["multipart", "mixed", params]
650
+ end
573
651
  when m.multipart?
574
652
  ["multipart", "alternative", params]
575
653
  else
@@ -643,5 +721,28 @@ module ActionMailer #:nodoc:
643
721
  container.add_part(part)
644
722
  end
645
723
 
724
+ module DeprecatedUrlOptions
725
+ def default_url_options
726
+ deprecated_url_options
727
+ end
728
+
729
+ def default_url_options=(val)
730
+ deprecated_url_options
731
+ end
732
+
733
+ def deprecated_url_options
734
+ raise "You can no longer call ActionMailer::Base.default_url_options " \
735
+ "directly. You need to set config.action_mailer.default_url_options. " \
736
+ "If you are using ActionMailer standalone, you need to include the " \
737
+ "url_helpers of a router directly."
738
+ end
739
+ end
740
+
741
+ # This module will complain if the user tries to set default_url_options
742
+ # directly instead of through the config object. In ActionMailer's Railtie,
743
+ # we include the url_helpers of the router, which will override this module
744
+ extend DeprecatedUrlOptions
745
+
746
+ ActiveSupport.run_load_hooks(:action_mailer, self)
646
747
  end
647
748
  end
@@ -3,6 +3,13 @@ module ActionMailer
3
3
  # Uses Text::Format to take the text and format it, indented two spaces for
4
4
  # each line, and wrapped at 72 columns.
5
5
  def block_format(text)
6
+ begin
7
+ require 'text/format'
8
+ rescue LoadError => e
9
+ $stderr.puts "You don't have text-format installed in your application. Please add it to your Gemfile and run bundle install"
10
+ raise e
11
+ end unless defined?(Text::Format)
12
+
6
13
  formatted = text.split(/\n\r\n/).collect { |paragraph|
7
14
  Text::Format.new(
8
15
  :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
@@ -25,5 +32,10 @@ module ActionMailer
25
32
  def message
26
33
  @_message
27
34
  end
35
+
36
+ # Access the message attachments list.
37
+ def attachments
38
+ @_message.attachments
39
+ end
28
40
  end
29
41
  end
@@ -1,3 +1,4 @@
1
+ require 'active_support/concern'
1
2
  require 'active_support/core_ext/object/try'
2
3
  require 'active_support/core_ext/object/blank'
3
4
 
@@ -5,10 +5,6 @@ module ActionMailer
5
5
  class Railtie < Rails::Railtie
6
6
  config.action_mailer = ActiveSupport::OrderedOptions.new
7
7
 
8
- initializer "action_mailer.url_for", :before => :load_environment_config do |app|
9
- ActiveSupport.on_load(:action_mailer) { include app.routes.url_helpers }
10
- end
11
-
12
8
  require "action_mailer/railties/log_subscriber"
13
9
  log_subscriber :action_mailer, ActionMailer::Railties::LogSubscriber.new
14
10
 
@@ -17,7 +13,18 @@ module ActionMailer
17
13
  end
18
14
 
19
15
  initializer "action_mailer.set_configs" do |app|
16
+ paths = app.config.paths
17
+ am = app.config.action_mailer
18
+
19
+ am.assets_dir ||= paths.public.to_a.first
20
+ am.javascripts_dir ||= paths.public.javascripts.to_a.first
21
+ am.stylesheets_dir ||= paths.public.stylesheets.to_a.first
22
+
20
23
  ActiveSupport.on_load(:action_mailer) do
24
+ self.config.merge!(am)
25
+
26
+ include app.routes.url_helpers
27
+
21
28
  app.config.action_mailer.each do |k,v|
22
29
  send "#{k}=", v
23
30
  end
@@ -3,7 +3,7 @@ module ActionMailer
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
5
  TINY = 0
6
- BUILD = "beta3"
6
+ BUILD = "beta4"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
9
9
  end
@@ -0,0 +1,15 @@
1
+ Description:
2
+ Stubs out a new mailer and its views. Pass the mailer name, either
3
+ CamelCased or under_scored, and an optional list of emails as arguments.
4
+
5
+ This generates a mailer class in app/mailers and invokes your template
6
+ engine and test framework generators.
7
+
8
+ Example:
9
+ `rails generate mailer Notifications signup forgot_password invoice`
10
+
11
+ creates a Notifications mailer class, views, test, and fixtures:
12
+ Mailer: app/mailers/notifications.rb
13
+ Views: app/views/notifications/signup.erb [...]
14
+ Test: test/functional/notifications_test.rb
15
+ Fixtures: test/fixtures/notifications/signup [...]
@@ -0,0 +1,16 @@
1
+ module Rails
2
+ module Generators
3
+ class MailerGenerator < NamedBase
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ argument :actions, :type => :array, :default => [], :banner => "method method"
7
+ check_class_collision
8
+
9
+ def create_mailer_file
10
+ template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}.rb")
11
+ end
12
+
13
+ hook_for :template_engine, :test_framework
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ class <%= class_name %> < ActionMailer::Base
2
+ default :from => "from@example.com"
3
+ <% for action in actions -%>
4
+
5
+ # Subject can be set in your I18n file at config/locales/en.yml
6
+ # with the following lookup:
7
+ #
8
+ # en.actionmailer.<%= file_name %>.<%= action %>.subject
9
+ #
10
+ def <%= action %>
11
+ @greeting = "Hi"
12
+
13
+ mail :to => "to@example.org"
14
+ end
15
+ <% end -%>
16
+ end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 3
7
7
  - 0
8
8
  - 0
9
- - beta3
10
- version: 3.0.0.beta3
9
+ - beta4
10
+ version: 3.0.0.beta4
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Heinemeier Hansson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-13 00:00:00 -07:00
18
+ date: 2010-06-08 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -29,8 +29,8 @@ dependencies:
29
29
  - 3
30
30
  - 0
31
31
  - 0
32
- - beta3
33
- version: 3.0.0.beta3
32
+ - beta4
33
+ version: 3.0.0.beta4
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
@@ -43,24 +43,10 @@ dependencies:
43
43
  segments:
44
44
  - 2
45
45
  - 2
46
- - 0
47
- version: 2.2.0
46
+ - 3
47
+ version: 2.2.3
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: text-format
52
- prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- requirements:
55
- - - ~>
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 1
59
- - 0
60
- - 0
61
- version: 1.0.0
62
- type: :runtime
63
- version_requirements: *id003
64
50
  description: Email on Rails. Compose, deliver, receive, and test emails using the familiar controller/view pattern. First-class support for multipart email and attachments.
65
51
  email: david@loudthinking.com
66
52
  executables: []
@@ -87,6 +73,9 @@ files:
87
73
  - lib/action_mailer/tmail_compat.rb
88
74
  - lib/action_mailer/version.rb
89
75
  - lib/action_mailer.rb
76
+ - lib/rails/generators/mailer/mailer_generator.rb
77
+ - lib/rails/generators/mailer/templates/mailer.rb
78
+ - lib/rails/generators/mailer/USAGE
90
79
  has_rdoc: true
91
80
  homepage: http://www.rubyonrails.org
92
81
  licenses: []