radiant-forms-extension 3.2.0.beta.1 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.0.beta.1
1
+ 3.2.1
@@ -5,14 +5,15 @@ class FormsController < ApplicationController
5
5
  skip_before_filter :verify_authenticity_token
6
6
 
7
7
  def update
8
- @form = Form.find(params[:id])
9
-
10
8
  @page = Page.find(params[:page_id]) rescue Page.first
11
9
  @page.data = params
12
10
  @page.request = OpenStruct.new({
13
11
  :session => session # Creating a pretend response object
14
12
  })
15
13
 
14
+ @form = Form.find(params[:id])
15
+ @form.page = @page
16
+
16
17
  # We need a response object
17
18
  @response = find_or_create_response
18
19
  # Put the submitted data into the response object
@@ -27,15 +28,10 @@ class FormsController < ApplicationController
27
28
 
28
29
  @results = {}
29
30
  # Iterate through each configured extension
30
- @form[:extensions].each do |ext, config|
31
- # New Instance of the FormExtension class
32
- extension = ("Form#{ext.to_s.pluralize.classify}".constantize).new(@form, @page)
33
- # .pluralize.classify means singulars like business and address are converted correctly
34
-
35
- # Result of the extension create method gets merged
36
- result = extension.create
31
+ @form[:extensions].each do |name, config|
32
+ result = @form.call_extension(name,config)
37
33
 
38
- @results.merge!({ ext.to_sym => result }) # merges this extensions results
34
+ @results.merge!({ name.to_sym => result })
39
35
  session.merge!(result[:session]) if result[:session].present?
40
36
  end
41
37
  # Those results are merged into the response object
data/app/models/form.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  class Form < ActiveRecord::Base
2
2
 
3
+ attr_accessor :page
4
+
3
5
  default_scope :order => 'forms.title ASC'
4
6
 
5
7
  validates_presence_of :title
@@ -8,4 +10,19 @@ class Form < ActiveRecord::Base
8
10
  belongs_to :created_by, :class_name => 'User'
9
11
  belongs_to :updated_by, :class_name => 'User'
10
12
 
13
+ def call_extension(name,config)
14
+ result = {}
15
+ # Create a class from the config extension
16
+ extension = config[:extension]
17
+ if extension.present?
18
+ klass = "Form#{extension.to_s.pluralize.classify}".constantize
19
+ # .pluralize.classify means singulars like business and address are converted correctly
20
+ # Create a new instance of that extension
21
+ klass = (klass).new(self, self.page, config)
22
+
23
+ # Result of the extension create method gets merged
24
+ result = klass.create
25
+ end
26
+ end
27
+
11
28
  end
@@ -2,8 +2,6 @@ class FormMail
2
2
  include Forms::Models::Extension
3
3
 
4
4
  def create
5
- @body = @page.render_snippet(@form)
6
-
7
5
  begin
8
6
  FormMailer.deliver_mail(
9
7
  :recipients => recipients,
@@ -14,7 +12,8 @@ class FormMail
14
12
  :cc => cc,
15
13
  :headers => headers,
16
14
  :content_type => content_type,
17
- :charset => charset
15
+ :charset => charset,
16
+ :config => @config
18
17
  )
19
18
  @sent = true
20
19
  rescue Exception => exception
@@ -82,7 +81,14 @@ class FormMail
82
81
  end
83
82
 
84
83
  def body
85
- @body || ''
84
+ # This parses the content of the form
85
+ @parser = Radius::Parser.new(PageContext.new(@page), :tag_prefix => 'r')
86
+ if @config[:body]
87
+ @body = @parser.parse(@form.send(@config[:body]))
88
+ else
89
+ @body = @parser.parse(@form.content)
90
+ end
91
+ @body
86
92
  end
87
93
 
88
94
  def cc
@@ -29,14 +29,14 @@
29
29
  #form_body.page{'data-caption'=>'body'}
30
30
  = render '/admin/forms/filters'
31
31
  = form_form.text_area :body, :class => 'textarea large', :style => 'width: 100%'
32
+ #form_config.page{'data-caption'=>'config'}
33
+ = form_form.text_area :config, :class => 'textarea large', :style => 'width: 100%'
32
34
  #form_content.page{'data-caption'=>'content'}
33
35
  = render '/admin/forms/filters'
34
36
  = form_form.text_area :content, :class => 'textarea large', :style => 'width: 100%'
35
- #form_config.page{'data-caption'=>'config'}
36
- %p
37
- %span.reference_links
38
- Available
39
- = form_form.text_area :config, :class => 'textarea large', :style => 'width: 100%'
37
+ #form_content.page{'data-caption'=>'secondary'}
38
+ = render '/admin/forms/filters'
39
+ = form_form.text_area :secondary, :class => 'textarea large', :style => 'width: 100%'
40
40
 
41
41
  .form_bottom
42
42
  - render_region :form_bottom do |form_bottom|
