wizard_controller 0.1.7 → 0.1.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.
Files changed (5) hide show
  1. data/History.txt +1 -0
  2. data/README.rdoc +19 -22
  3. data/lib/wizard_controller.rb +27 -12
  4. metadata +4 -4
  5. data/README +0 -3
@@ -1,2 +1,3 @@
1
+ 20100129: 0.1.8 Midwire added the direct_step action, and supporting 'direct_step_path' method, to allow handling of navigating to a step directly instead of always using next and previous.
1
2
  20091102: 0.1.5 Changed session variable that stores redirect information, to avoid conflicts.
2
3
  20090925: Packaged as Gem
@@ -3,46 +3,48 @@
3
3
  Wizard controller provides a base class (Inheriting from ActionController::Base)
4
4
  that provides a DSL for quickly making Wizards.
5
5
 
6
- In order for this to work, you need to have this standard route present:
7
-
8
- map.connect ':controller/:action/:id'
9
-
10
6
  VERY IMPORTANT!!! DONT OVERRIDE INDEX!
11
7
  Doing so will break all functionality. WizardController works by defining an
12
8
  "index" method that does all the work. To start a wizard, go to the "index" method.
13
9
 
14
10
  === Setup and Configuration
15
11
 
16
- Add the gem configuration to your config/environment.rb
12
+ Add the following gem configuration to <tt>config/environment.rb</tt>
17
13
 
18
14
  config.gem "wizard_controller"
19
15
 
16
+ Ensure the following is present in <tt>config/routes.rb</tt>
17
+
18
+ map.connect ':controller/:action/:id'
19
+
20
+ ... or explicitly map the routes you want to use.
21
+
20
22
  === Example Controller
21
23
 
22
24
  class ExampleController < Codeprimate::Wizard::Base
23
25
  # Define the method names of the wixard steps
24
26
  define_steps :page_one, :page_two, :page_three
25
-
27
+
26
28
  # Specify where the Wizard should redirect upon completion.
27
29
  set_finish_path "http://www.example.com/go_here_when_done.html"
28
-
30
+
29
31
 
30
32
  # Ensure "index" is not defined!
31
33
  # def index
32
34
  # end
33
-
35
+
34
36
  def start
35
37
  # Create a "safe" index method for this controller, and handle it appropriately
36
38
  end
37
-
39
+
38
40
  def foobar
39
41
  # You can define whatever actions you want. WizardController doesnt get in the way.
40
42
  end
41
-
43
+
42
44
  def page_one
43
45
  # This is a regular action method. Create indiviual views for action methods.
44
46
  end
45
-
47
+
46
48
  def process_page_one
47
49
  # Place logic to handle any output from page one here.
48
50
  # No view will be shown for this
@@ -51,24 +53,24 @@ Add the gem configuration to your config/environment.rb
51
53
  # Return false if you want to return to the page_one view
52
54
  return true
53
55
  end
54
-
56
+
55
57
  def page_two
56
58
  # Let's say this action/view is merely informative.
57
59
  # We will not supply a process method, and the user will always be able
58
60
  # to go to the next step
59
61
  end
60
-
62
+
61
63
  def page_three
62
64
  # Just another step method here
63
65
  end
64
-
66
+
65
67
  def process_page_three
66
68
  # Since this is the last step, if this process method returns true
67
69
  # the user will be redirected to the URL specified in the
68
70
  # "set_finish_path" declaration at the beginning of the Controller definition
69
71
  end
70
72
  end
71
-
73
+
72
74
  === View Helper Methods
73
75
 
74
76
  * <tt>step_number()</tt>: Current step index.
@@ -77,11 +79,6 @@ Add the gem configuration to your config/environment.rb
77
79
  * <tt>wizard_path()</tt>: Wizard index path. <b>THIS SHOULD BE THE ACTION PATH OF ALL FORMS/VIEWS WITH A "process" action.</b>
78
80
  * <tt>next_step_path()</tt>: URL to the next step.
79
81
  * <tt>previous_step_path()</tt>: URL to the previous step.
82
+ * <tt>direct_step_path()</tt>: URL to a direct step. Example for step 3: <code>direct_step_path(:id=>3)</code>. User will stay on the current step if they have not completed the one they are requesting.
80
83
  * <tt>reset_wizard_path()</tt>: URL to reset the Wizard.
81
- * <tt>abort_wizard_path()</tt>: URL to abort the Wizard.
82
-
83
-
84
-
85
-
86
-
87
-
84
+ * <tt>abort_wizard_path()</tt>: URL to abort the Wizard.
@@ -1,24 +1,22 @@
1
- module Codeprimate
2
- VERSION = "0.1.7"
3
-
1
+ module Codeprimate
4
2
  # = Wizard Controller
