actionmailer 4.0.13 → 4.1.0.beta1

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: 814ae49361a765b14f20ab4ee63f488db350f5e8
4
- data.tar.gz: 83b912bb6a7400aab9269490f052f1f85d776184
3
+ metadata.gz: 66fdea8138adbbf1916cfd7ae7c84778ea9d4cbf
4
+ data.tar.gz: aa44f5061ef399d6d464abaf6afc8278fa90a4b0
5
5
  SHA512:
6
- metadata.gz: 23359cdb11af5cf267f72864407b58acc85192a8f1b2528f57d572df8000fd32fdc063c5ab52ec1a380e724bc1cc70021a4fb66c47d19768ad1dc8a02b853391
7
- data.tar.gz: 8bf92eacb7884044e67ad0ad389724e34f78a233782f13a8160958c4844068ba352688393f31b139bdd489cc4496fcf7add2c426faba5c20ea8d732c13958589
6
+ metadata.gz: 113c0cf26324e04ccb9b8c96b9ae0c1c552155145b0670b6d90eda78ac23b768f9939b3e157c95effcc9bc3369f9027db9bafd87d66371eb68e6ea3e5e69a726
7
+ data.tar.gz: 33358816dccafbe1f37f35716db4936f319efba0d0c4dfbe1b87838f90b4e00a94f507ee6c67e6133d8404ff380b9b96e00d91dbe890097ac279af5613b349cd
@@ -1,54 +1,6 @@
1
- ## Rails 4.0.13 (January 6, 2015) ##
1
+ * Add mailer previews feature based on 37 Signals mail_view gem
2
2
 
3
- *No changes*
4
-
5
-
6
- ## Rails 4.0.12 (November 16, 2014) ##
7
-
8
- *No changes*
9
-
10
-
11
- ## Rails 4.0.11.1 (November 19, 2014) ##
12
-
13
- *No changes*
14
-
15
-
16
- ## Rails 4.0.11 (September 11, 2014) ##
17
-
18
- *No changes*
19
-
20
-
21
- ## Rails 4.0.10 (September 11, 2014) ##
22
-
23
- *No changes*
24
-
25
-
26
- ## Rails 4.0.9 (August 18, 2014) ##
27
-
28
- *No changes*
29
-
30
-
31
- ## Rails 4.0.8 (July 2, 2014) ##
32
-
33
- *No changes*
34
-
35
-
36
- ## Rails 4.0.7 (July 2, 2014) ##
37
-
38
- *No changes*
39
-
40
-
41
- ## Rails 4.0.6 (June 26, 2014) ##
42
-
43
- *No changes*
44
-
45
-
46
- ## Rails 4.0.5 (May 6, 2014) ##
47
-
48
- *No changes*
49
-
50
-
51
- ## Rails 4.0.4 (March 14, 2014) ##
3
+ *Andrew White*
52
4
 
53
5
  * Calling `mail()` without arguments serves as getter for the current mail
54
6
  message and keeps previously set headers.
@@ -69,87 +21,17 @@
69
21
 
70
22
  *Yves Senn*
71
23
 
72
-
73
- ## Rails 4.0.3 (February 18, 2014) ##
74
-
75
- *No changes*
76
-
77
-
78
- ## Rails 4.0.2 (December 02, 2013) ##
79
-
80
- *No changes*
81
-
82
-
83
- ## Rails 4.0.1 (November 01, 2013) ##
84
-
85
24
  * Instrument the generation of Action Mailer messages. The time it takes to
86
25
  generate a message is written to the log.
87
26
 
88
- * Invoke mailer defaults as procs only if they are procs, do not convert
89
- with `to_proc`. That an object is convertible to a proc does not mean it's
90
- meant to be always used as a proc.
27
+ *Daniel Schierbeck*
28
+
29
+ * Invoke mailer defaults as procs only if they are procs, do not convert with
30
+ `to_proc`. That an object is convertible to a proc does not mean it's meant
31
+ to be always used as a proc.
91
32
 
92
33
  Fixes #11533.
93
34
 
94
35
  *Alex Tsukernik*