@@ -0,0 +1,9 @@
1
+ class AddAnotherContentField < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :forms, :secondary, :text
4
+ end
5
+
6
+ def self.down
7
+ remove_column :forms, :secondary
8
+ end
9
+ end
@@ -6,14 +6,16 @@ module Forms
6
6
  base.class_eval do
7
7
  def current_response
8
8
  return @current_response if defined?(@current_response)
9
- @current_response = find_response
9
+ @current_response = find_or_create_response if request.session[:form_response]
10
10
  end
11
11
 
12
12
  def find_response
13
13
  response = nil
14
14
 
15
- if request.session[:form_response]
15
+ begin
16
16
  response = Response.find(request.session[:form_response])
17
+ rescue
18
+ response = nil
17
19
  end
18
20
 
19
21
  response
@@ -3,14 +3,14 @@ module Forms
3
3
  module Extension
4
4
  def self.included(base)
5
5
  base.class_eval do
6
- def initialize(form, page)
6
+ def initialize(form, page, config)
7
7
  @form = form
8
8
  @page = page
9
9
 
10
10
  @data = Forms::Config.deep_symbolize_keys(@page.data)
11
11
 
12
12
  # Sets the config to be the current environment config: checkout:
13
- @config = @form[:extensions][self.class.to_s.underscore.gsub('form_', '').to_sym]
13
+ @config = config
14
14
  end
15
15
 
16
16
  def current_user
@@ -157,7 +157,23 @@ module Forms
157
157
  }
158
158
  tag 'form:read' do |tag|
159
159
  Forms::Tags::Helpers.require!(tag,'form:read','name')
160
- data = Forms::Tags::Responses.retrieve(tag.locals.page.data, tag.attr['name'])
160
+ tag.locals.form_data ||= tag.locals.page.data
161
+
162
+ tag.locals.form_data = Forms::Tags::Responses.retrieve(tag.locals.form_data, tag.attr['name'])
163
+
164
+ tag.expand.present? ? tag.expand : tag.locals.form_data
165
+ end
166
+
167
+ tag 'form:read:each' do |tag|
168
+ result = ''
169
+
170
+ fields = tag.locals.form_data
171
+ fields.each do |index,data|
172
+ tag.locals.form_data = data
173
+ result << tag.expand
174
+ end
175
+
176
+ result
161
177
  end
162
178
 
