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.577 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.
29 Lazy_mail set +user+ as an instance variable +@user+ by default.
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
52 and just use in your mail view +@user+, +@post+, +@autor+.
53
54
55 === 2. Configurations
56
57 === Mailer Views
58
59 The Views are now located in a different folder: +app/views/notifications/mailer_name/current_locale/+
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
76 Just put the name of the model you want to use to set the :to.
77
78 By default it will call the method +email+, if you have another name change it in your initializer.
79
80 LazyMail.email_field = :email
81
82 === I18n subject
83
84 The subject is a scope: +[:mailer, :mailer_name, :action_name]+, you can change it:
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
99 For the development phase, you can set an option :to by default to overwrite user.email
100
101 LazyMail.development_mail = 'my_mail@test.com'
102
103 If you use Git:
104
105 LazyMail.development_mail = :git
106
107 lazy_mail will take your git +git config user.email+
108
109 You can find the initializer file {here}[https://github.com/arkes/lazy_mail/wiki/initializer]
Something went wrong with that request. Please try again.