95
36
 
96
-
97
- ## Rails 4.0.0 (June 25, 2013) ##
98
-
99
- * Allow passing interpolations to `#default_i18n_subject`, e.g.:
100
-
101
- # config/locales/en.yml
102
- en:
103
- user_mailer:
104
- welcome:
105
- subject: 'Hello, %{username}'
106
-
107
- # app/mailers/user_mailer.rb
108
- class UserMailer < ActionMailer::Base
109
- def welcome(user)
110
- mail(subject: default_i18n_subject(username: user.name))
111
- end
112
- end
113
-
114
- *Olek Janiszewski*
115
-
116
- * Eager loading made to use relation's `in_clause_length` instead of host's one.
117
- Fixes #8474.
118
-
119
- *Boris Staal*
120
-
121
- * Explicit multipart messages no longer set the order of the MIME parts.
122
-
123
- *Nate Berkopec*
124
-
125
- * Do not render views when `mail` isn't called. Fixes #7761.
126
-
127
- *Yves Senn*
128
-
129
- * Allow delivery method options to be set per mail instance.
130
-
131
- If your SMTP delivery settings are dynamic, you can now override settings
132
- per mail instance for e.g.
133
-
134
- def my_mailer(user, company)
135
- mail to: user.email, subject: "Welcome!",
136
- delivery_method_options: { user_name: company.smtp_user,
137
- password: company.smtp_password }
138
- end
139
-
140
- This will ensure that your default SMTP settings will be overridden
141
- by the company specific ones. You only have to override the settings
142
- that are dynamic and leave the static setting in your environment
143
- configuration file (e.g. `config/environments/production.rb`).
144
-
145
- *Aditya Sanghi*
146
-
147
- * Allow to set default Action Mailer options via `config.action_mailer.default_options=`. *Robert Pankowecki*
148
-
149
- * Raise an `ActionView::MissingTemplate` exception when no implicit template could be found. *Damien Mathieu*
150
-
151
- * Allow callbacks to be defined in mailers similar to `ActionController::Base`. You can configure default
152
- settings, headers, attachments, delivery settings or change delivery using
153
- `before_filter`, `after_filter`, etc. *Justin S. Leitgeb*
154
-
155
- Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/actionmailer/CHANGELOG.md) for previous changes.
37
+ Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/actionmailer/CHANGELOG.md) for previous changes.
@@ -61,9 +61,7 @@ generated would look like this:
61
61
 
62
62
  Thank you for signing up!
63
63
 
64
- In previous version of Rails you would call <tt>create_method_name</tt> and
65
- <tt>deliver_method_name</tt>. Rails 3.0 has a much simpler interface - you
66
- simply call the method and optionally call +deliver+ on the return value.
64
+ In order to send mails, you simply call the method and then call +deliver+ on the return value.
67
65
 
68
66
  Calling the method returns a Mail Message object:
69
67
 
@@ -76,7 +74,7 @@ Or you can just chain the methods together like:
76
74
 
77
75
  == Setting defaults
78
76
 
79
- It is possible to set default values that will be used in every method in your Action Mailer class. To implement this functionality, you just call the public class method <tt>default</tt> which you get for free from ActionMailer::Base. This method accepts a Hash as the parameter. You can use any of the headers e-mail messages has, like <tt>:from</tt> as the key. You can also pass in a string as the key, like "Content-Type", but Action Mailer does this out of the box for you, so you won't need to worry about that. Finally, it is also possible to pass in a Proc that will get evaluated when it is needed.
77
+ It is possible to set default values that will be used in every method in your Action Mailer class. To implement this functionality, you just call the public class method <tt>default</tt> which you get for free from <tt>ActionMailer::Base</tt>. This method accepts a Hash as the parameter. You can use any of the headers e-mail messages has, like <tt>:from</tt> as the key. You can also pass in a string as the key, like "Content-Type", but Action Mailer does this out of the box for you, so you won't need to worry about that. Finally, it is also possible to pass in a Proc that will get evaluated when it is needed.
80
78
 
81
79
  Note that every value you set with this method will get overwritten if you use the same key in your mailer method.
