radiant-forms-extension 3.2.4 → 3.2.5
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/VERSION +1 -1
- data/app/controllers/forms_controller.rb +31 -14
- data/forms_extension.rb +1 -1
- data/lib/forms/controllers/application_controller.rb +0 -6
- data/lib/forms/tags/core.rb +6 -10
- data/radiant-forms-extension.gemspec +55 -57
- data/spec/controllers/forms_controller_spec.rb +29 -5
- data/spec/lib/forms/tags/core_spec.rb +60 -0
- metadata +6 -7
- data/.gitignore +0 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.2.
|
1
|
+
3.2.5
|
@@ -8,32 +8,56 @@ class FormsController < ApplicationController
|
|
8
8
|
@response = find_or_create_response
|
9
9
|
@response.update_attribute(:result, nil)
|
10
10
|
|
11
|
-
redirect_to :back
|
11
|
+
redirect_to :back rescue redirect_to '/'
|
12
12
|
end
|
13
13
|
|
14
14
|
def update
|
15
|
+
set_page
|
16
|
+
set_form
|
17
|
+
set_response
|
18
|
+
set_configuration
|
19
|
+
|
20
|
+
execute_extensions
|
21
|
+
|
22
|
+
begin
|
23
|
+
@response.save!
|
24
|
+
redirect_to @form.redirect_to.present? ? @form.redirect_to : @page.url
|
25
|
+
rescue
|
26
|
+
"Form '#{@form.title}' could not be submitted."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def set_page
|
15
33
|
@page = Page.find(params[:page_id]) rescue Page.first
|
16
34
|
@page.data = params
|
17
35
|
@page.request = OpenStruct.new({
|
18
36
|
:referrer => request.referer,
|
19
37
|
:session => session # Creating a pretend response object
|
20
38
|
})
|
21
|
-
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_form
|
22
42
|
@form = Form.find(params[:id])
|
23
43
|
@form.page = @page
|
24
|
-
|
25
|
-
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_response
|
26
47
|
@response = find_or_create_response
|
27
|
-
# Put the submitted data into the response object
|
28
48
|
@response.result = Forms::Config.deep_symbolize_keys(params)
|
29
|
-
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_configuration
|
30
52
|
begin
|
31
53
|
# Grab the form configuration data
|
32
54
|
@form[:extensions] = Forms::Config.convert(@form.config)
|
33
55
|
rescue
|
34
56
|
raise "Form '#{@form.title}' has not been configured"
|
35
57
|
end
|
36
|
-
|
58
|
+
end
|
59
|
+
|
60
|
+
def execute_extensions
|
37
61
|
@results = {}
|
38
62
|
# Iterate through each configured extension
|
39
63
|
@form[:extensions].each do |name, config|
|
@@ -44,13 +68,6 @@ class FormsController < ApplicationController
|
|
44
68
|
end
|
45
69
|
# Those results are merged into the response object
|
46
70
|
@response.result = @response.result.merge!({ :results => @results})
|
47
|
-
|
48
|
-
begin
|
49
|
-
@response.save!
|
50
|
-
redirect_to @form.redirect_to.present? ? @form.redirect_to : @page.url
|
51
|
-
rescue
|
52
|
-
"Form '#{@form.title}' could not be submitted."
|
53
|
-
end
|
54
71
|
end
|
55
72
|
|
56
73
|
end
|
data/forms_extension.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class FormsExtension < Radiant::Extension
|
2
|
-
version
|
2
|
+
version YAML::load_file(File.join(File.dirname(__FILE__), 'VERSION'))
|
3
3
|
description 'Radiant Form extension. Site wide, useful form management'
|
4
4
|
url 'http://github.com/squaretalent/radiant-forms-extension'
|
5
5
|
|
@@ -10,20 +10,14 @@ module Forms
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def find_response
|
13
|
-
response = nil
|
14
|
-
|
15
13
|
begin
|
16
14
|
response = Response.find(request.session[:form_response])
|
17
15
|
rescue
|
18
16
|
response = nil
|
19
17
|
end
|
20
|
-
|
21
|
-
response
|
22
18
|
end
|
23
19
|
|
24
20
|
def find_or_create_response
|
25
|
-
response = nil
|
26
|
-
|
27
21
|
if find_response
|
28
22
|
response = find_response
|
29
23
|
else
|
data/lib/forms/tags/core.rb
CHANGED
@@ -190,14 +190,14 @@ module Forms
|
|
190
190
|
Expands if a response object exists in the user session
|
191
191
|
}
|
192
192
|
tag 'response:if_response' do |tag|
|
193
|
-
tag.expand if tag.locals.response.present? and tag.locals.response.
|
193
|
+
tag.expand if tag.locals.response.present? and tag.locals.response.result.present?
|
194
194
|
end
|
195
195
|
|
196
196
|
desc %{
|
197
197
|
Expands unless a response object exists in the user session
|
198
198
|
}
|
199
199
|
tag 'response:unless_response' do |tag|
|
200
|
-
tag.expand if tag.locals.response.blank? or tag.locals.response.
|
200
|
+
tag.expand if tag.locals.response.blank? or tag.locals.response.result.blank?
|
201
201
|
end
|
202
202
|
|
203
203
|
desc %{
|
@@ -242,31 +242,27 @@ module Forms
|
|
242
242
|
|
243
243
|
desc %{ Expand if there is a positive response to a specified for value of an extension
|
244
244
|
|
245
|
-
|
246
|
-
<r:response:if_get extension='bogus_gateway' name='checkout'>yay</r:response:if_get>
|
247
|
-
</pre>
|
245
|
+
@<r:response:if_get extension='bogus_gateway' name='checkout'>yay</r:response:if_get>@
|
248
246
|
}
|
249
247
|
tag 'response:if_get' do |tag|
|
250
248
|
if tag.locals.response_extension.present?
|
251
249
|
query = tag.attr['name'].to_sym
|
252
250
|
result = tag.locals.response_extension[query]
|
253
251
|
|
254
|
-
tag.expand if result
|
252
|
+
tag.expand if result
|
255
253
|
end
|
256
254
|
end
|
257
255
|
|
258
256
|
desc %{ Expand if there is a negative response to a specified for value of an extension
|
259
257
|
|
260
|
-
|
261
|
-
<r:response:unless_get extension='bogus_gateway' name='checkout'>no</r:response:unless_get>
|
262
|
-
</pre>
|
258
|
+
@<r:response:unless_get extension='bogus_gateway' name='checkout'>no</r:response:unless_get>@
|
263
259
|
}
|
264
260
|
tag 'response:unless_get' do |tag|
|
265
261
|
if tag.locals.response_extension.present?
|
266
262
|
query = tag.attr['name'].to_sym
|
267
263
|
result = tag.locals.response_extension[query]
|
268
264
|
|
269
|
-
tag.expand
|
265
|
+
tag.expand unless result
|
270
266
|
else
|
271
267
|
tag.expand
|
272
268
|
end
|
@@ -1,82 +1,80 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{radiant-forms-extension}
|
8
|
-
s.version = "3.2.
|
8
|
+
s.version = "3.2.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["dirkkelly"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-22}
|
13
13
|
s.description = %q{Send data from a page to a form handler, extendable with addons}
|
14
14
|
s.email = %q{dirk.kelly@squaretalent.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.md"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
".
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
"spec/spec_helper.rb"
|
19
|
+
"README.md",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"app/controllers/admin/forms_controller.rb",
|
23
|
+
"app/controllers/forms_controller.rb",
|
24
|
+
"app/models/form.rb",
|
25
|
+
"app/models/form_mail.rb",
|
26
|
+
"app/models/form_mailer.rb",
|
27
|
+
"app/models/form_page.rb",
|
28
|
+
"app/models/response.rb",
|
29
|
+
"app/views/admin/forms/_fields.html.haml",
|
30
|
+
"app/views/admin/forms/_filters.html.haml",
|
31
|
+
"app/views/admin/forms/_form.html.haml",
|
32
|
+
"app/views/admin/forms/_header.html.haml",
|
33
|
+
"app/views/admin/forms/edit.html.haml",
|
34
|
+
"app/views/admin/forms/index.html.haml",
|
35
|
+
"app/views/admin/forms/new.html.haml",
|
36
|
+
"app/views/admin/forms/remove.html.haml",
|
37
|
+
"config/locales/en.yml",
|
38
|
+
"config/routes.rb",
|
39
|
+
"cucumber.yml",
|
40
|
+
"db/migrate/001_create_forms.rb",
|
41
|
+
"db/migrate/002_create_user_observer.rb",
|
42
|
+
"db/migrate/003_rename_output_to_content.rb",
|
43
|
+
"db/migrate/004_create_responses.rb",
|
44
|
+
"db/migrate/20100929150423_change_to_updated_by_id.rb",
|
45
|
+
"db/migrate/20101012230144_add_another_content_field.rb",
|
46
|
+
"forms_extension.rb",
|
47
|
+
"lib/forms/config.rb",
|
48
|
+
"lib/forms/controllers/application_controller.rb",
|
49
|
+
"lib/forms/controllers/site_controller.rb",
|
50
|
+
"lib/forms/interface/forms.rb",
|
51
|
+
"lib/forms/models/extension.rb",
|
52
|
+
"lib/forms/models/page.rb",
|
53
|
+
"lib/forms/tags/core.rb",
|
54
|
+
"lib/forms/tags/helpers.rb",
|
55
|
+
"lib/forms/tags/responses.rb",
|
56
|
+
"lib/tasks/forms_extension_tasks.rake",
|
57
|
+
"public/images/admin/extensions/form/form.png",
|
58
|
+
"radiant-forms-extension.gemspec",
|
59
|
+
"spec/controllers/forms_controller_spec.rb",
|
60
|
+
"spec/datasets/forms.rb",
|
61
|
+
"spec/lib/forms/tags/core_spec.rb",
|
62
|
+
"spec/models/form_spec.rb",
|
63
|
+
"spec/models/response_spec.rb",
|
64
|
+
"spec/spec.opts",
|
65
|
+
"spec/spec_helper.rb"
|
67
66
|
]
|
68
67
|
s.homepage = %q{http://github.com/squaretalent/radiant-forms-extension}
|
69
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
70
68
|
s.require_paths = ["lib"]
|
71
69
|
s.rubygems_version = %q{1.3.7}
|
72
70
|
s.summary = %q{Forms Extension for Radiant CMS}
|
73
71
|
s.test_files = [
|
74
72
|
"spec/controllers/forms_controller_spec.rb",
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
"spec/datasets/forms.rb",
|
74
|
+
"spec/lib/forms/tags/core_spec.rb",
|
75
|
+
"spec/models/form_spec.rb",
|
76
|
+
"spec/models/response_spec.rb",
|
77
|
+
"spec/spec_helper.rb"
|
80
78
|
]
|
81
79
|
|
82
80
|
if s.respond_to? :specification_version then
|
@@ -5,18 +5,42 @@ describe FormsController do
|
|
5
5
|
|
6
6
|
context '#new' do
|
7
7
|
|
8
|
-
|
9
|
-
request.env['HTTP_REFERER'] = '/back'
|
8
|
+
before :each do
|
10
9
|
@object = Object.new
|
11
10
|
stub(@object).result = { :some => 'array'}
|
12
11
|
|
13
12
|
mock(controller).find_or_create_response { @object }
|
14
13
|
mock(@object).update_attribute(:result, nil)
|
15
|
-
|
16
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'referrer set' do
|
17
|
+
|
18
|
+
before :each do
|
19
|
+
request.env['HTTP_REFERER'] = '/back'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should redirect to :back' do
|
23
|
+
get :new
|
24
|
+
|
25
|
+
response.should redirect_to("/back")
|
26
|
+
end
|
17
27
|
|
18
|
-
response.should redirect_to("/back")
|
19
28
|
end
|
29
|
+
|
30
|
+
context 'no referrer set' do
|
31
|
+
|
32
|
+
it 'should redirect to index' do
|
33
|
+
get :new
|
34
|
+
|
35
|
+
response.should redirect_to('/')
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
20
44
|
end
|
21
45
|
|
22
46
|
context '#create' do
|
@@ -155,6 +155,66 @@ describe Forms::Tags::Core do
|
|
155
155
|
@page = pages(:home)
|
156
156
|
mock_response
|
157
157
|
end
|
158
|
+
|
159
|
+
describe 'if_response' do
|
160
|
+
context 'response and result exist' do
|
161
|
+
it 'should render' do
|
162
|
+
@response.result[:results] = { :bogus => { :payment => true } }
|
163
|
+
|
164
|
+
tag = %{<r:response:if_response>success</r:response:if_response>}
|
165
|
+
exp = %{success}
|
166
|
+
@page.should render(tag).as(exp)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
context 'result does not exist' do
|
170
|
+
it 'should not render' do
|
171
|
+
@response.result = nil
|
172
|
+
|
173
|
+
tag = %{<r:response:if_response>failure</r:response:if_response>}
|
174
|
+
exp = %{}
|
175
|
+
@page.should render(tag).as(exp)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
context 'response does not exist' do
|
179
|
+
it 'should not render' do
|
180
|
+
@response = nil
|
181
|
+
|
182
|
+
tag = %{<r:response:if_response>failure</r:response:if_response>}
|
183
|
+
exp = %{}
|
184
|
+
@page.should render(tag).as(exp)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe 'unless_response' do
|
190
|
+
context 'response and result exist' do
|
191
|
+
it 'should not render' do
|
192
|
+
@response.result[:results] = { :bogus => { :payment => true } }
|
193
|
+
|
194
|
+
tag = %{<r:response:unless_response>failure</r:response:unless_response>}
|
195
|
+
exp = %{}
|
196
|
+
@page.should render(tag).as(exp)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
context 'result does not exist' do
|
200
|
+
it 'should not render' do
|
201
|
+
@response.result = nil
|
202
|
+
|
203
|
+
tag = %{<r:response:unless_response>success</r:response:unless_response>}
|
204
|
+
exp = %{success}
|
205
|
+
@page.should render(tag).as(exp)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
context 'response does not exist' do
|
209
|
+
it 'should not render' do
|
210
|
+
@response = nil
|
211
|
+
|
212
|
+
tag = %{<r:response:unless_response>success</r:response:unless_response>}
|
213
|
+
exp = %{success}
|
214
|
+
@page.should render(tag).as(exp)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
158
218
|
|
159
219
|
describe 'if_results' do
|
160
220
|
context 'extension sent results' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-forms-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 3.2.
|
9
|
+
- 5
|
10
|
+
version: 3.2.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- dirkkelly
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-22 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -28,7 +28,6 @@ extensions: []
|
|
28
28
|
extra_rdoc_files:
|
29
29
|
- README.md
|
30
30
|
files:
|
31
|
-
- .gitignore
|
32
31
|
- README.md
|
33
32
|
- Rakefile
|
34
33
|
- VERSION
|
@@ -81,8 +80,8 @@ homepage: http://github.com/squaretalent/radiant-forms-extension
|
|
81
80
|
licenses: []
|
82
81
|
|
83
82
|
post_install_message:
|
84
|
-
rdoc_options:
|
85
|
-
|
83
|
+
rdoc_options: []
|
84
|
+
|
86
85
|
require_paths:
|
87
86
|
- lib
|
88
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/.gitignore
DELETED