josevalim-simple_form 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -1
- data/README +22 -13
- data/lib/simple_form/dsl.rb +31 -20
- data/lib/simple_form/notifier.rb +2 -0
- data/test/notifier_test.rb +6 -1
- data/test/test_file.txt +1 -0
- data/test/test_helper.rb +10 -1
- metadata +3 -2
data/CHANGELOG
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
# Version 0.
|
1
|
+
# Version 0.3
|
2
2
|
|
3
|
+
* Added support to symbols on :sender, :subject and :recipients
|
3
4
|
* Added support to symbols on :validate
|
5
|
+
|
6
|
+
# Version 0.2
|
7
|
+
|
4
8
|
* Added support to request objects and append DSL
|
5
9
|
* Added support to :attachments (thanks to @andrewtimberlake)
|
6
10
|
|
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Simple Form
|
2
2
|
License: MIT
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.3.1
|
4
4
|
|
5
5
|
You can also read this README in pretty html at the GitHub project Wiki page:
|
6
6
|
|
@@ -121,31 +121,40 @@ Examples:
|
|
121
121
|
# save is an alias to deliver to allow it to work with InheritedResources
|
122
122
|
c.save #=> true
|
123
123
|
|
124
|
-
== subject(
|
124
|
+
== subject(string_or_symbol_or_block)
|
125
125
|
|
126
|
-
Declares the subject of the contact email. It can be a string or a proc.
|
127
|
-
|
126
|
+
Declares the subject of the contact email. It can be a string or a proc or a symbol.
|
127
|
+
|
128
|
+
When a symbol is given, it will call a method on the form object with the same
|
129
|
+
name as the symbol. As a proc, it receives a simple form instance. It defaults
|
128
130
|
to the class human name.
|
129
131
|
|
130
132
|
subject "My Contact Form"
|
131
|
-
subject {|c| "Contacted by #{c.name}"}
|
133
|
+
subject { |c| "Contacted by #{c.name}" }
|
134
|
+
|
135
|
+
== sender(string_or_symbol_or_block)
|
132
136
|
|
133
|
-
|
137
|
+
Declares contact email sender. It can be a string or a proc or a symbol.
|
134
138
|
|
135
|
-
|
136
|
-
As a proc, it receives a simple form instance. By default is:
|
139
|
+
When a symbol is given, it will call a method on the form object with the same
|
140
|
+
name as the symbol. As a proc, it receives a simple form instance. By default is:
|
137
141
|
|
138
142
|
sender{ |c| c.email }
|
139
143
|
|
140
|
-
This requires that your SimpleForm object have
|
144
|
+
This requires that your SimpleForm object have an email attribute.
|
141
145
|
|
142
|
-
==
|
146
|
+
== recipients(string_or_array_or_symbol_or_block)
|
143
147
|
|
144
|
-
|
148
|
+
Who will receive the e-mail. Can be a string or array or a symbol or a proc.
|
145
149
|
|
146
|
-
|
150
|
+
When a symbol is given, it will call a method on the form object with the same
|
151
|
+
name as the symbol. As a proc, it receives a simple form instance.
|
147
152
|
|
148
|
-
|
153
|
+
Both the proc and the symbol must return a string or an array. By default is nil.
|
154
|
+
|
155
|
+
== headers(hash)
|
156
|
+
|
157
|
+
Additional headers to your e-mail.
|
149
158
|
|
150
159
|
I18n
|
151
160
|
----
|
data/lib/simple_form/dsl.rb
CHANGED
@@ -60,9 +60,11 @@ class SimpleForm
|
|
60
60
|
end
|
61
61
|
alias :attributes :attribute
|
62
62
|
|
63
|
-
# Declares
|
64
|
-
#
|
65
|
-
#
|
63
|
+
# Declares contact email sender. It can be a string or a proc or a symbol.
|
64
|
+
#
|
65
|
+
# When a symbol is given, it will call a method on the form object with
|
66
|
+
# the same name as the symbol. As a proc, it receives a simple form
|
67
|
+
# instance. By default is the class human name.
|
66
68
|
#
|
67
69
|
# == Examples
|
68
70
|
#
|
@@ -70,53 +72,62 @@ class SimpleForm
|
|
70
72
|
# subject "My Contact Form"
|
71
73
|
# end
|
72
74
|
#
|
73
|
-
def subject(
|
74
|
-
write_inheritable_attribute(:form_subject,
|
75
|
+
def subject(duck=nil, &block)
|
76
|
+
write_inheritable_attribute(:form_subject, duck || block)
|
75
77
|
end
|
76
78
|
|
77
|
-
# Declares contact email sender. It can be a string or a proc.
|
78
|
-
#
|
79
|
+
# Declares contact email sender. It can be a string or a proc or a symbol.
|
80
|
+
#
|
81
|
+
# When a symbol is given, it will call a method on the form object with
|
82
|
+
# the same name as the symbol. As a proc, it receives a simple form
|
83
|
+
# instance. By default is:
|
79
84
|
#
|
80
85
|
# sender{ |c| c.email }
|
81
86
|
#
|
82
|
-
# This requires that your SimpleForm object have
|
87
|
+
# This requires that your SimpleForm object have an email attribute.
|
83
88
|
#
|
84
89
|
# == Examples
|
85
90
|
#
|
86
91
|
# class ContactForm < SimpleForm
|
87
92
|
# # Change sender to include also the name
|
88
|
-
# sender{|c| %{"#{c.name}" <#{c.email}>} }
|
93
|
+
# sender { |c| %{"#{c.name}" <#{c.email}>} }
|
89
94
|
# end
|
90
95
|
#
|
91
|
-
def sender(
|
92
|
-
write_inheritable_attribute(:form_sender,
|
96
|
+
def sender(duck=nil, &block)
|
97
|
+
write_inheritable_attribute(:form_sender, duck || block)
|
93
98
|
end
|
94
99
|
alias :from :sender
|
95
100
|
|
96
|
-
#
|
101
|
+
# Who will receive the e-mail. Can be a string or array or a symbol or a proc.
|
102
|
+
#
|
103
|
+
# When a symbol is given, it will call a method on the form object with
|
104
|
+
# the same name as the symbol. As a proc, it receives a simple form instance.
|
105
|
+
#
|
106
|
+
# Both the proc and the symbol must return a string or an array. By default
|
107
|
+
# is nil.
|
97
108
|
#
|
98
109
|
# == Examples
|
99
110
|
#
|
100
111
|
# class ContactForm < SimpleForm
|
101
|
-
#
|
112
|
+
# recipients [ "first.manager@domain.com", "second.manager@domain.com" ]
|
102
113
|
# end
|
103
114
|
#
|
104
|
-
def
|
105
|
-
|
115
|
+
def recipients(duck=nil, &block)
|
116
|
+
write_inheritable_attribute(:form_recipients, duck || block)
|
106
117
|
end
|
118
|
+
alias :to :recipients
|
107
119
|
|
108
|
-
#
|
120
|
+
# Additional headers to your e-mail.
|
109
121
|
#
|
110
122
|
# == Examples
|
111
123
|
#
|
112
124
|
# class ContactForm < SimpleForm
|
113
|
-
#
|
125
|
+
# headers { :content_type => 'text/html' }
|
114
126
|
# end
|
115
127
|
#
|
116
|
-
def
|
117
|
-
|
128
|
+
def headers(hash)
|
129
|
+
write_inheritable_hash(:form_headers, hash)
|
118
130
|
end
|
119
|
-
alias :to :recipients
|
120
131
|
|
121
132
|
# Values from request object to be appended to the contact form.
|
122
133
|
# Whenever used, you have to send the request object when initializing the object:
|
data/lib/simple_form/notifier.rb
CHANGED
data/test/notifier_test.rb
CHANGED
@@ -9,7 +9,7 @@ class SimpleFormNotifierTest < ActiveSupport::TestCase
|
|
9
9
|
@valid_attributes = { :name => 'José', :email => 'my.email@my.domain.com', :message => "Cool\nno?" }
|
10
10
|
@advanced = AdvancedForm.new(@valid_attributes, @request)
|
11
11
|
|
12
|
-
test_file = ActionController::TestUploadedFile.new(File.join(File.dirname(__FILE__), '
|
12
|
+
test_file = ActionController::TestUploadedFile.new(File.join(File.dirname(__FILE__), 'test_file.txt'))
|
13
13
|
@with_file = FileForm.new(:name => 'José', :email => 'my.email@my.domain.com', :message => "Cool", :file => test_file)
|
14
14
|
|
15
15
|
ActionMailer::Base.deliveries = []
|
@@ -51,6 +51,11 @@ class SimpleFormNotifierTest < ActiveSupport::TestCase
|
|
51
51
|
assert_equal ['my.first@email.com', 'my.second@email.com'], ActionMailer::Base.deliveries.first.to
|
52
52
|
end
|
53
53
|
|
54
|
+
def test_recipients_is_a_symbold
|
55
|
+
@with_file.deliver
|
56
|
+
assert_equal ['contact_file@my.domain.com'], ActionMailer::Base.deliveries.first.to
|
57
|
+
end
|
58
|
+
|
54
59
|
def test_headers_is_a_hash
|
55
60
|
@advanced.deliver
|
56
61
|
assert_equal '<mypath>', ActionMailer::Base.deliveries.first.header['return-path'].to_s
|
data/test/test_file.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
A test file
|
data/test/test_helper.rb
CHANGED
@@ -37,13 +37,22 @@ end
|
|
37
37
|
|
38
38
|
class FileForm < ContactForm
|
39
39
|
attribute :file, :attachment => true, :validate => true
|
40
|
+
recipients :set_recipient
|
41
|
+
|
42
|
+
def set_recipient
|
43
|
+
if file
|
44
|
+
"contact_file@my.domain.com"
|
45
|
+
else
|
46
|
+
"contact@my.domain.com"
|
47
|
+
end
|
48
|
+
end
|
40
49
|
end
|
41
50
|
|
42
51
|
class NullRecipient < SimpleForm
|
43
52
|
sender 'my.email@my.domain.com'
|
44
53
|
end
|
45
54
|
|
46
|
-
#Needed to correctly test an uploaded file
|
55
|
+
# Needed to correctly test an uploaded file
|
47
56
|
class ActionController::TestUploadedFile
|
48
57
|
def read
|
49
58
|
@tempfile.read
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: josevalim-simple_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jos\xC3\xA9 Valim"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -64,4 +64,5 @@ test_files:
|
|
64
64
|
- test/base_test.rb
|
65
65
|
- test/errors_test.rb
|
66
66
|
- test/notifier_test.rb
|
67
|
+
- test/test_file.txt
|
67
68
|
- test/test_helper.rb
|