Module: MailerLayouts

Defined in:
lib/mailer_layouts.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mailer_layouts.rb', line 2

def self.included(base)
  base.extend ClassMethods
  base.class_eval {
    adv_attr_accessor :message_layout                   # instance method to set individual message layout

    # the radiant_layout class method will store a default in :mailer_layout_name
    # during ActionMailer initialization we instantiate that and store that in an instance variable 
    # (having called it, if it's a proc)
    # Note that individual messages you can override this by calling the instance method
    #   radiant_layout(Layout object)
    # during message instantiation (alongside subject, recipients, etc)

    def initialize_defaults_with_layout(method_name)
      initialize_defaults_without_layout(method_name)
      default_layout = self.class.read_inheritable_attribute :default_layout
      default_layout = default_layout.call(self) if default_layout.is_a? Proc
      @message_layout = Layout.find_by_name(default_layout)
    end
    alias_method_chain :initialize_defaults, :layout
  }
end