82
80
 
@@ -142,7 +140,7 @@ The latest version of Action Mailer can be installed with RubyGems:
142
140
 
143
141
  Source code can be downloaded as part of the Rails project on GitHub
144
142
 
145
- * https://github.com/rails/rails/tree/4-0-stable/actionmailer
143
+ * https://github.com/rails/rails/tree/master/actionmailer
146
144
 
147
145
 
148
146
  == License
@@ -22,7 +22,6 @@
22
22
  #++
23
23
 
24
24
  require 'abstract_controller'
25
- require 'action_view'
26
25
  require 'action_mailer/version'
27
26
 
28
27
  # Common Active Support usage in Action Mailer
@@ -42,6 +41,8 @@ module ActionMailer
42
41
  autoload :Base
43
42
  autoload :DeliveryMethods
44
43
  autoload :MailHelper
44
+ autoload :Preview
45
+ autoload :Previews, 'action_mailer/preview'
45
46
  autoload :TestCase
46
47
  autoload :TestHelper
47
48
  end
@@ -3,6 +3,7 @@ require 'action_mailer/collector'
3
3
  require 'active_support/core_ext/string/inflections'
4
4
  require 'active_support/core_ext/hash/except'
5
5
  require 'active_support/core_ext/module/anonymous'
6
+
6
7
  require 'action_mailer/log_subscriber'
7
8
 
8
9
  module ActionMailer
@@ -151,9 +152,9 @@ module ActionMailer
151
152
  #
152
153
  # For example, if the following templates exist:
153
154
  # * signup_notification.text.erb
154
- # * signup_notification.text.html.erb
155
- # * signup_notification.text.xml.builder
156
- # * signup_notification.text.yaml.erb
155
+ # * signup_notification.html.erb
156
+ # * signup_notification.xml.builder
157
+ # * signup_notification.yaml.erb
157
158
  #
158
159
  # Each would be rendered and added as a separate part to the message, with the corresponding content
159
160
  # type. The content type for the entire message is automatically set to <tt>multipart/alternative</tt>,
@@ -175,7 +176,7 @@ module ActionMailer
175
176
  # end
176
177
  # end
177
178
  #
178
- # Which will (if it had both a <tt>welcome.text.erb</tt> and <tt>welcome.text.html.erb</tt>
179
+ # Which will (if it had both a <tt>welcome.text.erb</tt> and <tt>welcome.html.erb</tt>
179
180
  # template in the view directory), send a complete <tt>multipart/mixed</tt> email with two parts,
180
181
  # the first part being a <tt>multipart/alternative</tt> with the text and HTML email parts inside,
181
182
  # and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
@@ -307,6 +308,25 @@ module ActionMailer
307
308
  # Note that unless you have a specific reason to do so, you should prefer using before_action
308
309
  # rather than after_action in your ActionMailer classes so that headers are parsed properly.
309
310
  #
311
+ # = Previewing emails
312
+ #
313
+ # You can preview your email templates visually by adding a mailer preview file to the
314
+ # <tt>ActionMailer::Base.preview_path</tt>. Since most emails do something interesting
315
+ # with database data, you'll need to write some scenarios to load messages with fake data:
316
+ #
317
+ # class NotifierPreview < ActionMailer::Preview
318
+ # def welcome
319
+ # Notifier.welcome(User.first)
320
+ # end
321
+ # end
322
+ #
323
+ # Methods must return a Mail::Message object which can be generated by calling the mailer
324
+ # method without the additional <tt>deliver</tt>. The location of the mailer previews
325
+ # directory can be configured using the <tt>preview_path</tt> option which has a default
326
+ # of <tt>test/mailers/previews</tt>:
327
+ #
328
+ # config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
329
+ #
310
330
  # = Configuration options
311
331
  #
312
332
  # These options are specified on the class level, like
@@ -361,17 +381,25 @@ module ActionMailer
361
381
  # <tt>delivery_method :test</tt>. Most useful for unit and functional testing.
362
382
  class Base < AbstractController::Base
363
383
  include DeliveryMethods
