easy_mail 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/easy_mail/mailer.rb
CHANGED
@@ -5,7 +5,7 @@ module EasyMail
|
|
5
5
|
|
6
6
|
mattr_accessor :default_to, :default_bcc, :default_from, :default_subject
|
7
7
|
|
8
|
-
attr_accessor :name, :to, :bcc, :from, :subject, :template_name, :namespace
|
8
|
+
attr_accessor :name, :to, :bcc, :from, :subject, :template_name, :namespace, :attachments
|
9
9
|
|
10
10
|
def initialize(name, attributes = {})
|
11
11
|
@name = name.to_s.split("/").pop
|
@@ -28,6 +28,8 @@ module EasyMail
|
|
28
28
|
name.to_s.split("/").slice(0..-2).map(&:classify).join("::")
|
29
29
|
end
|
30
30
|
|
31
|
+
@attachments = attributes[:attachments] || []
|
32
|
+
|
31
33
|
generate_mailer
|
32
34
|
generate_controller
|
33
35
|
|
@@ -69,11 +71,12 @@ module EasyMail
|
|
69
71
|
end
|
70
72
|
|
71
73
|
def mail_controller
|
72
|
-
@mail_controller ||=
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
@mail_controller ||= controller_namespace.const_set(mail_controller_name, Class.new(mail_parent_controller))
|
75
|
+
#begin
|
76
|
+
#(namespace_array + ["Mail::#{mail_controller_name}"]).join("::").constantize
|
77
|
+
#rescue NameError
|
78
|
+
#controller_namespace.const_set(mail_controller_name, Class.new(mail_parent_controller))
|
79
|
+
#end
|
77
80
|
end
|
78
81
|
|
79
82
|
def mail_controller_name
|
@@ -110,15 +113,13 @@ module EasyMail
|
|
110
113
|
if instance_variable_get("@#{mailer.name}").valid?
|
111
114
|
mailer.mailer_class.send_mail(instance_variable_get("@#{mailer.name}")).deliver
|
112
115
|
|
113
|
-
|
116
|
+
instance_variable_set("@#{mailer.name}", mailer.model_class.new)
|
117
|
+
|
118
|
+
redirect_to send("#{mailer.route_as}_url") , notice: "Mail send successful"
|
114
119
|
else
|
115
120
|
render :show
|
116
121
|
end
|
117
122
|
end
|
118
|
-
|
119
|
-
define_method :confirmation do
|
120
|
-
render "shared/mail/confirmation"
|
121
|
-
end
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
@@ -132,6 +133,9 @@ module EasyMail
|
|
132
133
|
define_method :send_mail do |column|
|
133
134
|
instance_variable_set("@#{column.class.name.demodulize.underscore}", column)
|
134
135
|
|
136
|
+
mailer.attachments.each do |attachment|
|
137
|
+
attachments[column.send(attachment).original_filename] = File.read(column.send("#{attachment}").send(:path))
|
138
|
+
end
|
135
139
|
mail(to: mailer.to, bcc: mailer.bcc, from: mailer.from, subject: mailer.subject, template_path: mailer.template_path, template_name: mailer.template_name)
|
136
140
|
end
|
137
141
|
end
|
@@ -200,7 +204,7 @@ module EasyMail
|
|
200
204
|
def routes(router)
|
201
205
|
EasyMail::Mailer.all.each do |mailer|
|
202
206
|
router.get mailer.route_url, to: "#{mailer.route_to_controller_part}#show", as: mailer.route_as
|
203
|
-
router.get "#{mailer.route_url}/confirmation", to: "#{mailer.route_to_controller_part}#confirmation"
|
207
|
+
#router.get "#{mailer.route_url}/confirmation", to: "#{mailer.route_to_controller_part}#confirmation"
|
204
208
|
router.post mailer.route_url, to: "#{mailer.route_to_controller_part}#create"
|
205
209
|
end
|
206
210
|
end
|
data/lib/easy_mail/version.rb
CHANGED
@@ -5,7 +5,7 @@ module EasyMail
|
|
5
5
|
|
6
6
|
def generate_init_file
|
7
7
|
copy_file "easy_mail.rb", "config/initializers/easy_mail.rb"
|
8
|
-
copy_file "confirmation.html.erb", "app/views/shared/mail/confirmation.html.erb"
|
8
|
+
#copy_file "confirmation.html.erb", "app/views/shared/mail/confirmation.html.erb"
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/spec/easy_mail_spec.rb
CHANGED
@@ -95,7 +95,7 @@ describe EasyMail::Mailer do
|
|
95
95
|
@mailer.namespace.should == ""
|
96
96
|
|
97
97
|
@mailer.form_key.should == :mail_contact
|
98
|
-
@mailer.template_path.should == "
|
98
|
+
@mailer.template_path.should == "mail/contacts"
|
99
99
|
@mailer.route_url.should == "/contact"
|
100
100
|
@mailer.route_to_controller_part.should == "mail/contacts"
|
101
101
|
@mailer.route_as.should == "mail_contact"
|
@@ -150,7 +150,7 @@ describe EasyMail::Mailer do
|
|
150
150
|
|
151
151
|
@mailer.name.should == "contact"
|
152
152
|
@mailer.form_key.should == :namespace_one_namespace_two_mail_contact
|
153
|
-
@mailer.template_path.should == "
|
153
|
+
@mailer.template_path.should == "namespace_one/namespace_two/mail/contacts"
|
154
154
|
@mailer.route_url.should == "/namespace_one/namespace_two/contact"
|
155
155
|
@mailer.route_to_controller_part.should == "namespace_one/namespace_two/mail/contacts"
|
156
156
|
@mailer.route_as.should == "namespace_one_namespace_two_mail_contact"
|