wizard_controller 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +80 -2
- data/lib/wizard_controller.rb +17 -6
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,3 +1,81 @@
|
|
1
|
-
Wizard Controller
|
1
|
+
= Wizard Controller
|
2
2
|
|
3
|
-
|
3
|
+
Wizard controller provides a base class (Inheriting from ActionController::Base)
|
4
|
+
that provides a DSL for quickly making Wizards.
|
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
|
+
VERY IMPORTANT!!! DONT OVERRIDE INDEX!
|
11
|
+
Doing so will break all functionality. WizardController works by defining an
|
12
|
+
"index" method that does all the work. To start a wizard, go to the "index" method.
|
13
|
+
|
14
|
+
=== Example Controller
|
15
|
+
|
16
|
+
class ExampleController < Codeprimate::Wizard::Base
|
17
|
+
# Define the method names of the wixard steps
|
18
|
+
define_steps :page_one, :page_two, :page_three
|
19
|
+
|
20
|
+
# Specify where the Wizard should redirect upon completion.
|
21
|
+
set_finish_path "http://www.example.com/go_here_when_done.html"
|
22
|
+
|
23
|
+
|
24
|
+
# Ensure "index" is not defined!
|
25
|
+
# def index
|
26
|
+
# end
|
27
|
+
|
28
|
+
def start
|
29
|
+
# Create a "safe" index method for this controller, and handle it appropriately
|
30
|
+
end
|
31
|
+
|
32
|
+
def foobar
|
33
|
+
# You can define whatever actions you want. WizardController doesnt get in the way.
|
34
|
+
end
|
35
|
+
|
36
|
+
def page_one
|
37
|
+
# This is a regular action method. Create indiviual views for action methods.
|
38
|
+
end
|
39
|
+
|
40
|
+
def process_page_one
|
41
|
+
# Place logic to handle any output from page one here.
|
42
|
+
# No view will be shown for this
|
43
|
+
#
|
44
|
+
# Return true if your logic wants you to go to the next step
|
45
|
+
# Return false if you want to return to the page_one view
|
46
|
+
return true
|
47
|
+
end
|
48
|
+
|
49
|
+
def page_two
|
50
|
+
# Let's say this action/view is merely informative.
|
51
|
+
# We will not supply a process method, and the user will always be able
|
52
|
+
# to go to the next step
|
53
|
+
end
|
54
|
+
|
55
|
+
def page_three
|
56
|
+
# Just another step method here
|
57
|
+
end
|
58
|
+
|
59
|
+
def process_page_three
|
60
|
+
# Since this is the last step, if this process method returns true
|
61
|
+
# the user will be redirected to the URL specified in the
|
62
|
+
# "set_finish_path" declaration at the beginning of the Controller definition
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
=== View Helper Methods
|
67
|
+
|
68
|
+
* <tt>step_number()</tt>: Current step index.
|
69
|
+
* <tt>total_steps()</tt>: Total Number of steps in the wizard.
|
70
|
+
* <tt>step_completed()</tt>: Returns boolean, whether the step has been completed.
|
71
|
+
* <tt>wizard_path()</tt>: Wizard index path. <b>THIS SHOULD BE THE ACTION PATH OF ALL FORMS/VIEWS WITH A "process" action.</b>
|
72
|
+
* <tt>next_step_path()</tt>: URL to the next step.
|
73
|
+
* <tt>previous_step_path()</tt>: URL to the previous step.
|
74
|
+
* <tt>reset_wizard_path()</tt>: URL to reset the Wizard.
|
75
|
+
* <tt>abort_wizard_path()</tt>: URL to abort the Wizard.
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
data/lib/wizard_controller.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Codeprimate
|
2
|
-
VERSION = "0.1.
|
2
|
+
VERSION = "0.1.6"
|
3
3
|
|
4
4
|
module Wizard
|
5
5
|
|
@@ -13,18 +13,26 @@ module Codeprimate
|
|
13
13
|
@wizard_default_error = 'There was a problem processing the last step.'
|
14
14
|
attr_accessor :wizard_steps, :finish_path, :abort_path, :wizard_default_error
|
15
15
|
|
16
|
+
# Define steps of the wizard.
|
17
|
+
#
|
18
|
+
# Should be an array of symbols.
|
16
19
|
def define_steps(*args)
|
17
20
|
self.wizard_steps = args
|
18
21
|
end
|
19
22
|
|
23
|
+
# Set the URL that a user is redirected to after finishing the Wizard.
|
24
|
+
#
|
25
|
+
# Should be a string
|
20
26
|
def set_finish_path(p)
|
21
27
|
self.finish_path = p
|
22
28
|
end
|
23
29
|
|
30
|
+
# Set the URL that a user is redirected to after aborting the Wizard.
|
24
31
|
def set_abort_path(p)
|
25
32
|
self.abort_path = p
|
26
33
|
end
|
27
34
|
|
35
|
+
# Set the flash message a user sees when a process_action method returns false
|
28
36
|
def set_default_error(e)
|
29
37
|
self.wizard_default_error = e
|
30
38
|
end
|
@@ -32,10 +40,7 @@ module Codeprimate
|
|
32
40
|
|
33
41
|
### PUBLIC ACTIONS
|
34
42
|
|
35
|
-
|
36
|
-
self.abort_path = p
|
37
|
-
end
|
38
|
-
|
43
|
+
# Internal.
|
39
44
|
def index
|
40
45
|
if finished
|
41
46
|
handle_finished_wizard
|
@@ -43,7 +48,8 @@ module Codeprimate
|
|
43
48
|
handle_unfinished_wizard
|
44
49
|
end
|
45
50
|
end
|
46
|
-
|
51
|
+
|
52
|
+
# Internal.
|
47
53
|
def next_step
|
48
54
|
if step_completed
|
49
55
|
incr_step
|
@@ -54,16 +60,21 @@ module Codeprimate
|
|
54
60
|
redirect_to :action => :index
|
55
61
|
end
|
56
62
|
|
63
|
+
# Internal.
|
57
64
|
def previous_step
|
58
65
|
decr_step
|
59
66
|
redirect_to :action => :index
|
60
67
|
end
|
61
68
|
|
69
|
+
# Public action to reset the wizard
|
62
70
|
def reset
|
63
71
|
reset_wizard
|
64
72
|
redirect_to :action => :index
|
65
73
|
end
|
66
74
|
|
75
|
+
# Assign finish path.
|
76
|
+
#
|
77
|
+
# Accepts a string.
|
67
78
|
def finish_path=(p)
|
68
79
|
unless p.blank?
|
69
80
|
session[:finish_path] = p
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wizard_controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Morgan
|
@@ -54,6 +54,6 @@ rubyforge_project: wizard_controller
|
|
54
54
|
rubygems_version: 1.3.5
|
55
55
|
signing_key:
|
56
56
|
specification_version: 3
|
57
|
-
summary: Wizard
|
57
|
+
summary: Wizard controller provides a base class (Inheriting from ActionController::Base) that provides a DSL for quickly making Wizards.
|
58
58
|
test_files: []
|
59
59
|
|