Coder Social home page Coder Social logo

mail_view's Introduction

MailView -- Visual email testing

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

Install

Add the gem to your Gemfile:

  gem 'mail_view', :git => 'https://github.com/37signals/mail_view.git'
  # or
  gem "mail_view", "~> 1.0.3"

And run bundle install.

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.

  # app/mailers/mail_preview.rb or lib/mail_preview.rb
  class MailPreview < 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.destroy
      mail
    end

    # Stub-like
    def forgot_password
      user = Struct.new(:email, :name).new('[email protected]', 'Jill Smith')
      mail = UserMailer.forgot_password(user)
    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, [MailPreview]

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

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

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

Interface

Plain text view HTML view

mail_view's People

Contributors

jeremy avatar packagethief avatar jonleighton avatar wesgibbs avatar grosser avatar aitor avatar joshnabbott avatar josh avatar nateberkopec avatar sc0ttman avatar vijaydev avatar

Watchers

Miguel Senquiz avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.