Module: Padrino::Mailer::Helpers::ClassMethods

### Home Classes Methods

### In Files

- lib/padrino-mailer/helpers.rb

### Methods

- #deliver
- #email
- #inherited
- #mailer
- #mailers
- #registered_mailers

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Mailer
- Padrino::Mailer::Base
- Padrino::Mailer::Helpers
- Padrino::Mailer::Helpers::ClassMethods
- Padrino::Mailer::Mime
- Mail
- Mail::Message

No matching classes.

# Padrino::Mailer::Helpers::ClassMethods

Class methods responsible for registering mailers, configuring settings and delivering messages.

### Public Instance Methods

deliver(mailer_name, message_name, *attributes) click to toggle source

Delivers a mailer message email with the given attributes.

@param [Symbol] mailer_name

    The name of the mailer.

@param [Symbol] message_name

    The name of the message to deliver.

@param attributes

    The parameters to pass to the mailer.

@example

    deliver(:sample, :birthday, "Joey", 21)
    deliver(:example, :message, "John")

    # File lib/padrino-mailer/helpers.rb, line 108
    def deliver(mailer_name, message_name, *attributes)
      message = registered_mailers[mailer_name].messages[message_name].call(*attributes)
      message.delivery_method(*delivery_settings)
      message.deliver
    end

email(mail_attributes={}, &block) click to toggle source

Delivers an email with the given mail attributes with specified and default settings.

@param [Hash] mail_attributes

    The attributes for this message (to, from, subject, cc, bcc, body, etc.).

@param [Proc] block

    The block mail attributes for this message.

@example

    MyApp.email(:to => 'to@ma.il', :from => 'from@ma.il', :subject => 'Welcome!', :body => 'Welcome Here!')

    # or if you prefer blocks

    MyApp.email do
      to @user.email
      from "awesomeness@example.com"
      subject "Welcome to Awesomeness!"
      body 'path/to/my/template', :locals => { :a => a, :b => b }
    end

    # File lib/padrino-mailer/helpers.rb, line 134
    def email(mail_attributes={}, &block)
      message = _padrino_mailer::Message.new(self)
      message.delivery_method(*delivery_settings)
      message.instance_eval(&block) if block_given?
      mail_attributes.reverse_merge(mailer_defaults) if respond_to?(:mailer_defaults)
      mail_attributes.each_pair { |k, v| message.method(k).call(v) }
      message.deliver
    end

inherited(subclass) click to toggle source

    # File lib/padrino-mailer/helpers.rb, line 56
    def inherited(subclass)
      @_registered_mailers ||= {}
      super(subclass)
    end

mailer(name, &block) click to toggle source

Defines a mailer object allowing the definition of various email messages that can be delivered.

@param [Symbol] name

    The name of the mailer to initialize.

@example

    mailer :sample do
      email :birthday do |name, age|
        subject 'Happy Birthday!'
        to      'john@fake.com'
        from    'noreply@birthday.com'
        locals  :name => name, :age => age
        render  'sample/birthday'
      end
    end

    # File lib/padrino-mailer/helpers.rb, line 86
    def mailer(name, &block)
      mailer                   = Padrino::Mailer::Base.new(self, name, &block)
      mailer.delivery_settings = delivery_settings
      registered_mailers[name] = mailer
      mailer
    end

Also aliased as: mailers
mailers(name, &block) click to toggle source
Alias for: mailer
registered_mailers() click to toggle source

Returns all registered mailers for this application.

    # File lib/padrino-mailer/helpers.rb, line 64
    def registered_mailers
      @_registered_mailers ||= {}
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.