163
179
  desc %{
@@ -196,6 +212,40 @@ module Forms
196
212
 
197
213
  result = Forms::Tags::Responses.retrieve(tag.locals.response.result, tag.attr['name']).to_s
198
214
  end
215
+
216
+ desc %{
217
+ Renders the numeric index value of an arbitrary array name incrementing this
218
+ value after every call.
219
+ *Usage:* _The following would render '0012'
220
+ <pre><code><r:index [array="widgets"] /><r:index array="snippets" /><r:index [array="widgets"] /><r:index [array="widgets"] /></code></pre>
221
+ }
222
+ tag 'index' do |tag|
223
+ key = tag.attr['array'] ||= 'array'
224
+
225
+ if tag.globals.indexes.present? # If the global indexes array exists
226
+ if tag.globals.indexes[key].nil? # Set the value of that index to zero if not present
227
+ tag.globals.indexes[key] = 0
228
+ end
229
+ else
230
+ tag.globals.indexes = { key => 0 } # Create the indexes array and that index
231
+ end
232
+
233
+ index = tag.globals.indexes[key] # Store the current value for return
234
+ tag.globals.indexes[key] += 1 # Increment the index value on the global object
235
+
236
+ index # Return the stored index
237
+ end
238
+
239
+ desc %{
240
+ Resets the counter on an array
241
+ *Usage:* _The following with render '010'
242
+ <pre><code><r:index [array="widgets"] /><r:index [array="widgets"] /><r:reset [array="widgets"] /><r:index [array="widgets"] /></code></pre>
243
+ }
244
+ tag 'reset' do |tag|
245
+ key = tag.attr['array'] ||= 'array'
246
+ tag.globals.indexes[key] = 0
247
+ nil
248
+ end
199
249
  end
200
250
  end
201
251
  end
@@ -6,7 +6,6 @@ module Forms
6
6
 
7
7
  def current(tag, request)
8
8
  response = nil
9
-
10
9
  if tag.locals.response.present?
11
10
  response = tag.locals.response
12
11
  elsif tag.locals.page.request.present?
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{radiant-forms-extension}
8
- s.version = "3.2.0.beta.1"
8
+ s.version = "3.2.1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
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-10-19}
12
+ s.date = %q{2010-10-23}
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 = [
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
43
43
  "db/migrate/003_rename_output_to_content.rb",
44
44
  "db/migrate/004_create_responses.rb",
45
45
  "db/migrate/20100929150423_change_to_updated_by_id.rb",
46
+ "db/migrate/20101012230144_add_another_content_field.rb",
46
47
  "forms_extension.rb",
47
48
  "lib/forms/config.rb",
48
49
  "lib/forms/controllers/application_controller.rb",
@@ -58,7 +59,7 @@ Gem::Specification.new do |s|
58
59
  "radiant-forms-extension.gemspec",
59
60
  "spec/controllers/forms_controller_spec.rb",
60
61
  "spec/datasets/forms.rb",
61
- "spec/lib/forms/tags_spec.rb",
62
+ "spec/lib/forms/tags/core_spec.rb",
62
63
  "spec/models/form_spec.rb",
63
64
  "spec/models/response_spec.rb",
64
65
  "spec/spec.opts",
@@ -72,7 +73,7 @@ Gem::Specification.new do |s|
72
73
  s.test_files = [
73
74
  "spec/controllers/forms_controller_spec.rb",
74
75
  "spec/datasets/forms.rb",
75
- "spec/lib/forms/tags_spec.rb",
76
+ "spec/lib/forms/tags/core_spec.rb",
76
77
  "spec/models/form_spec.rb",
77
78
  "spec/models/response_spec.rb",
78
79
  "spec/spec_helper.rb"
@@ -53,7 +53,7 @@ describe FormsController do
53
53
  context 'configuration exists' do
54
54
 
55
55
  it 'should assign the configuration settings' do
56
- assigns(:form)[:extensions][:test][:config].should == 'test'
56
+ assigns(:form)[:extensions][:test][:extension].should == 'test'
57
57
  end
58
58
 
59
59
  end
@@ -19,9 +19,10 @@ class FormsDataset < Dataset::Base
19
19
  :title => "test_form",
20
20
  :body => "<r:text name='request[test]' />",
21
21
  :content => "<r:form:read name='request[test]' />",
22
+ :secondary => "<r:form:read name='request[test]' />",
22
23
  :config => <<-CONFIG
23
24
  test:
24
- config: test
25
+ extension: test
25
26
  CONFIG
26
27
  }
27
28
  create_record :form, :test, attributes
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require 'spec/spec_helper'
2
2
 
3
- describe Forms::Tags do
3
+ describe Forms::Tags::Core do
4
4
  dataset :pages, :forms
5
5
 
6
6
  context 'form output' do
@@ -31,6 +31,10 @@ describe Form do
31
31
  @form.content.is_a?(String).should == true
32
32
  end
33
33
 
34
+ it 'should have an secondary string' do
35
+ @form.secondary.is_a?(String).should == true
36
+ end
37
+
34
38
  it 'should have a config string' do
35
39
  @form.config.is_a?(String).should == true
36
40
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-forms-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196449
5
- prerelease: true
4
+ hash: 13
5
+ prerelease: false
6
6
  segments:
7
7
  - 3
8
8
  - 2
9
- - 0
10
- - beta
11
9
  - 1
12
- version: 3.2.0.beta.1
10
+ version: 3.2.1
13
11
  platform: ruby
14
12
  authors:
15
13
  - dirkkelly
@@ -17,7 +15,7 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2010-10-19 00:00:00 +08:00
18
+ date: 2010-10-23 00:00:00 +08:00
21
19
  default_executable:
22
20
  dependencies: []
23
21
 
@@ -57,6 +55,7 @@ files:
57
55
  - db/migrate/003_rename_output_to_content.rb
58
56
  - db/migrate/004_create_responses.rb
59
57
  - db/migrate/20100929150423_change_to_updated_by_id.rb
58
+ - db/migrate/20101012230144_add_another_content_field.rb
60
59
  - forms_extension.rb
61
60
  - lib/forms/config.rb
62
61
  - lib/forms/controllers/application_controller.rb
@@ -72,7 +71,7 @@ files:
72
71
  - radiant-forms-extension.gemspec
73
72
  - spec/controllers/forms_controller_spec.rb
74
73
  - spec/datasets/forms.rb
75
- - spec/lib/forms/tags_spec.rb
74
+ - spec/lib/forms/tags/core_spec.rb
76
75
  - spec/models/form_spec.rb
77
76
  - spec/models/response_spec.rb
78
77
  - spec/spec.opts
@@ -98,14 +97,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
97
  required_rubygems_version: !ruby/object:Gem::Requirement
99
98
  none: false
100
99
  requirements:
101
- - - ">"
100
+ - - ">="
102
101
  - !ruby/object:Gem::Version
103
- hash: 25
102
+ hash: 3
104
103
  segments:
105
- - 1
106
- - 3
107
- - 1
108
- version: 1.3.1
104
+ - 0
105
+ version: "0"
109
106
  requirements: []
110
107
 
111
108
  rubyforge_project:
@@ -116,7 +113,7 @@ summary: Forms Extension for Radiant CMS
116
113
  test_files:
117
114
  - spec/controllers/forms_controller_spec.rb
118
115
  - spec/datasets/forms.rb
119
- - spec/lib/forms/tags_spec.rb
116
+ - spec/lib/forms/tags/core_spec.rb
120
117
  - spec/models/form_spec.rb
121
118
  - spec/models/response_spec.rb
122
119
  - spec/spec_helper.rb