Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 109 lines (61 sloc) 2.63 kb
66a0388 @arkes first commit
authored
1 = Lazy Mail
2
3 lazy_mail is a lazy and quick way to use the function mail and offers configurations to write less code.
4
5 == Installation
6
7 <b>This Gem works only for Rails 3</b>
8
9 Add this to your Gemfile and run the +bundle+ command.
10
11 gem 'lazy_mail'
12
13 == Usage
14
15 === 1. Basics
16
17 Your mailer before was:
18
19 class UserMailer < ActionMailer::Base
20 default :from => 'test@test.com'
21
22 def confirmation(user)
23 @user = user
24 mail(:to => user.email, :subject => 'confirm')
25 end
26 end
27
28 With lazy_mail you just write less code.
5b756aa @arkes update documentation
authored
29 lazy_mail set +user+ as an instance variable <tt>@user</tt> by default.
66a0388 @arkes first commit
authored
30
31 class UserMailer < ActionMailer::Base
32 def confirmation(user)
33 lazy_mail user
34 end
35 end
36
37 And you email view doesn't change:
38
39 Hello <%= @user.username %>
40
41 You can still use the options of mail:
42
43 lazy_mail user, { :to => 'another@test.com', :subject => 'my subject' }
44
45
46 You can pass many arguments as you like:
47
48 def confirmation(user, post, author)
49 lazy_mail user, post, author
50 end
51
5b756aa @arkes update documentation
authored
52 and just use in your mail view <tt>@user</tt>, <tt>@post</tt>, <tt>@autor</tt>.
66a0388 @arkes first commit
authored
53
54
55 === 2. Configurations
56
57 === Mailer Views
58
5b756aa @arkes update documentation
authored
59 The views are now located in a different folder: +app/views/notifications/mailer_name/current_locale/+
66a0388 @arkes first commit
authored
60 For example your locale is english the path will be:
61
62 views/notifications/user_mailer/en/confirmation.text.erb
63
64 You can set the path you want in your initializer with:
65
66 LazyMail.mailer_templates_path = 'notification'
67
68 If you set it to +nil+ it will take the default rails path
69
70 === Option :to
71
72 The mail option :to is set by default, but you have to configure it in your initializer:
73
74 Lazy.user_model = User
75
27a36cc @arkes update readme
authored
76 Just put the name of the model you want to use.
66a0388 @arkes first commit
authored
77
5b756aa @arkes update documentation
authored
78 By default it will call the method email, if you have another name change it in your initializer.
66a0388 @arkes first commit
authored
79
80 LazyMail.email_field = :email
81
82 === I18n subject
83
5b756aa @arkes update documentation
authored
84 The subject is a scope: <tt>[:mailer, :mailer_name, :action_name]</tt>, you can change it:
66a0388 @arkes first commit
authored
85
86 LazyMail.i18n_scope = [:mailer, :class_name, :action_name]
87 => 'mailer.user_mailer.confirmation.subject'
88
89 If you prefer to use the rails default just set it to +nil+
90
91 === Option :from
92
93 Set the option :from in the initializer
94
95 LazyMail.default_no_reply = 'no-reply@test.com'
96
97 === Development
98
5b756aa @arkes update documentation
authored
99 For the development phase, you can set an option :to by default to overwrite +user.email+
66a0388 @arkes first commit
authored
100
101 LazyMail.development_mail = 'my_mail@test.com'
102
103 If you use Git:
104
105 LazyMail.development_mail = :git
106
5b756aa @arkes update documentation
authored
107 lazy_mail will take your git <tt>git config user.email</tt>
66a0388 @arkes first commit
authored
108
27a36cc @arkes update readme
authored
109 You can find the initializer file {here}[https://github.com/arkes/lazy_mail/blob/master/misc/initializers/lazy_mail.rb]
Something went wrong with that request. Please try again.