public
Fork of rails/rails
Description: Ruby on Rails - forked for implementing I18n patch
Homepage: http://rubyonrails.org
Clone URL: git://github.com/svenfuchs/rails.git
Revert "Revert "Add layout functionality to mailers.""

This reverts commit 36c6aa01ee0a7aee5b0510a8e649c44de318b060.
dhh (author)
Tue Sep 09 15:25:09 -0700 2008
commit  6228220c9b8a3bb32f8617ad2d963dabc965376e
tree    cecf4f2ef0fd7c2747826fd22c56ba8f596ed1c4
parent  36c6aa01ee0a7aee5b0510a8e649c44de318b060
...
 
 
 
 
 
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.