384
+ include Previews
385
+
364
386
  abstract!
365
387
 
366
- include AbstractController::Logger
367
388
  include AbstractController::Rendering
368
- include AbstractController::Layouts
389
+
390
+ include AbstractController::Logger
369
391
  include AbstractController::Helpers
370
392
  include AbstractController::Translation
371
393
  include AbstractController::AssetPaths
372
394
  include AbstractController::Callbacks
373
395
 
374
- self.protected_instance_variables = [:@_action_has_layout]
396
+ include ActionView::Layouts
397
+
398
+ PROTECTED_IVARS = AbstractController::Rendering::DEFAULT_PROTECTED_INSTANCE_VARIABLES + [:@_action_has_layout]
399
+
400
+ def _protected_ivars # :nodoc:
401
+ PROTECTED_IVARS
402
+ end
375
403
 
376
404
  helper ActionMailer::MailHelper
377
405
 
@@ -398,7 +426,7 @@ module ActionMailer
398
426
 
399
427
  # Register an Observer which will be notified when mail is delivered.
400
428
  # Either a class or a string can be passed in as the Observer. If a string is passed in
401
- # it will be <tt>constantize</tt>d.
429
+ # it will be +constantize+d.
402
430
  def register_observer(observer)
403
431
  delivery_observer = (observer.is_a?(String) ? observer.constantize : observer)
404
432
  Mail.register_observer(delivery_observer)
@@ -412,12 +440,20 @@ module ActionMailer
412
440
  Mail.register_interceptor(delivery_interceptor)
413
441
  end
414
442
 
443
+ # Returns the name of current mailer. This method is also being used as a path for a view lookup.
444
+ # If this is an anonymous mailer, this method will return +anonymous+ instead.
415
445
  def mailer_name
416
446
  @mailer_name ||= anonymous? ? "anonymous" : name.underscore
417
447
  end
448
+ # Allows to set the name of current mailer.
418
449
  attr_writer :mailer_name
419
450
  alias :controller_path :mailer_name
420
451
 
452
+ # Sets the defaults through app configuration:
453
+ #
454
+ # config.action_mailer.default { from: "no-reply@example.org" }
455
+ #
456
+ # Aliased by ::default_options=
421
457
  def default(value = nil)
422
458
  self.default_params = default_params.merge(value).freeze if value
423
459
  default_params
@@ -429,13 +465,15 @@ module ActionMailer
429
465
 
430
466
  # Receives a raw email, parses it into an email object, decodes it,
431
467
  # instantiates a new mailer, and passes the email object to the mailer
432
- # object's +receive+ method. If you want your mailer to be able to
433
- # process incoming messages, you'll need to implement a +receive+
434
- # method that accepts the raw email string as a parameter:
468
+ # object's +receive+ method.
469
+ #
470
+ # If you want your mailer to be able to process incoming messages, you'll
471
+ # need to implement a +receive+ method that accepts the raw email string
472
+ # as a parameter:
435
473
  #
436
474
  # class MyMailer < ActionMailer::Base
437
475
  # def receive(mail)
438
- # ...
476
+ # # ...
439
477
  # end
440
478
  # end
441
479
  def receive(raw_mail)
@@ -446,10 +484,12 @@ module ActionMailer
446
484
  end
447
485
  end
448
486
 
449
- # Wraps an email delivery inside of Active Support Notifications instrumentation. This
450
- # method is actually called by the <tt>Mail::Message</tt> object itself through a callback
451
- # when you call <tt>:deliver</tt> on the Mail::Message, calling +deliver_mail+ directly
452
- # and passing a Mail::Message will do nothing except tell the logger you sent the email.
487
+ # Wraps an email delivery inside of ActiveSupport::Notifications instrumentation.
488
+ #
489
+ # This method is actually called by the Mail::Message object itself
490
+ # through a callback when you call +:deliver+ on the Mail::Message,
491
+ # calling +deliver_mail+ directly and passing a Mail::Message will do
492
+ # nothing except tell the logger you sent the email.
453
493
  def deliver_mail(mail) #:nodoc:
