Skip to content

mobilecause/mail_view

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MailView -- Visual email testing

Preview plain text and html mail templates in your browser without redelivering it every time you make a change.

Install

As gem:

gem install mail_view

# Gemfile
gem 'mail_view', :group => :development

As plugin

rails plugin install https://github.com/37signals/mail_view.git

# Gemfile
gem 'tilt', :group => :development

Usage

Since most emails do something interesting with database data, you'll need to write some scenarios to load messages with fake data. Its similar to writing mailer unit tests but you see a visual representation of the output instead.

class Notifier < ActionMailer::Base
  def invitation(inviter, invitee)
    # ...
  end

  def welcome(user)
    # ...
  end

  class Preview < MailView
    # Pull data from existing fixtures
    def invitation
      account = Account.first
      inviter, invitee = account.users[0, 2]
      Notifier.invitation(inviter, invitee)
    end

    # Factory-like pattern
    def welcome
      user = User.create!
      mail = Notifier.welcome(user)
      user.destory
      mail
    end
  end
end

Methods must return a Mail or TMail object. Using ActionMailer, call Notifier.create_action_name(args) to return a compatible TMail object. Now on ActionMailer 3.x, Notifier.action_name(args) will return a Mail object.

Routing

A mini router middleware is bundled for Rails 2.x support.

# config/environments/development.rb
config.middleware.use MailView::Mapper, Notifier::Preview

For Rails³ you can map the app inline in your routes config.

# config/routes.rb
if Rails.env.development?
  mount Notifier::Preview => 'mail_view'
end

Now just load up http://localhost:3000/mail_view.

Interface

Plain text view HTML view

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%