Skip to content
This repository has been archived by the owner on Mar 2, 2020. It is now read-only.

Commit

Permalink
Change README to reflect more extensible usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nateberkopec committed Nov 21, 2012
1 parent 6a4bc7f commit c300061
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions README.md
Expand Up @@ -8,7 +8,9 @@ Install


Add the gem to your `Gemfile`: Add the gem to your `Gemfile`:


gem 'mail_view', :git => 'https://github.com/37signals/mail_view.git' ```ruby
gem 'mail_view', :git => 'https://github.com/37signals/mail_view.git'
```


And run `bundle install`. And run `bundle install`.


Expand All @@ -17,50 +19,52 @@ 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. 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 ```ruby
def invitation(inviter, invitee) # app/mailers/mail_preview.rb or lib/mail_preview.rb
# ... class MailPreview < MailView
end # Pull data from existing fixtures

def invitation
def welcome(user) account = Account.first
# ... inviter, invitee = account.users[0, 2]
end Notifier.invitation(inviter, invitee)

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

# Factory-like pattern
def welcome
user = User.create!
mail = Notifier.welcome(user)
user.destroy
mail
end
end
end 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('name@example.com', 'Jill Smith')
mail = UserMailer.forgot_password(user)
end
end
```

Methods must return a [Mail][1] or [TMail][2] 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. Methods must return a [Mail][1] or [TMail][2] 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 Routing
------- -------


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


# config/environments/development.rb ```ruby
config.middleware.use MailView::Mapper, [Notifier::Preview] # config/environments/development.rb
config.middleware.use MailView::Mapper, [MailPreview]
```


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


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


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


Expand Down

0 comments on commit c300061

Please sign in to comment.