454
494
  ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
455
495
  set_payload_for_mail(payload, mail)
@@ -475,7 +515,7 @@ module ActionMailer
475
515
  payload[:mail] = mail.encoded
476
516
  end
477
517
 
478
- def method_missing(method_name, *args)
518
+ def method_missing(method_name, *args) # :nodoc:
479
519
  if respond_to?(method_name)
480
520
  new(method_name, *args).message
481
521
  else
@@ -497,11 +537,18 @@ module ActionMailer
497
537
  process(method_name, *args) if method_name
498
538
  end
499
539
 
500
- def process(*args) #:nodoc:
501
- lookup_context.skip_default_locale!
540
+ def process(method_name, *args) #:nodoc:
541
+ payload = {
542
+ mailer: self.class.name,
543
+ action: method_name
544
+ }
545
+
546
+ ActiveSupport::Notifications.instrument("process.action_mailer", payload) do
547
+ lookup_context.skip_default_locale!
502
548
 
503
- super
504
- @_message = NullMail.new unless @_mail_was_called
549
+ super
550
+ @_message = NullMail.new unless @_mail_was_called
551
+ end
505
552
  end
506
553
 
507
554
  class NullMail #:nodoc:
@@ -512,17 +559,18 @@ module ActionMailer
512
559
  end
513
560
  end
514
561
 
562
+ # Returns the name of the mailer object.
515
563
  def mailer_name
516
564
  self.class.mailer_name
517
565
  end
518
566
 
519
- # Allows you to pass random and unusual headers to the new <tt>Mail::Message</tt> object
520
- # which will add them to itself.
567
+ # Allows you to pass random and unusual headers to the new Mail::Message
568
+ # object which will add them to itself.
521
569
  #
522
570
  # headers['X-Special-Domain-Specific-Header'] = "SecretValue"
523
571
  #
524
- # You can also pass a hash into headers of header field names and values, which
525
- # will then be set on the Mail::Message object:
572
+ # You can also pass a hash into headers of header field names and values,
573
+ # which will then be set on the Mail::Message object:
526
574
  #
527
575
  # headers 'X-Special-Domain-Specific-Header' => "SecretValue",
528
576
  # 'In-Reply-To' => incoming.message_id
@@ -578,22 +626,22 @@ module ActionMailer
578
626
  # Both methods accept a headers hash. This hash allows you to specify the most used headers
579
627
  # in an email message, these are:
580
628
  #
581
- # * <tt>:subject</tt> - The subject of the message, if this is omitted, Action Mailer will
582
- # ask the Rails I18n class for a translated <tt>:subject</tt> in the scope of
629
+ # * +:subject+ - The subject of the message, if this is omitted, Action Mailer will
630
+ # ask the Rails I18n class for a translated +:subject+ in the scope of
583
631
  # <tt>[mailer_scope, action_name]</tt> or if this is missing, will translate the
584
- # humanized version of the <tt>action_name</tt>
585
- # * <tt>:to</tt> - Who the message is destined for, can be a string of addresses, or an array
632
+ # humanized version of the +action_name+
633
+ # * +:to+ - Who the message is destined for, can be a string of addresses, or an array
586
634
  # of addresses.
587
- # * <tt>:from</tt> - Who the message is from
588
- # * <tt>:cc</tt> - Who you would like to Carbon-Copy on this email, can be a string of addresses,
635
+ # * +:from+ - Who the message is from
636
+ # * +:cc+ - Who you would like to Carbon-Copy on this email, can be a string of addresses,
589
637
  # or an array of addresses.
590
- # * <tt>:bcc</tt> - Who you would like to Blind-Carbon-Copy on this email, can be a string of
638
+ # * +:bcc+ - Who you would like to Blind-Carbon-Copy on this email, can be a string of
591
639
  # addresses, or an array of addresses.
592
- # * <tt>:reply_to</tt> - Who to set the Reply-To header of the email to.
593
- # * <tt>:date</tt> - The date to say the email was sent on.
640
+ # * +:reply_to+ - Who to set the Reply-To header of the email to.
641
+ # * +:date+ - The date to say the email was sent on.
594
642
  #