5
3
  #
6
4
  # Wizard controller provides a base class (Inheriting from ActionController::Base)
7
5
  # that provides a DSL for quickly making Wizards.
8
6
  #
9
- # In order for this to work, you need to have this standard route present:
10
- #
11
- # map.connect ':controller/:action/:id'
12
- #
13
7
  # VERY IMPORTANT!!! DONT OVERRIDE INDEX!
14
8
  # Doing so will break all functionality. WizardController works by defining an
15
9
  # "index" method that does all the work. To start a wizard, go to the "index" method.
16
10
  #
17
11
  # === Setup and Configuration
18
12
  #
19
- # Add the gem configuration to your config/environment.rb
13
+ # Add the following gem configuration to <tt>config/environment.rb</tt>
20
14
  #
21
15
  # config.gem "wizard_controller"
16
+ #
17
+ # Ensure the following is present in <tt>config/routes.rb</tt>
18
+ #
19
+ # map.connect ':controller/:action/:id'
22
20
  #
23
21
  # === Example Controller
24
22
  #
@@ -83,6 +81,7 @@ module Codeprimate
83
81
  # * <tt>reset_wizard_path()</tt>: URL to reset the Wizard.
84
82
  # * <tt>abort_wizard_path()</tt>: URL to abort the Wizard.
85
83
  module Wizard
84
+ VERSION = "0.1.7"
86
85
 
87
86
  class Base < ApplicationController
88
87
  before_filter :restrict_access, :init_wizard_session
@@ -151,6 +150,17 @@ module Codeprimate
151
150
  redirect_to :action => :index
152
151
  end
153
152
 
153
+ # Internal.
154
+ def direct_step
155
+ step = params[:id].to_i
156
+ if step_completed(step)
157
+ set_current_wizard_step([1, step].max)
158
+ else
159
+ flash[:error] ||= self.class.wizard_default_error
160
+ end
161
+ redirect_to :action => :index
162
+ end
163
+
154
164
  # Public action to reset the wizard
155
165
  def reset
156
166
  reset_wizard
@@ -199,7 +209,7 @@ module Codeprimate
199
209
  end
200
210
 
201
211
  def restrict_access
202
- ['index', 'next_step', 'previous_step', 'reset'].include?(params[:action])
212
+ ['index', 'next_step', 'previous_step', 'direct_step', 'reset'].include?(params[:action])
203
213
  end
204
214
 
205
215
  def execute_method(m=current_wizard_step_method)
@@ -234,9 +244,14 @@ module Codeprimate
234
244
  url_for(:controller => self.controller_name, :action => :previous_step)
235
245
  end
236
246
 
247
+ helper_method :direct_step_path
248
+ def direct_step_path(step)
249
+ url_for(:controller => self.controller_name, :action => :direct_step, :id => step)
250
+ end
251
+
237
252
  helper_method :step_completed
238
- def step_completed
239
- session[:wizard][self.class.to_s][:completed][current_wizard_step] == true
253
+ def step_completed(direct_step = current_wizard_step)
254
+ session[:wizard][self.class.to_s][:completed][direct_step] == true
240
255
  end
241
256
 
242
257
  helper_method :wizard_path
@@ -273,7 +288,7 @@ module Codeprimate
273
288
  def decr_step
274
289
  set_current_wizard_step([1, (current_wizard_step - 1)].max)
275
290
  end
276
-
291
+
277
292
  def current_wizard_step_method
278
293
  self.class.wizard_steps[(current_wizard_step - 1)]
279
294
  end
metadata CHANGED
@@ -1,20 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wizard_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Morgan
8
+ - Midwire
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-11-02 00:00:00 -06:00
13
+ date: 2010-02-02 00:00:00 -06:00
13
14
  default_executable:
14
15
  dependencies: []
15
16
 
16
17
  description: Wizard Controller is an inheritable class to ease the creation of Wizards
17
- email: patrick.morgan@masterwebdesign.net
18
+ email: patrick.morgan@masterwebdesign.net midwire@midwire.com
18
19
  executables: []
19
20
 
20
21
  extensions: []
@@ -22,7 +23,6 @@ extensions: []
22
23
  extra_rdoc_files: []
23
24
 
24
25
  files:
25
- - README
26
26
  - README.rdoc
27
27
  - History.txt
28
28
  - lib/wizard_controller.rb
data/README DELETED
@@ -1,3 +0,0 @@
1
- Wizard Controller
2
-
3
- Make your controller inherit from this class.