mail_form 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +5 -0
- data/Rakefile +2 -0
- data/lib/generators/rails/mail_form_generator.rb +17 -0
- data/lib/generators/rails/templates/model.rb +9 -0
- data/lib/mail_form/delivery.rb +9 -35
- data/lib/mail_form/shim.rb +8 -4
- data/lib/mail_form/version.rb +1 -1
- data/test/mail_form_test.rb +2 -0
- data/test/resource_test.rb +2 -0
- data/test/test_helper.rb +4 -4
- metadata +6 -4
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
class MailFormGenerator < Rails::Generators::NamedBase
|
4
|
+
def self.source_root
|
5
|
+
@_mail_form_source_root ||= File.expand_path("../templates", __FILE__)
|
6
|
+
end
|
7
|
+
|
8
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
9
|
+
|
10
|
+
check_class_collision
|
11
|
+
|
12
|
+
def create_model_file
|
13
|
+
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/mail_form/delivery.rb
CHANGED
@@ -15,42 +15,16 @@ module MailForm
|
|
15
15
|
class_attribute :mail_appendable
|
16
16
|
self.mail_appendable = []
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
module Deprecated
|
28
|
-
def subject(duck=nil, &block)
|
29
|
-
ActiveSupport::Deprecation.warn "subject is deprecated. Please define a headers method " <<
|
30
|
-
"in your instance which returns a hash with :subject as key instead.", caller
|
31
|
-
end
|
32
|
-
|
33
|
-
def sender(duck=nil, &block)
|
34
|
-
ActiveSupport::Deprecation.warn "from/sender is deprecated. Please define a headers method " <<
|
35
|
-
"in your instance which returns a hash with :from as key instead.", caller
|
18
|
+
if respond_to?(:before_deliver) && respond_to?(:after_deliver)
|
19
|
+
before_deliver :not_spam?
|
20
|
+
after_deliver :deliver!
|
21
|
+
else # For ActiveRecord compatibility
|
22
|
+
before_create :not_spam?
|
23
|
+
after_create :deliver!
|
24
|
+
alias :deliver :save
|
36
25
|
end
|
37
|
-
alias :from :sender
|
38
26
|
|
39
|
-
|
40
|
-
ActiveSupport::Deprecation.warn "to/recipients is deprecated. Please define a headers method " <<
|
41
|
-
"in your instance which returns a hash with :to as key instead.", caller
|
42
|
-
end
|
43
|
-
alias :to :recipients
|
44
|
-
|
45
|
-
def headers(hash)
|
46
|
-
ActiveSupport::Deprecation.warn "headers is deprecated. Please define a headers method " <<
|
47
|
-
"in your instance which returns the desired headers instead.", caller
|
48
|
-
end
|
49
|
-
|
50
|
-
def template(new_template)
|
51
|
-
ActiveSupport::Deprecation.warn "template is deprecated. Please define a headers method " <<
|
52
|
-
"in your instance which returns a hash with :template_name as key instead.", caller
|
53
|
-
end
|
27
|
+
attr_accessor :request
|
54
28
|
end
|
55
29
|
|
56
30
|
module ClassMethods
|
@@ -169,7 +143,7 @@ module MailForm
|
|
169
143
|
!spam?
|
170
144
|
end
|
171
145
|
|
172
|
-
# Deliver the resource without
|
146
|
+
# Deliver the resource without running any validation.
|
173
147
|
def deliver!
|
174
148
|
MailForm::Notifier.contact(self).deliver
|
175
149
|
end
|
data/lib/mail_form/shim.rb
CHANGED
@@ -12,7 +12,7 @@ module MailForm
|
|
12
12
|
include ActiveModel::Conversion
|
13
13
|
|
14
14
|
extend MailForm::Shim::ClassMethods
|
15
|
-
define_model_callbacks :
|
15
|
+
define_model_callbacks :deliver
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -43,19 +43,23 @@ module MailForm
|
|
43
43
|
true
|
44
44
|
end
|
45
45
|
|
46
|
+
def persisted?
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
46
50
|
# Always return nil so when using form_for, the default method will be post.
|
47
51
|
def id
|
48
52
|
nil
|
49
53
|
end
|
50
54
|
|
51
55
|
# Create just check validity, and if so, trigger callbacks.
|
52
|
-
def
|
56
|
+
def deliver
|
53
57
|
if valid?
|
54
|
-
|
58
|
+
_run_deliver_callbacks { true }
|
55
59
|
else
|
56
60
|
false
|
57
61
|
end
|
58
62
|
end
|
59
|
-
alias :save :
|
63
|
+
alias :save :deliver
|
60
64
|
end
|
61
65
|
end
|
data/lib/mail_form/version.rb
CHANGED
data/test/mail_form_test.rb
CHANGED
data/test/resource_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -26,7 +26,7 @@ class ContactForm < MailForm::Base
|
|
26
26
|
|
27
27
|
attributes :created_at, :message, :validate => :callback
|
28
28
|
|
29
|
-
|
29
|
+
before_deliver :set_created_at
|
30
30
|
|
31
31
|
def headers
|
32
32
|
{ :to => 'my.email@my.domain.com' }
|
@@ -55,14 +55,14 @@ end
|
|
55
55
|
|
56
56
|
class FileForm < ContactForm
|
57
57
|
attribute :file, :attachment => true, :validate => true
|
58
|
-
recipients :set_recipient
|
59
58
|
|
60
|
-
def
|
61
|
-
if file
|
59
|
+
def headers
|
60
|
+
to = if file
|
62
61
|
"contact_file@my.domain.com"
|
63
62
|
else
|
64
63
|
"contact@my.domain.com"
|
65
64
|
end
|
65
|
+
{ :to => to }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 1.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Jos\xC3\xA9 Valim"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-05-26 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -32,6 +32,8 @@ files:
|
|
32
32
|
- MIT-LICENSE
|
33
33
|
- README.rdoc
|
34
34
|
- Rakefile
|
35
|
+
- lib/generators/rails/mail_form_generator.rb
|
36
|
+
- lib/generators/rails/templates/model.rb
|
35
37
|
- lib/mail_form.rb
|
36
38
|
- lib/mail_form/base.rb
|
37
39
|
- lib/mail_form/delivery.rb
|