595
- # You can set default values for any of the above headers (except :date) by using the <tt>default</tt>
596
- # class method:
643
+ # You can set default values for any of the above headers (except +:date+)
644
+ # by using the ::default class method:
597
645
  #
598
646
  # class Notifier < ActionMailer::Base
599
647
  # default from: 'no-reply@test.lindsaar.net',
@@ -605,17 +653,19 @@ module ActionMailer
605
653
  # as part of the headers hash or use the <tt>headers['name'] = value</tt>
606
654
  # method.
607
655
  #
608
- # When a <tt>:return_path</tt> is specified as header, that value will be used as the 'envelope from'
609
- # address for the Mail message. Setting this is useful when you want delivery notifications
610
- # sent to a different address than the one in <tt>:from</tt>. Mail will actually use the
611
- # <tt>:return_path</tt> in preference to the <tt>:sender</tt> in preference to the <tt>:from</tt>
612
- # field for the 'envelope from' value.
656
+ # When a +:return_path+ is specified as header, that value will be used as
657
+ # the 'envelope from' address for the Mail message. Setting this is useful
658
+ # when you want delivery notifications sent to a different address than the
659
+ # one in +:from+. Mail will actually use the +:return_path+ in preference
660
+ # to the +:sender+ in preference to the +:from+ field for the 'envelope
661
+ # from' value.
613
662
  #
614
- # If you do not pass a block to the +mail+ method, it will find all templates in the
615
- # view paths using by default the mailer name and the method name that it is being
616
- # called from, it will then create parts for each of these templates intelligently,
617
- # making educated guesses on correct content type and sequence, and return a fully
618
- # prepared Mail::Message ready to call <tt>:deliver</tt> on to send.
663
+ # If you do not pass a block to the +mail+ method, it will find all
664
+ # templates in the view paths using by default the mailer name and the
665
+ # method name that it is being called from, it will then create parts for
666
+ # each of these templates intelligently, making educated guesses on correct
667
+ # content type and sequence, and return a fully prepared Mail::Message
668
+ # ready to call +:deliver+ on to send.
619
669
  #
620
670
  # For example:
621
671
  #
@@ -650,8 +700,8 @@ module ActionMailer
650
700
  # format.html { render text: "<h1>Hello Mikel!</h1>" }
651
701
  # end
652
702
  #
653
- # Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
654
- # <tt>text/html</tt> parts.
703
+ # Which will render a +multipart/alternative+ email with +text/plain+ and
704
+ # +text/html+ parts.
655
705
  #
656
706
  # The block syntax also allows you to customize the part headers if desired:
657
707
  #
@@ -670,9 +720,9 @@ module ActionMailer
670
720
  content_type = headers[:content_type]
671
721
 
672
722
  # Call all the procs (if any)
673
- class_default = self.class.default
674
- default_values = class_default.merge(class_default) do |k,v|
675
- v.is_a?(Proc) ? instance_eval(&v) : v
723
+ default_values = {}
724
+ self.class.default.each do |k,v|
725
+ default_values[k] = v.is_a?(Proc) ? instance_eval(&v) : v
676
726
  end
677
727
 
678
728
  # Handle defaults
@@ -707,6 +757,15 @@ module ActionMailer
707
757
 
708
758
  protected
709
759
 
760
+ # Used by #mail to set the content type of the message.
761
+ #
762
+ # It will use the given +user_content_type+, or multipart if the mail
763
+ # message has any attachments. If the attachments are inline, the content
764
+ # type will be "multipart/related", otherwise "multipart/mixed".
765
+ #
766
+ # If there is no content type passed in via headers, and there are no
767
+ # attachments, or the message is multipart, then the default content type is
768
+ # used.
710
769
  def set_content_type(m, user_content_type, class_default)
711
770
  params = m.content_type_parameters || {}
712
771
  case
@@ -38,6 +38,7 @@ module ActionMailer
38
38
  add_delivery_method :test, Mail::TestMailer
39
39
  end
40
40
 
