jeffp-wizardly 0.1.8.7 → 0.1.8.8
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/README.rdoc +24 -17
- data/lib/validation_group.rb +12 -1
- data/lib/wizardly/wizard/configuration.rb +1 -1
- data/lib/wizardly/wizard/configuration/methods.rb +29 -15
- metadata +29 -28
data/README.rdoc
CHANGED
@@ -15,6 +15,10 @@ Install
|
|
15
15
|
Examples
|
16
16
|
|
17
17
|
* http://github.com/jeffp/wizardly-examples
|
18
|
+
|
19
|
+
== Contributions
|
20
|
+
|
21
|
+
Thanks for feedback from Roland Schulz, Steve Hoeksema, Morgan Christiansson, Jonathan Clarke
|
18
22
|
|
19
23
|
== Description
|
20
24
|
|
@@ -23,14 +27,13 @@ DRY up the Rails MVC implementation of a wizard. In three easy steps, +wizardly
|
|
23
27
|
produces the scaffolding and controller of a multi-step wizard.
|
24
28
|
|
25
29
|
Features include:
|
26
|
-
* Model-based
|
27
|
-
* Wizard
|
28
|
-
* Wizard
|
29
|
-
*
|
30
|
-
*
|
31
|
-
*
|
32
|
-
*
|
33
|
-
* Rich in Configuration
|
30
|
+
* Model-based Wizard Definition
|
31
|
+
* Wizard Controller Macros
|
32
|
+
* Wizard Scaffold Generators
|
33
|
+
* Sizard Form Helpers
|
34
|
+
* Configurable Buttons
|
35
|
+
* Callbacks
|
36
|
+
* Paperclip Support
|
34
37
|
|
35
38
|
== Example
|
36
39
|
|
@@ -189,8 +192,8 @@ Here's a list of options for the +act_wizardly_for+ controller macro
|
|
189
192
|
:cancel => false
|
190
193
|
:guard => false
|
191
194
|
:mask_fields => [:password, :password_confirmation] (by default)
|
192
|
-
:persist_model => {:once
|
193
|
-
:form_data => {:sandbox
|
195
|
+
:persist_model => {:per_page|:once}
|
196
|
+
:form_data => {:session|:sandbox}
|
194
197
|
|
195
198
|
Setting the :skip option to +true+ tells the scaffold helpers to include a skip button on each page.
|
196
199
|
The :cancel option set to +false+ removes the 'cancel' button from the wizard views.
|
@@ -225,7 +228,7 @@ the application needs to navigate away and return to the wizard.
|
|
225
228
|
The guarding behavior works a little differently depending on the :form_data setting.
|
226
229
|
When :form_data is set to :session (the default behavior), guarding only occurs
|
227
230
|
for the initial entry. Once a user has entered the form and started it, while
|
228
|
-
form data is being kept, the application may thereafter enter anywhere. On the
|
231
|
+
form data is being kept, the application may thereafter enter anywhere. On the
|
229
232
|
contrary, if :form_data is set to :sandbox, entry is always guarded, and once the user
|
230
233
|
leaves the wizard, entry may only occur at the initial page (as the form data has
|
231
234
|
been reset).
|
@@ -233,13 +236,17 @@ been reset).
|
|
233
236
|
==== Persisting The Model
|
234
237
|
|
235
238
|
The :persist_model option controls how the model is saved, either :once or :per_page.
|
236
|
-
The default
|
237
|
-
|
238
|
-
|
239
|
-
|
239
|
+
The default setting :per_page, saves the model incrementally for each page that
|
240
|
+
validates according to its validation group. This setting may result in invalid and
|
241
|
+
incomplete records in the database.
|
242
|
+
|
243
|
+
This problem can be remedied by using the :once setting, in which case, form data is
|
244
|
+
kept in the session until the wizard is complete and then saved out to the database.
|
240
245
|
|
241
|
-
The
|
242
|
-
|
246
|
+
The :once option does not work in all cases, particularly for any attribute that
|
247
|
+
can not be marshalled and dumped in the session. In particular, this will not work
|
248
|
+
for forms with file uploads like any forms using Paperclip. When using Paperclip, use
|
249
|
+
the :per_page setting.
|
243
250
|
|
244
251
|
|
245
252
|
=== Buttons
|
data/lib/validation_group.rb
CHANGED
@@ -77,12 +77,17 @@ module ValidationGroup
|
|
77
77
|
# jeffp: delete fields
|
78
78
|
@current_validation_fields = nil
|
79
79
|
end
|
80
|
+
|
81
|
+
def reject_non_validation_group_errors
|
82
|
+
return unless validation_group_enabled?
|
83
|
+
self.errors.remove_on(@current_validation_fields)
|
84
|
+
end
|
80
85
|
|
81
86
|
# jeffp: optimizer for someone writing custom :validate method -- no need
|
82
87
|
# to validate fields outside the current validation group note: could also
|
83
88
|
# use in validation modules to improve performance
|
84
89
|
def should_validate?(attribute)
|
85
|
-
|
90
|
+
!self.validation_group_enabled? || (@current_validation_fields && @current_validation_fields.include?(attribute.to_sym))
|
86
91
|
end
|
87
92
|
|
88
93
|
def validation_group_enabled?
|
@@ -105,6 +110,12 @@ module ValidationGroup
|
|
105
110
|
add_error = @base.respond_to?(:should_validate?) ? @base.should_validate?(attribute.to_sym) : true
|
106
111
|
add_without_validation_group(attribute, msg, *args, &block) if add_error
|
107
112
|
end
|
113
|
+
|
114
|
+
def remove_on(attributes)
|
115
|
+
return unless attributes
|
116
|
+
attributes = [attributes] unless attributes.is_a?(Array)
|
117
|
+
@errors.reject!{|k,v| !attributes.include?(k.to_sym)}
|
118
|
+
end
|
108
119
|
|
109
120
|
def self.included(base) #:nodoc:
|
110
121
|
base.class_eval do
|
@@ -23,7 +23,7 @@ module Wizardly
|
|
23
23
|
@include_cancel_button = opts.key?(:cancel) ? opts[:cancel] : true
|
24
24
|
@guard_entry = opts.key?(:guard) ? opts[:guard] : true
|
25
25
|
@password_fields = opts[:mask_fields] || opts[:mask_passwords] || [:password, :password_confirmation]
|
26
|
-
@persist_model = opts[:persist_model] || :
|
26
|
+
@persist_model = opts[:persist_model] || :per_page
|
27
27
|
@form_data = opts[:form_data] || :session
|
28
28
|
raise(ArgumentError, ":persist_model option must be one of :once or :per_page", caller) unless [:once, :per_page].include?(@persist_model)
|
29
29
|
raise(ArgumentError, ":form_data option must be one of :sandbox or :session", caller) unless [:sandbox, :session].include?(@form_data)
|
@@ -85,7 +85,6 @@ EVENTS
|
|
85
85
|
page = @pages[id]
|
86
86
|
finish_button = self.button_for_function(:finish).id
|
87
87
|
next_button = self.button_for_function(:next).id
|
88
|
-
model_persist_line = self.persist_model_per_page? ? "@#{self.model}.save_without_validation!" : ''
|
89
88
|
|
90
89
|
(mb = StringIO.new) << <<-ONE
|
91
90
|
def #{page.name}
|
@@ -94,8 +93,7 @@ EVENTS
|
|
94
93
|
@wizard = wizard_config
|
95
94
|
@title = '#{page.title}'
|
96
95
|
@description = '#{page.description}'
|
97
|
-
|
98
|
-
@#{self.model} = build_wizard_model(h)
|
96
|
+
_build_wizard_model
|
99
97
|
if request.post? && callback_performs_action?(:_on_post_#{id}_form)
|
100
98
|
raise CallbackError, "render or redirect not allowed in :on_post(:#{id}) callback", caller
|
101
99
|
end
|
@@ -128,7 +126,6 @@ EVENTS
|
|
128
126
|
complete_wizard unless @do_not_complete
|
129
127
|
return
|
130
128
|
end
|
131
|
-
#{model_persist_line}
|
132
129
|
return if callback_performs_action?(:_on_#{id}_form_#{next_button})
|
133
130
|
redirect_to :action=>:#{self.next_page(id)}
|
134
131
|
THREE
|
@@ -139,7 +136,6 @@ EVENTS
|
|
139
136
|
complete_wizard unless @do_not_complete
|
140
137
|
return
|
141
138
|
end
|
142
|
-
#{model_persist_line}
|
143
139
|
return if callback_performs_action?(:_on_#{id}_form_#{next_button})
|
144
140
|
redirect_to :action=>:#{self.next_page(id)}
|
145
141
|
FOUR
|
@@ -147,7 +143,7 @@ EVENTS
|
|
147
143
|
|
148
144
|
mb << <<-ENSURE
|
149
145
|
ensure
|
150
|
-
|
146
|
+
_preserve_wizard_model
|
151
147
|
end
|
152
148
|
end
|
153
149
|
ENSURE
|
@@ -281,18 +277,36 @@ SANDBOX
|
|
281
277
|
_on_wizard_#{finish_button}
|
282
278
|
redirect_to(#{Utils.formatted_redirect(self.completed_redirect)}) unless self.performed?
|
283
279
|
end
|
284
|
-
def
|
285
|
-
if
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
280
|
+
def _build_wizard_model
|
281
|
+
if self.wizard_config.persist_model_per_page?
|
282
|
+
h = self.wizard_form_data
|
283
|
+
if (h && model_id = h['id'])
|
284
|
+
_model = #{self.model_class_name}.find(model_id)
|
285
|
+
_model.attributes = params[:#{self.model}]||{}
|
286
|
+
@#{self.model} = _model
|
287
|
+
return
|
291
288
|
end
|
289
|
+
@#{self.model} = #{self.model_class_name}.new(params[:#{self.model}])
|
290
|
+
else # persist data in session or flash
|
291
|
+
h = (self.wizard_form_data||{}).merge(params[:#{self.model}] || {})
|
292
|
+
@#{self.model} = #{self.model_class_name}.new(h)
|
292
293
|
end
|
293
|
-
#{self.model_class_name}.new(params)
|
294
294
|
end
|
295
|
-
|
295
|
+
def _preserve_wizard_model
|
296
|
+
return unless (@#{self.model} && !@wizard_completed_flag)
|
297
|
+
if self.wizard_config.persist_model_per_page?
|
298
|
+
@#{self.model}.save_without_validation!
|
299
|
+
if request.get?
|
300
|
+
@#{self.model}.errors.clear
|
301
|
+
else
|
302
|
+
@#{self.model}.reject_non_validation_group_errors
|
303
|
+
end
|
304
|
+
self.wizard_form_data = {'id'=>@#{self.model}.id}
|
305
|
+
else
|
306
|
+
self.wizard_form_data = @#{self.model}.attributes
|
307
|
+
end
|
308
|
+
end
|
309
|
+
hide_action :_build_wizard_model, :_preserve_wizard_model
|
296
310
|
|
297
311
|
def initial_referer
|
298
312
|
session[:#{self.initial_referer_key}]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeffp-wizardly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.8.
|
4
|
+
version: 0.1.8.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Patmon
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-10 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,55 +22,56 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
-
- lib/
|
25
|
+
- lib/generators
|
26
26
|
- lib/wizardly.rb
|
27
|
+
- lib/validation_group.rb
|
28
|
+
- lib/jeffp-wizardly.rb
|
27
29
|
- lib/wizardly
|
28
|
-
- lib/wizardly/
|
30
|
+
- lib/wizardly/wizard.rb
|
29
31
|
- lib/wizardly/wizard
|
32
|
+
- lib/wizardly/wizard/page.rb
|
30
33
|
- lib/wizardly/wizard/configuration.rb
|
31
34
|
- lib/wizardly/wizard/button.rb
|
35
|
+
- lib/wizardly/wizard/utils.rb
|
36
|
+
- lib/wizardly/wizard/dsl.rb
|
32
37
|
- lib/wizardly/wizard/configuration
|
33
38
|
- lib/wizardly/wizard/configuration/methods.rb
|
34
39
|
- lib/wizardly/wizard/text_helpers.rb
|
35
|
-
- lib/wizardly/
|
36
|
-
- lib/wizardly/wizard/page.rb
|
37
|
-
- lib/wizardly/wizard/dsl.rb
|
38
|
-
- lib/wizardly/wizard.rb
|
39
|
-
- lib/jeffp-wizardly.rb
|
40
|
-
- lib/generators
|
41
|
-
- rails_generators/wizardly_controller
|
42
|
-
- rails_generators/wizardly_controller/wizardly_controller_generator.rb
|
43
|
-
- rails_generators/wizardly_controller/templates
|
44
|
-
- rails_generators/wizardly_controller/templates/controller.rb.erb
|
45
|
-
- rails_generators/wizardly_controller/templates/helper.rb.erb
|
46
|
-
- rails_generators/wizardly_controller/USAGE
|
40
|
+
- lib/wizardly/action_controller.rb
|
47
41
|
- rails_generators/wizardly_app
|
48
|
-
- rails_generators/wizardly_app/templates
|
49
|
-
- rails_generators/wizardly_app/templates/wizardly.rake
|
50
42
|
- rails_generators/wizardly_app/USAGE
|
51
43
|
- rails_generators/wizardly_app/wizardly_app_generator.rb
|
44
|
+
- rails_generators/wizardly_app/templates
|
45
|
+
- rails_generators/wizardly_app/templates/wizardly.rake
|
52
46
|
- rails_generators/wizardly_scaffold
|
53
47
|
- rails_generators/wizardly_scaffold/wizardly_scaffold_generator.rb
|
48
|
+
- rails_generators/wizardly_scaffold/USAGE
|
54
49
|
- rails_generators/wizardly_scaffold/templates
|
50
|
+
- rails_generators/wizardly_scaffold/templates/style.css
|
51
|
+
- rails_generators/wizardly_scaffold/templates/form.html.haml.erb
|
52
|
+
- rails_generators/wizardly_scaffold/templates/form.html.erb
|
53
|
+
- rails_generators/wizardly_scaffold/templates/layout.html.haml.erb
|
54
|
+
- rails_generators/wizardly_scaffold/templates/layout.html.erb
|
55
55
|
- rails_generators/wizardly_scaffold/templates/images
|
56
|
-
- rails_generators/wizardly_scaffold/templates/images/skip.png
|
57
|
-
- rails_generators/wizardly_scaffold/templates/images/cancel.png
|
58
|
-
- rails_generators/wizardly_scaffold/templates/images/finish.png
|
59
56
|
- rails_generators/wizardly_scaffold/templates/images/next.png
|
57
|
+
- rails_generators/wizardly_scaffold/templates/images/finish.png
|
60
58
|
- rails_generators/wizardly_scaffold/templates/images/back.png
|
61
|
-
- rails_generators/wizardly_scaffold/templates/
|
62
|
-
- rails_generators/wizardly_scaffold/templates/
|
63
|
-
- rails_generators/wizardly_scaffold/templates/style.css
|
59
|
+
- rails_generators/wizardly_scaffold/templates/images/cancel.png
|
60
|
+
- rails_generators/wizardly_scaffold/templates/images/skip.png
|
64
61
|
- rails_generators/wizardly_scaffold/templates/helper.rb.erb
|
65
|
-
- rails_generators/
|
66
|
-
- rails_generators/
|
67
|
-
- rails_generators/
|
62
|
+
- rails_generators/wizardly_controller
|
63
|
+
- rails_generators/wizardly_controller/USAGE
|
64
|
+
- rails_generators/wizardly_controller/wizardly_controller_generator.rb
|
65
|
+
- rails_generators/wizardly_controller/templates
|
66
|
+
- rails_generators/wizardly_controller/templates/controller.rb.erb
|
67
|
+
- rails_generators/wizardly_controller/templates/helper.rb.erb
|
68
68
|
- CHANGELOG.rdoc
|
69
69
|
- init.rb
|
70
70
|
- LICENSE
|
71
71
|
- README.rdoc
|
72
72
|
has_rdoc: false
|
73
73
|
homepage: http://github.com/jeffp/wizardly/tree/master
|
74
|
+
licenses:
|
74
75
|
post_install_message:
|
75
76
|
rdoc_options: []
|
76
77
|
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
requirements: []
|
92
93
|
|
93
94
|
rubyforge_project:
|
94
|
-
rubygems_version: 1.
|
95
|
+
rubygems_version: 1.3.5
|
95
96
|
signing_key:
|
96
97
|
specification_version: 3
|
97
98
|
summary: Produces controllers and wizard scaffolding for models with validation_groups
|