GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Add layout functionality to mailers.

Mailer layouts behaves just like controller layouts, except layout names 
need to
have '_mailer' postfix for them to be automatically picked up.
lifo (author)
Sun Aug 31 11:11:15 -0700 2008
commit  e9a8e0053be3b293ab89fb584f1d660063f107aa
tree    045661abc41c4cc5123735702d57f6897a3787c1
parent  7ce03db77884e21256ba8f1615ad8dd841b76b86
...
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
0
@@ -1,3 +1,8 @@
0
+* Add layout functionality to mailers [Pratik]
0
+
0
+ Mailer layouts behaves just like controller layouts, except layout names need to
0
+ have '_mailer' postfix for them to be automatically picked up.
0
+
0
 *2.1.0 (May 31st, 2008)*
0
 
0
 * Fixed that a return-path header would be ignored #7572 [joost]
...
246
247
248
249
 
 
 
 
250
251
252
...
362
363
364
 
365
366
367
...
530
531
532
 
533
534
535
...
546
547
548
549
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
550
551
552
...
246
247
248
 
249
250
251
252
253
254
255
...
365
366
367
368
369
370
371
...
534
535
536
537
538
539
540
...
551
552
553
 
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
0
@@ -246,7 +246,10 @@ module ActionMailer #:nodoc:
0
   # +implicit_parts_order+.
0
   class Base
0
     include AdvAttrAccessor, PartContainer
0
- include ActionController::UrlWriter if Object.const_defined?(:ActionController)
0
+ if Object.const_defined?(:ActionController)
0
+ include ActionController::UrlWriter
0
+ include ActionController::Layout
0
+ end
0
 
0
     private_class_method :new #:nodoc:
0
 
0
@@ -362,6 +365,7 @@ module ActionMailer #:nodoc:
0
 
0
     # The mail object instance referenced by this mailer.
0
     attr_reader :mail
0
+ attr_reader :template_name, :default_template_name, :action_name
0
 
0
     class << self
0
       attr_writer :mailer_name
0
@@ -530,6 +534,7 @@ module ActionMailer #:nodoc:
0
         @content_type ||= @@default_content_type.dup
0
         @implicit_parts_order ||= @@default_implicit_parts_order.dup
0
         @template ||= method_name
0
+ @default_template_name = @action_name = @template
0
         @mailer_name ||= self.class.name.underscore
0
         @parts ||= []
0
         @headers ||= {}
0
@@ -546,7 +551,22 @@ module ActionMailer #:nodoc:
0
         if opts[:file] && (opts[:file] !~ /\// && !opts[:file].respond_to?(:render))
0
           opts[:file] = "#{mailer_name}/#{opts[:file]}"
0
         end
0
- initialize_template_class(body).render(opts)
0
+
0
+ begin
0
+ old_template, @template = @template, initialize_template_class(body)
0
+ layout = respond_to?(:pick_layout, true) ? pick_layout(opts) : false
0
+ @template.render(opts.merge(:layout => layout))
0
+ ensure
0
+ @template = old_template
0
+ end
0
+ end
0
+
0
+ def default_template_format
0
+ :html
0
+ end
0
+
0
+ def candidate_for_layout?(options)
0
+ !@template.send(:_exempt_from_layout?, default_template_name)
0
       end
0
 
0
       def template_root
...
216
217
218
219
 
220
221
222
...
276
277
278
 
 
 
 
279
280
...
216
217
218
 
219
220
221
222
...
276
277
278
279
280
281
282
283
284
0
@@ -216,7 +216,7 @@ module ActionController #:nodoc:
0
     # object). If the layout was defined without a directory, layouts is assumed. So <tt>layout "weblog/standard"</tt> will return
0
     # weblog/standard, but <tt>layout "standard"</tt> will return layouts/standard.
0
     def active_layout(passed_layout = nil)
0
- layout = passed_layout || self.class.default_layout(response.template.template_format)
0
+ layout = passed_layout || self.class.default_layout(default_template_format)
0
       active_layout = case layout
0
         when String then layout
0
         when Symbol then send!(layout)
0
@@ -276,5 +276,9 @@ module ActionController #:nodoc:
0
       rescue ActionView::MissingTemplate
0
         false
0
       end
0
+
0
+ def default_template_format
0
+ response.template.template_format
0
+ end
0
   end
0
 end

Comments

    No one has commented yet.