41
+ # Helpers for creating and wrapping delivery behavior, used by DeliveryMethods.
41
42
  module ClassMethods
42
43
  # Provides a list of emails that have been delivered by Mail::TestMailer
43
44
  delegate :deliveries, :deliveries=, to: Mail::TestMailer
@@ -1,5 +1,10 @@
1
+ require 'active_support/log_subscriber'
2
+
1
3
  module ActionMailer
4
+ # Implements the ActiveSupport::LogSubscriber for logging notifications when
5
+ # email is delivered and received.
2
6
  class LogSubscriber < ActiveSupport::LogSubscriber
7
+ # An email was delivered.
3
8
  def deliver(event)
4
9
  return unless logger.info?
5
10
  recipients = Array(event.payload[:to]).join(', ')
@@ -7,12 +12,21 @@ module ActionMailer
7
12
  debug(event.payload[:mail])
8
13
  end
9
14
 
15
+ # An email was received.
10
16
  def receive(event)
11
17
  return unless logger.info?
12
18
  info("\nReceived mail (#{event.duration.round(1)}ms)")
13
19
  debug(event.payload[:mail])
14
20
  end
15
21
 
22
+ # An email was generated.
23
+ def process(event)
24
+ mailer = event.payload[:mailer]
25
+ action = event.payload[:action]
26
+ debug("\n#{mailer}##{action}: processed outbound mail in #{event.duration.round(1)}ms")
27
+ end
28
+
29
+ # Use the logger configured for ActionMailer::Base
16
30
  def logger
17
31
  ActionMailer::Base.logger
18
32
  end
@@ -1,4 +1,7 @@
1
1
  module ActionMailer
2
+ # Provides helper methods for ActionMailer::Base that can be used for easily
3
+ # formatting messages, accessing mailer or message instances, and the
4
+ # attachments list.
2
5
  module MailHelper
3
6
  # Take the text and format it, indented two spaces for each line, and
4
7
  # wrapped at 72 columns.
@@ -46,8 +49,9 @@ module ActionMailer
46
49
  end
47
50
  end
48
51
 
49
- sentences.map { |sentence|
50
- "#{" " * indent}#{sentence.join(' ')}"
52
+ indentation = " " * indent
53
+ sentences.map! { |sentence|
54
+ "#{indentation}#{sentence.join(' ')}"
51
55
  }.join "\n"
52
56
  end
53
57
  end
@@ -0,0 +1,67 @@
1
+ require 'active_support/descendants_tracker'
2
+
3
+ module ActionMailer
4
+ module Previews #:nodoc:
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ # Set the location of mailer previews through app configuration:
9
+ #
10
+ # config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
11
+ #
12
+ class_attribute :preview_path, instance_writer: false
13
+ end
14
+ end
15
+
16
+ class Preview
17
+ extend ActiveSupport::DescendantsTracker
18
+
19
+ class << self
20
+ # Returns all mailer preview classes
21
+ def all
22
+ load_previews if descendants.empty?
23
+ descendants
24
+ end
25
+
26
+ # Returns the mail object for the given email name
27
+ def call(email)
28
+ preview = self.new
29
+ preview.public_send(email)
30
+ end
31
+
32
+ # Returns all of the available email previews
33
+ def emails
34
+ public_instance_methods(false).map(&:to_s).sort
35
+ end
36
+
37
+ # Returns true if the email exists
38
+ def email_exists?(email)
39
+ emails.include?(email)
40
+ end
41
+
42
+ # Returns true if the preview exists
43
+ def exists?(preview)
44
+ all.any?{ |p| p.preview_name == preview }
45
+ end
46
+
47
+ # Find a mailer preview by its underscored class name
48
+ def find(preview)
49
+ all.find{ |p| p.preview_name == preview }
50
+ end
51
+
52
+ # Returns the underscored name of the mailer preview without the suffix
53
+ def preview_name
54
+ name.sub(/Preview$/, '').underscore
55
+ end
56
+
57
+ protected
58
+ def load_previews #:nodoc:
59
+ Dir["#{preview_path}/**/*_preview.rb"].each{ |file| require_dependency file }
60
+ end
61
+
62
+ def preview_path #:nodoc:
63
+ Base.preview_path
64
+ end
65
+ end
66
+ end
67
+ end
@@ -40,5 +40,13 @@ module ActionMailer
40
40
  config.compile_methods! if config.respond_to?(:compile_methods!)
41
41
  end
42
42
  end
43
+
44
+ initializer "action_mailer.configure_mailer_previews", before: :set_autoload_paths do |app|
45
+ if Rails.env.development?
46
+ options = app.config.action_mailer
47
+ options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil
48
+ app.config.autoload_paths << options.preview_path
49
+ end
50
+ end
43
51
  end
44
52
  end
@@ -1,7 +1,7 @@
1
1
  module ActionMailer
2
2
  # Returns the version of the currently loaded ActionMailer as a Gem::Version
3
3
  def self.version
4
- Gem::Version.new "4.0.13"
4
+ Gem::Version.new "4.1.0.beta1"
5
5
  end
6
6
 
7
7
  module VERSION #:nodoc:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.13
4
+ version: 4.1.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-06 00:00:00.000000000 Z
11
+ date: 2013-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -16,32 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.13
19
+ version: 4.1.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.13
26
+ version: 4.1.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
- name: mail
28
+ name: actionview
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '2.5'
34
- - - ">="
33
+ version: 4.1.0.beta1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 4.1.0.beta1
41
+ - !ruby/object:Gem::Dependency
42
+ name: mail
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
35
46
  - !ruby/object:Gem::Version
36
47
  version: 2.5.4
37
48
  type: :runtime
38
49
  prerelease: false
39
50
  version_requirements: !ruby/object:Gem::Requirement
40
51
  requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '2.5'
44
- - - ">="
52
+ - - ~>
45
53
  - !ruby/object:Gem::Version
46
54
  version: 2.5.4
47
55
  description: Email on Rails. Compose, deliver, receive, and test emails using the
@@ -52,21 +60,22 @@ extensions: []
52
60
  extra_rdoc_files: []
53
61
  files:
54
62
  - CHANGELOG.md
55
- - MIT-LICENSE
56
63
  - README.rdoc
57
- - lib/action_mailer.rb
64
+ - MIT-LICENSE
58
65
  - lib/action_mailer/base.rb
59
66
  - lib/action_mailer/collector.rb
60
67
  - lib/action_mailer/delivery_methods.rb
61
68
  - lib/action_mailer/log_subscriber.rb
62
69
  - lib/action_mailer/mail_helper.rb
70
+ - lib/action_mailer/preview.rb
63
71
  - lib/action_mailer/railtie.rb
64
72
  - lib/action_mailer/test_case.rb
65
73
  - lib/action_mailer/test_helper.rb
66
74
  - lib/action_mailer/version.rb
67
- - lib/rails/generators/mailer/USAGE
75
+ - lib/action_mailer.rb
68
76
  - lib/rails/generators/mailer/mailer_generator.rb
69
77
  - lib/rails/generators/mailer/templates/mailer.rb
78
+ - lib/rails/generators/mailer/USAGE
70
79
  homepage: http://www.rubyonrails.org
71
80
  licenses:
72
81
  - MIT
@@ -77,18 +86,18 @@ require_paths:
77
86
  - lib
78
87
  required_ruby_version: !ruby/object:Gem::Requirement
79
88
  requirements:
80
- - - ">="
89
+ - - '>='
81
90
  - !ruby/object:Gem::Version
82
91
  version: 1.9.3
83
92
  required_rubygems_version: !ruby/object:Gem::Requirement
84
93
  requirements:
85
- - - ">="
94
+ - - '>'
86
95
  - !ruby/object:Gem::Version
87
- version: '0'
96
+ version: 1.3.1
88
97
  requirements:
89
98
  - none
90
99
  rubyforge_project:
91
- rubygems_version: 2.4.5
100
+ rubygems_version: 2.1.11
92
101
  signing_key:
93
102
  specification_version: 4
94
103
  summary: Email composition, delivery, and receiving framework (part of Rails).