Permalink
Browse files

first import

  • Loading branch information...
0 parents commit bb190e568bf78465be898c1242cd9c0e9049521c @jeffp committed Aug 2, 2009
Showing with 11,013 additions and 0 deletions.
  1. +12 −0 .gitignore
  2. +28 −0 CHANGELOG.rdoc
  3. +20 −0 LICENSE
  4. +412 −0 README.rdoc
  5. +108 −0 Rakefile
  6. +10 −0 app/controllers/application_controller.rb
  7. +37 −0 app/controllers/callbacks_controller.rb
  8. +227 −0 app/controllers/generated_controller.rb
  9. +7 −0 app/controllers/macro_controller.rb
  10. +28 −0 app/controllers/main_controller.rb
  11. +8 −0 app/controllers/scaffold_test_controller.rb
  12. +3 −0 app/helpers/application_helper.rb
  13. +14 −0 app/helpers/callbacks_helper.rb
  14. +14 −0 app/helpers/generated_helper.rb
  15. +14 −0 app/helpers/scaffold_test_helper.rb
  16. +9 −0 app/models/four_step_user.rb
  17. +22 −0 app/models/user.rb
  18. +31 −0 app/views/callbacks/finish.html.erb
  19. +26 −0 app/views/callbacks/init.html.erb
  20. +26 −0 app/views/callbacks/second.html.erb
  21. +26 −0 app/views/callbacks/third.html.erb
  22. +8 −0 app/views/generated/finish.html.erb
  23. +7 −0 app/views/generated/init.html.erb
  24. +10 −0 app/views/generated/second.html.erb
  25. +9 −0 app/views/layouts/application.html.erb
  26. +15 −0 app/views/layouts/callbacks.html.erb
  27. +15 −0 app/views/layouts/scaffold_test.html.erb
  28. +8 −0 app/views/macro/finish.html.erb
  29. +7 −0 app/views/macro/init.html.erb
  30. +10 −0 app/views/macro/second.html.erb
  31. +7 −0 app/views/main/canceled.html.erb
  32. +7 −0 app/views/main/finished.html.erb
  33. +3 −0 app/views/main/index.html.erb
  34. +7 −0 app/views/main/referrer_page.html.erb
  35. +31 −0 app/views/scaffold_test/finish.html.erb
  36. +26 −0 app/views/scaffold_test/init.html.erb
  37. +36 −0 app/views/scaffold_test/second.html.erb
  38. +110 −0 config/boot.rb
  39. +22 −0 config/database.yml
  40. +45 −0 config/environment.rb
  41. +17 −0 config/environments/development.rb
  42. +28 −0 config/environments/production.rb
  43. +30 −0 config/environments/test.rb
  44. +7 −0 config/initializers/backtrace_silencers.rb
  45. +10 −0 config/initializers/inflections.rb
  46. +5 −0 config/initializers/mime_types.rb
  47. +19 −0 config/initializers/new_rails_defaults.rb
  48. +15 −0 config/initializers/session_store.rb
  49. +5 −0 config/locales/en.yml
  50. +44 −0 config/routes.rb
  51. BIN db/development.sqlite3
  52. +16 −0 db/migrate/20090718171255_create_sessions.rb
  53. +20 −0 db/migrate/20090718172749_create_users.rb
  54. 0 db/production.sqlite3
  55. +37 −0 db/schema.rb
  56. BIN db/test.sqlite3
  57. +1 −0 init.rb
  58. +6 −0 lib/generators/wizardly_app/USAGE
  59. +33 −0 lib/generators/wizardly_app/templates/wizardly.rake
  60. +41 −0 lib/generators/wizardly_app/wizardly_app_generator.rb
  61. +3 −0 lib/generators/wizardly_controller/USAGE
  62. +45 −0 lib/generators/wizardly_controller/templates/controller.rb.erb
  63. +14 −0 lib/generators/wizardly_controller/templates/helper.rb.erb
  64. +54 −0 lib/generators/wizardly_controller/wizardly_controller_generator.rb
  65. +4 −0 lib/generators/wizardly_scaffold/USAGE
  66. +23 −0 lib/generators/wizardly_scaffold/templates/form.html.erb
  67. +14 −0 lib/generators/wizardly_scaffold/templates/helper.rb.erb
  68. +15 −0 lib/generators/wizardly_scaffold/templates/layout.html.erb
  69. +54 −0 lib/generators/wizardly_scaffold/templates/style.css
  70. +90 −0 lib/generators/wizardly_scaffold/wizardly_scaffold_generator.rb
  71. +31 −0 lib/wizardly.rb
  72. +49 −0 lib/wizardly/action_controller.rb
  73. +116 −0 lib/wizardly/validation_group.rb
  74. +15 −0 lib/wizardly/wizard.rb
  75. +26 −0 lib/wizardly/wizard/button.rb
  76. +168 −0 lib/wizardly/wizard/configuration.rb
  77. +186 −0 lib/wizardly/wizard/configuration/methods.rb
  78. +27 −0 lib/wizardly/wizard/dsl.rb
  79. +57 −0 lib/wizardly/wizard/page.rb
  80. +13 −0 lib/wizardly/wizard/text_helpers.rb
  81. +11 −0 lib/wizardly/wizard/utils.rb
  82. +30 −0 public/404.html
  83. +30 −0 public/422.html
  84. +30 −0 public/500.html
  85. 0 public/favicon.ico
  86. BIN public/images/rails.png
  87. +2 −0 public/javascripts/application.js
  88. +963 −0 public/javascripts/controls.js
  89. +973 −0 public/javascripts/dragdrop.js
  90. +1,128 −0 public/javascripts/effects.js
  91. +4,320 −0 public/javascripts/prototype.js
  92. +5 −0 public/robots.txt
  93. +54 −0 public/stylesheets/scaffold.css
  94. +4 −0 script/about
  95. +6 −0 script/autospec
  96. +3 −0 script/console
  97. +3 −0 script/dbconsole
  98. +3 −0 script/destroy
  99. +3 −0 script/generate
  100. +3 −0 script/performance/benchmarker
  101. +3 −0 script/performance/profiler
  102. +3 −0 script/plugin
  103. +3 −0 script/runner
  104. +3 −0 script/server
  105. +10 −0 script/spec
  106. +9 −0 script/spec_server
  107. +7 −0 spec/fixtures/users.yml
  108. +77 −0 spec/integrations/callbacks_spec.rb
  109. +43 −0 spec/integrations/generated_spec.rb
  110. +34 −0 spec/integrations/macro_spec.rb
  111. +12 −0 spec/integrations/matchers.rb
  112. +41 −0 spec/integrations/scaffold_test_spec.rb
  113. +157 −0 spec/integrations/shared_examples.rb
  114. +12 −0 spec/models/user_specd.rb
  115. +2 −0 spec/rcov.opts
  116. +4 −0 spec/spec.opts
  117. +41 −0 spec/spec_helper.rb
  118. +21 −0 test/fixtures/users.yml
  119. +62 −0 test/functional/callbacks_controller_test.rb
  120. +9 −0 test/performance/browsing_test.rb
  121. +47 −0 test/test_helper.rb
  122. +4 −0 test/unit/helpers/callbacks_helper_test.rb
  123. +8 −0 test/unit/user_test.rb
  124. +27 −0 wizardly.gemspec
12 .gitignore
@@ -0,0 +1,12 @@
+.DS_Store
+**/*.log
+pkg
+rdoc
+coverage
+doc
+log
+nbproject
+tmp
+vendor
+rails_generators
+lib/tasks
28 CHANGELOG.rdoc
@@ -0,0 +1,28 @@
+== master
+
+== 0.0.1 / 2009-07-28
+
+* Created wizard implementation for submit_tag buttons
+* Created WizardConfig, WizardPage and WizardButton
+* Added wizard functions to validation_group (by alex kira)
+* Created validation_group gem
+* Added Implementation, Macro, Generated Controllers
+* Refactored spec integration tests for the three controllers
+* Created Wizardized_controller generator
+
+== 0.0.2 / 2009-07-29
+
+* script/generate wizardly_scaffold controller_name
+
+== 0.0.3 / 2009-07-30
+
+* added render_wizard_page for respond_to handling
+* added wizard button and page callbacks
+* tests for callbacks
+
+== 0.0.3 / 2009-08-01
+
+* refactored into library
+* integrated validation_groups until later
+* renamed to act_wizardly_for
+
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2006-2009 Jeff Patmon
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
412 README.rdoc
@@ -0,0 +1,412 @@
+= wizardly
+
++wizardly+ produces a working wizard from any ActiveRecord model in three steps.
+
+== Resources
+
+Development
+
+* http://github.com/jeffp/wizardly
+
+Source
+
+* git://github.com/jeffp/wizardly.git
+
+Install
+
+* sudo gem install jeffp-wizardly --source=http://gems.github.com
+
+== Description
+
+Wizards are a common and useful pattern in programming. Typically, in Ruby,
+enumerated attributes are implemented with strings, symbols or constants. Often the
+developer is burdened with repeatedly defining common methods in support of each
+attribute. Such repetition coding unnecessarily increases
+costs and wastes time.
+
++enumerated_attribute+ simplifies the definition of enumerated attributes by emphasizing
+convention and DRYing the implementation. Repetitive code such as initializers, accessors,
+predicate and enumeration methods are automatically generated, resulting in better
+encapsulation, quicker implementation and cleaner code.
+
+Features include:
+* Short and simple definition
+* Auto-defined attribute methods
+* Dynamically-generated predicate methods
+* Attribute initialization
+* Method definition short-hand (DSL)
+* ActiveRecord integration
+
+== Example
+
+Create a working controller wizard for any model in 3 steps. Here's how:
+
+Step 1: Define validation groups for your model.
+
+ require 'validation_group'
+ class User < ActiveRecord::Base
+ validation_group :step1, :fields=>[:first_name, :last_name]
+ ...
+ end
+
+Step 2: Tell your controller to act 'wizardly'.
+
+ require 'wizardly'
+ class SignupController < ActionController::Base
+ wizard_for_model :user
+ end
+
+Step 3: Generate 'wizardly' views for your controller.
+
+ ./script/generate wizardly_scaffold :signup
+
+You are ready to go.
+
+
+== Usage
+
+=== Defining the Attribute
+
+Defining an enumerated attribute is as simple as this:
+
+ require 'enumerated_attribute'
+
+ class Tractor
+ enumerated_attribute :gear, %w(reverse neutral first second over_drive)
+
+ def initialize
+ @gear = :neutral
+ end
+ end
+
+Notice the plugin +enumerated_attribute+ is required at the top of the code.
+The +require+ line must be added at least once at some point in the code.
+It is not included in subsequent examples.
+
+The above code uses +enumerated_attribute+ to define an attribute named 'gear' with five enumeration values.
+In general, +enumerated_attribute+ takes three parameters: the name of the attribute, an array of
+enumeration values (either symbols or strings), and an optional hash of options (not shown above). The complete
+form of +enumerated_attribute+ looks like this:
+
+ enumerated_attribute :name, array_of_enumerations, hash_of_options
+
+Defining the attribute :gear has done a number things.
+It has generated an instance variable '@gear', read/write accessors for the
+attribute and support methods
+for the enumeration, such as incrementor and decrementor methods. These methods are
+demonstrated below using the Tractor class above:
+
+ Tractor.instance_methods(false)
+ # =>["gear", "gear=", "gears", "gear_next", "gear_previous", ...
+
+ t = Tractor.new
+ t.gear # => :neutral
+ t.gear = :reverse # => :reverse
+ t.gear # => :reverse
+ t.gear = :third
+ # => ArgumentError: 'third' is not an enumerated value for gear attribute
+
+ t.gears # => [:reverse, :neutral, :first, :second, :over_drive]
+ t.gear_next # => :neutral
+ t.gear_previous # => :reverse
+ t.gear_previous # => :over_drive
+
+The plugin has defined +gear+ and gear= accessors for the attribute. They can be used
+to set the attribute to one of the defined enumeration values. Attempting to set the
+attribute to something besides a defined enumeration value raises an ArgumentError.
+
++gear_next+ and +gear_previous+ are incrementors and decrementors of the attribute.
+The increment order is based on the order of the enumeration values in the attribute definition.
+Both the incrementor and decrementor will wrap when reaching the boundary elements
+of the enumeration array. For example:
+
+ t.gear = :second
+ t.gear_next # => :over_drive
+ t.gear_next # => :reverse
+
+
+==== Dynamically-Generating Predicates Methods
+
+Predicate methods are methods that query the state of the attribute,
+for instance, gear_is_neutral? is a predicate method that returns 'true' if
+the gear attribute is in the :neutral state.
+By default, predicate methods are not predefined, instead, they are dynamically generated.
+The plugin will evaluate and respond to methods adhering to a format that it
+can associate with an attribute name and one of the attribute's enumeration values.
++enumerated_attribute+ recognizes predicate methods of the following format:
+
+ {attribute name}_{anything}_{enumeration value}?
+
+The predicate method must satisfy three requirements: it must begin with the name
+of the attribute,
+it must end with a question mark, and the question mark must be preceded with
+a valid enumeration value (all connected by underscores without colons).
+So we can write the following two predicate methods without any prior definition and
+the plugin will recognize, define and respond to them as demonstrated here:
+
+ t.gear= :neutral
+ t.gear_is_in_neutral? # => true
+ t.gear_is_in_reverse? # => false
+
+The '_is_in_' part of the methods above is merely semantic but enhances
+readability. The contents of the {anything} portion is completely
+at the discretion of the developer. However, there is one twist.
+The evaluation of a predicate method can be negated
+by including 'not' in the the middle {anything} section, such as here:
+
+ t.gear_is_not_in_neutral? # => false
+ t.gear_is_not_in_reverse? # => true
+
+Basically, the shortest acceptable form of a predicate method is:
+
+ t.gear_neutral? # => true
+ t.gear_not_neutral? # => false
+
+
+==== Abbreviating Predicate Methods
+
+In the case that an enumeration value is associated with only one
+attribute, the attribute name can be left out of the predicate method name.
+The plugin will infer the attribute from the enum value in the method name.
+The abbreviate format can be written like this:
+
+ {anything}{_}{enumeration value}?
+
+And results in the following possibilities:
+
+ t.gear = :neutral
+ t.neutral? # => true
+ t.is_neutral? # => true
+ t.not_neutral? # => false
+ t.is_not_neutral? # => false
+
+Calling the abbreviated form of the method containing an enumeration value
+belonging to two or more attributes throws an AmbiguousMethod error.
+
+
+==== Initializing Attributes
+
+The plugin provides a few ways to eliminate setting the initial value of the attribute in
+the +initialize+ method. Two ways are demonstrated here:
+
+ class Tractor
+ enum_attr :gear, %w(reverse ^neutral first second third)
+ enum_attr :front_light, %w(off low high), :init=>:off
+ end
+
+ t = Tractor.new
+ t.gear # => :neutral
+ t.front_light # => :off
+
+*Note* +enumerated_attribute+ can be abbreviated to +enum_attr+. The abbreviated
+form will be used in subsequent examples.
+
+The first and simplest way involves designating the initial value by
+prepending a carot '^' to one of the enumeration values in the definition.
+The plugin recognizes that the gear attribute is to be initialized to :neutral.
+Alternatively, the :init option can be used to indicate the initial value of the attribute.
+
+
+==== Setting Attributes to nil
+
+By default, the attribute setter does not allow nils unless the :nil option is set to true
+in the definition as demonstrated here:
+
+ class Tractor
+ enum_attr :plow, %w(^up down), :nil=>true
+ end
+
+ t = Tractor.new
+ t.plow # => :up
+ t.plow_nil? # => :false
+ t.plow = nil # => nil
+ t.plow_is_nil? # => true
+ t.plow_is_not_nil? # => false
+
+Regardless of the :nil option setting, the plugin can dynamically recognize and define
+predicate methods for testing 'nil' values.
+
+
+==== Changing Method Names
+
+The plugin provides options for changing the method names of the enumeration accessor, incrementor
+and decrementor (ie, +gears+, +gear_next+, +gear_previous+):
+
+ class Tractor
+ enum_attr :lights, %w(^off low high), :plural=>:lights_values,
+ :inc=>'lights_inc', :dec=>'lights_dec'
+ end
+
+ t = Tractor.new
+ t.lights_values # => [:off, :low, :high]
+ t.lights_inc # => :low
+ t.lights_dec # => :off
+
+By default, the plugin uses the plural of the attribute for the accessor method name of the enumeration
+values. The pluralization uses a simple algorithm which does not support irregular forms. In
+the case of 'lights' as an
+attribute, the default pluralization does not work, so the accessor can be changed using
+the :plural option. Likewise, the decrementor
+and incrementor have options :decrementor and :incrementor, or :inc and :dec, for changing
+their method names.
+
+
+=== Defining Other Methods
+
+In the case that other methods are required to support the attribute,
+the plugin provides a short-hand for defining these methods in the
++enumerated_attribute+ block.
+
+ class Tractor
+ enum_attr :gear, %w(reverse ^neutral first second over_drive) do
+ parked? :neutral
+ driving? [:first, :second, :over_drive]
+ end
+ end
+
+ t = Tractor.new
+ t.parked? # => true
+ t.driving? # => false
+
+Two predicate methods are defined for the 'gear' attribute in the above example using
+the plugin's short-hand.
+The first method, parked?, defines a method which evaluates
+the code {@gear == :neutral}. The second method, driving?, evaluates
+to true if the attribute is set to one of the enumeration values defined in the array
+[:first, :second, :over_drive].
+
+The same short-hand can be used to define methods where the attribute 'is not' equal to the
+indicated value or 'is not' included in the array of values.
+
+ class Tractor
+ enum_attr :gear, %w(reverse ^neutral first second over_drive) do
+ not_parked? is_not :neutral
+ not_driving? is_not [:first, :second, :over_drive]
+ end
+ end
+
+
+==== Defining Other Methods With Blocks
+
+For predicate methods requiring fancier logic,
+a block can be used to define the method body.
+
+ class Tractor
+ enum_attr :gear, %w(reverse ^neutral first second over_drive) do
+ parked? :neutral
+ driving? [:first, :second, :over_drive]
+ end
+ enum_attr :plow, %w(^up down), :plural=>:plow_values do
+ plowing? { self.gear_is_in_first? && @plow == :down }
+ end
+ end
+
+Here, a method plowing? is true if the gear attribute equates to :first
+and the plow attribute is set to :down. There is
+no short-hand for the block. The code must be complete and evaluate in
+the context of the instance.
+
+Method definitions are not limited to predicate methods. Other methods
+can be defined to manipulate the attributes. Here, two methods are defined acting
+as bounded incrementor and decrementor of the gear attribute.
+
+ class Tractor
+ enum_attr :gear, %w(reverse ^neutral first second over_drive) do
+ parked? :neutral
+ driving? [:first, :second, :over_drive]
+ upshift { self.gear_is_in_over_drive? ? self.gear : self.gear_next }
+ downshift { self.driving? ? self.gear_previous : self.gear }
+ end
+ end
+
+ t = Tractor.new
+ t.gear # => :neutral
+ 10.times { t.upshift }
+ t.gear # => :over_drive
+ 10.times { t.downshift }
+ t.gear # => :neutral
+
+Methods +upshift+ and +downshift+ use the automatically generated
+incrementor and decrementor as
+well as a couple predicate methods. +upshift+ increments the gear attribute until
+it reaches over_drive and does not allow a wrap around. +downshift+ decrements
+until the attribute reaches neutral.
+
+=== Integration
+
+==== ActiveRecord integration
+
+The plugin can be used with ActiveRecord. Enumerated attributes may be declared on
+column attributes or as independent enumerations. Declaring an enumerated attribute
+on a column attribute will enforce the enumeration using symbols. The
+enumerated column attribute must be declared as a STRING in the database schema.
+The enumerated attribute will be stored as a string but retrieved in code as a symbol. The
+enumeration functionality is consistent across integrations.
+
+ require 'enumerated_attribute'
+ require 'active_record'
+
+ class Order < ActiveRecord::Base
+ enum_attr :status, %w(^hold, processing, delayed, shipped)
+ enum_attr :billing_status,
+ %w(^unauthorized, authorized, auth_failed, captured, capture_failed, closed)
+ end
+
+ o = Order.new
+ o.status # => :hold
+ o.billing_status # => :unauthorized
+ o.save!
+
+ o = Order.new(:invoice=>'43556334-W84', :status=>:processing, :billing=>:authorized)
+ o.save!
+ o.status # => :processing
+ o.invoice # => "43556334-W84"
+
+
+=== Implementation Notes
+
+==== New and Method_missing methods
+
+The plugin chains both the 'new' and the 'method_missing' methods. Any 'new' and 'method_missing'
+implementations in the same class declaring an enumerated_attribute should come before the
+declaration; otherwise, the 'new' and 'method_missing' implementations must chain in order to avoid
+overwriting the plugin's methods. The best approach is shown here:
+
+ class Soup
+ def self.new(*args)
+ ...
+ end
+
+ private
+ def method_missing(methId, *args, &blk)
+ ...
+ end
+
+ enum_attr temp:, %w(cold warm hot boiling)
+ end
+
+
+== Testing
+
+The plugin uses RSpec for testing. Make sure you have the RSpec gem installed:
+
+ gem install rspec
+
+To test the plugin for regular ruby objects, run:
+
+ rake spec
+
+Testing ActiveRecord integration requires the install of Sqlite3 and the
+sqlite3-ruby gem. To test ActiveRecord, run:
+
+ rake spec:active_record
+
+To test all specs:
+
+ rake spec:all
+
+
+== Dependencies
+
+* ActiveRecord
+* Sqlite3 and sqlite3-ruby gem (for testing)
108 Rakefile
@@ -0,0 +1,108 @@
+$: << 'lib'
+# Add your own tasks in files placed in lib/tasks ending in .rake, for example
+# lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+require 'rake/gempackagetask'
+
+require 'tasks/rails'
+require 'fileutils'
+
+spec = Gem::Specification.new do |s|
+ s.name = 'wizardly'
+ s.version = '0.1.0'
+ s.platform = Gem::Platform::RUBY
+ s.description = 'Create wizards from any model in three steps'
+ s.summary = 'Produces controllers and wizard scaffolding for models with validation_groups'
+
+ #move all files in lib/generators -> rails_generators
+ FileUtils.rm_rf "rails_generators"
+ FileUtils.mkdir "rails_generators"
+ FileUtils.cp_r "lib/generators/.", "rails_generators"
+ s.files = FileList['{lib,rails_generators}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE README.rdoc) - FileList['**/*.log','lib/generators','lib/tasks']
+ s.require_path = 'lib'
+ s.has_rdoc = true
+ #s.test_files = Dir['spec/*_spec.rb']
+
+ s.author = 'Jeff Patmon'
+ s.email = 'jpatmon@yahoo.com'
+ s.homepage = 'http://github.com/jeffp/wizardly/tree/master'
+end
+
+require 'spec/version'
+require 'spec/rake/spectask'
+
+
+
+namespace :spec do
+ desc "Run all specs"
+ task :all=>[:macro, :gen, :scaffold, :callbacks]
+ desc "Test the MacroController"
+ Spec::Rake::SpecTask.new(:macro) do |t|
+ t.spec_files = FileList['spec/integrations/macro_spec.rb']
+ t.libs << 'lib' << 'spec' << 'spec/integrations'
+ t.spec_opts = ['--options', 'spec/spec.opts']
+ t.rcov = false
+ end
+ desc "Test the GeneratedController"
+ Spec::Rake::SpecTask.new(:gen=>[:generate_controller]) do |t|
+ t.spec_files = FileList['spec/integrations/generated_spec.rb']
+ t.libs << 'lib' << 'spec' << 'spec/integrations'
+ t.spec_opts = ['--options', 'spec/spec.opts']
+ t.rcov = false
+ end
+ desc "Generate GeneratedController for spec test"
+ task :generate_controller=>[:environment] do
+ require 'rails_generator'
+ require 'rails_generator/scripts/generate'
+ gen_argv = []
+ gen_argv << "wizardly_controller" << "generated" << "user" << "/main/finished" << "/main/canceled" << "--force"
+ Rails::Generator::Scripts::Generate.new.run(gen_argv)
+ end
+ desc "Test the ScaffoldTestController"
+ Spec::Rake::SpecTask.new(:scaffold) do |t|
+ t.spec_files = FileList['spec/integrations/scaffold_test_spec.rb']
+ t.libs << 'lib' << 'spec' << 'spec/integrations'
+ t.spec_opts = ['--options', 'spec/spec.opts']
+ t.rcov = false
+ end
+ desc "Test the CallbacksController"
+ Spec::Rake::SpecTask.new(:callback) do |t|
+ t.spec_files = FileList['spec/integrations/callbacks_spec.rb']
+ t.libs << 'lib' << 'spec' << 'spec/integrations'
+ t.spec_opts = ['--options', 'spec/spec.opts']
+ t.rcov = false
+ end
+end
+
+
+desc "Generate documentation for the #{spec.name} plugin."
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = spec.name
+ # #rdoc.template = '../rdoc_template.rb'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG.rdoc', 'LICENSE', 'lib/wizardly.rb', 'lib/wizardly/**/*.rb')
+end
+
+desc 'Generate a gemspec file.'
+task :gemspec do
+ File.open("#{spec.name}.gemspec", 'w') do |f|
+ f.write spec.to_ruby
+ end
+end
+
+Rake::GemPackageTask.new(spec) do |p|
+ FileUtils.rm_rf "rails_generators"
+ FileUtils.mkdir "rails_generators"
+ FileUtils.cp_r "lib/generators/.", "rails_generators"
+ p.gem_spec = spec
+ p.need_tar = false
+ p.need_zip = true
+end
+
+Dir['tasks/**/*.rake'].each {|rake| load rake}
10 app/controllers/application_controller.rb
@@ -0,0 +1,10 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
+
+ # Scrub sensitive parameters from your log
+ # filter_parameter_logging :password
+end
37 app/controllers/callbacks_controller.rb
@@ -0,0 +1,37 @@
+class CallbacksController < ApplicationController #< WizardForModelController
+ before_filter :init_flash_notice
+
+# wizard_for_model :four_step_user, :skip=>true, :mask_passwords=>[:password, :password_confirmation],
+# :completed=>{:controller=>:main, :action=>:finished},
+# :canceled=>{:controller=>:main, :action=>:canceled}
+
+ def init_flash_notice; flash[:notice] = ''; end
+
+ def flag(val)
+ instance_variable_set("@#{val}", true)
+ puts "--<<#{val}>>--"
+# flash[:notice] = flash[:notice] + "[#{val}]"
+ end
+
+ def on_get_init_page; flag :on_get_init_page; end
+ def on_init_page_errors; flag :on_init_page_errors; end
+ def on_init_page_next; flag :on_init_page_next; end
+ def on_init_page_skip; flag :on_init_page_skip; end
+ def on_init_page_cancel; flag :on_init_page_cancel; end
+
+ def on_get_second_page; flag :on_get_second_page; end
+ def on_second_page_back; flag :on_second_page_back; end
+ def on_second_page_next; flag :on_second_page_next; end
+ def on_second_page_errors; flag :on_second_page_errors; end
+ def on_second_page_skip; flag :on_second_age_skip; end
+ def on_second_page_cancel; flag :on_second_page_cancel; end
+
+ def wizard_render_page; flag :wizard_render_page; end
+
+ def on_finish_page_errors
+ flag :on_finish_page_errors
+ @four_step_user[:password] = ''
+ @four_step_user[:password_confirmation] = ''
+ end
+
+end
227 app/controllers/generated_controller.rb
@@ -0,0 +1,227 @@
+#
+# GeneratedController class generated by wizardly_controller
+#
+
+class GeneratedController < ApplicationController
+ before_filter :guard_entry
+
+
+ # init action method
+ def init
+ @step = :init
+ @wizard = wizard_config
+ @title = 'Init'
+ @description = ''
+ h = (flash[:wizard_model]||{}).merge(params[:user] || {})
+ @user = User.new(h)
+ flash[:wizard_model] = h
+ button_id = check_action_for_button
+ return if performed?
+ if request.get?
+ return if callback_performs_action?(:on_get_init_page)
+ render_wizard_page
+ return
+ end
+
+ @user.enable_validation_group :init
+ unless @user.valid?
+ return if callback_performs_action?(:on_init_page_errors)
+ render_wizard_page
+ return
+ end
+
+ return _on_wizard_finish if button_id == :finish
+ session[:progression] = [:init]
+ return if callback_performs_action?(:on_init_page_next)
+ redirect_to :action=>:second
+ end
+
+
+ # finish action method
+ def finish
+ @step = :finish
+ @wizard = wizard_config
+ @title = 'Finish'
+ @description = ''
+ h = (flash[:wizard_model]||{}).merge(params[:user] || {})
+ @user = User.new(h)
+ flash[:wizard_model] = h
+ button_id = check_action_for_button
+ return if performed?
+ if request.get?
+ return if callback_performs_action?(:on_get_finish_page)
+ render_wizard_page
+ return
+ end
+
+ @user.enable_validation_group :finish
+ unless @user.valid?
+ return if callback_performs_action?(:on_finish_page_errors)
+ render_wizard_page
+ return
+ end
+
+ return if _on_wizard_finish
+ redirect_to '/main/finished'
+ end
+
+
+ # second action method
+ def second
+ @step = :second
+ @wizard = wizard_config
+ @title = 'Second'
+ @description = ''
+ h = (flash[:wizard_model]||{}).merge(params[:user] || {})
+ @user = User.new(h)
+ flash[:wizard_model] = h
+ button_id = check_action_for_button
+ return if performed?
+ if request.get?
+ return if callback_performs_action?(:on_get_second_page)
+ render_wizard_page
+ return
+ end
+
+ @user.enable_validation_group :second
+ unless @user.valid?
+ return if callback_performs_action?(:on_second_page_errors)
+ render_wizard_page
+ return
+ end
+
+ return _on_wizard_finish if button_id == :finish
+ session[:progression].push(:second)
+ return if callback_performs_action?(:on_second_page_next)
+ redirect_to :action=>:finish
+ end
+
+ def index
+ redirect_to :action=>:init
+ end
+
+
+ protected
+ def _on_wizard_finish
+ @user.save_without_validation!
+ flash.discard(:wizard_model)
+ initial_referer = reset_wizard_session_vars
+ return redirect_to(wizard_config.completed_redirect || initial_referer)
+ end
+ def _on_wizard_skip
+ redirect_to :action=>wizard_config.next_page(@step)
+ true
+ end
+ def _on_wizard_back
+ redirect_to :action=>((session[:progression]||[]).pop || :init)
+ true
+ end
+ def _on_wizard_cancel
+ initial_referer = reset_wizard_session_vars
+ return (false) unless (wizard_config.canceled_redirect || initial_referer)
+ redirect_to(wizard_config.canceled_redirect || initial_referer)
+ true
+ end
+ hide_action :_on_wizard_finish, :_on_wizard_skip, :_on_wizard_back, :_on_wizard_cancel
+
+
+ protected
+ def guard_entry
+ if (r = request.env['HTTP_REFERER'])
+ h = ::ActionController::Routing::Routes.recognize_path(URI.parse(r).path)
+ return if (h[:controller]||'') == 'generated'
+ session[:initial_referer] = h
+ else
+ session[:initial_referer] = nil
+ end
+ flash.discard(:wizard_model)
+ redirect_to :action=>:init unless (params[:action] || '') == 'init'
+ end
+ hide_action :guard_entry
+
+ def render_wizard_page
+ end
+ hide_action :render_wizard_page
+
+ def performed?; super; end
+ hide_action :performed?
+
+ def check_action_for_button
+ button_id = nil
+ #check if params[:commit] has returned a button from submit_tag
+ unless (params[:commit] == nil)
+ button_name = methodize_button_name(params[:commit])
+ unless [:next, :finish].include?(button_id = button_name.to_sym)
+ action_method_name = "on_" + params[:action].to_s + "_page_" + button_name
+ unless callback_performs_action?(action_method_name)
+ method_name = "_on_wizard_" + button_name
+ if (method = self.method(method_name))
+ method.call
+ else
+ raise MissingCallbackError, "Callback method either '" + action_method_name + "' or '" + method_name + "' not defined", caller
+ end
+ end
+ end
+ end
+ #add other checks here or above
+ button_id
+ end
+ hide_action :check_action_for_button
+
+ @wizard_callbacks ||= {}
+ class << self
+ attr_reader :wizard_callbacks
+ end
+
+ def callback_performs_action?(methId)
+ wc = self.class.wizard_callbacks
+ case wc[methId]
+ when :none
+ return false
+ when :found
+ else #nil
+ unless self.class.method_defined?(methId)
+ wc[methId] = :none
+ return false
+ end
+ wc[methId] = :found
+ end
+ self.__send__(methId)
+ return self.performed?
+ end
+ hide_action :callback_performs_action?
+
+
+
+ private
+ def methodize_button_name(value)
+ value.to_s.strip.squeeze(' ').gsub(/ /, '_').downcase
+ end
+
+ def reset_wizard_session_vars
+ session[:progression] = nil
+ init = session[:initial_referer]
+ session[:initial_referer] = nil
+ init
+ end
+ hide_action :methodize_button_name, :reset_wizard_session_vars
+
+ public
+ def wizard_config; self.class.wizard_config; end
+ hide_action :wizard_config
+
+ private
+
+ def self.wizard_config; @wizard_config; end
+ @wizard_config = Wizardly::Wizard::Configuration.create(:generated, :user, :allow_skip=>true) do
+ when_completed_redirect_to '/main/finished'
+ when_canceled_redirect_to '/main/canceled'
+
+ # other things you can configure
+ # change_button(:next).to('Next One')
+ # change_button(:back).to('Previous')
+ # create_button('Help')
+ # set_page(:init).buttons_to :next_one, :previous, :cancel, :help #this removes skip
+ end
+
+end
7 app/controllers/macro_controller.rb
@@ -0,0 +1,7 @@
+class MacroController < ApplicationController
+
+ act_wizardly_for :user,
+ :completed=>{:controller=>:main, :action=>:finished},
+ :canceled=>{:controller=>:main, :action=>:canceled}
+
+end
28 app/controllers/main_controller.rb
@@ -0,0 +1,28 @@
+class MainController < ApplicationController
+ def index
+ @links = {
+ :macro=>'/macro',
+ :generated=>'/generated',
+ :scaffold_test=>'/scaffold_test',
+ :callbacks=>'/callbacks'
+ }
+ end
+
+ def finished
+ @referring_controller = referring_controller
+ end
+
+ def canceled
+ @referring_controller = referring_controller
+ end
+
+ def referrer_page
+ end
+
+ private
+ def referring_controller
+ referer = request.env['HTTP_REFERER']
+ ActionController::Routing::Routes.recognize_path(URI.parse(referer).path)[:controller]
+ end
+
+end
8 app/controllers/scaffold_test_controller.rb
@@ -0,0 +1,8 @@
+class ScaffoldTestController < ApplicationController #< WizardForModelController
+
+ wizard_for_model :user, :skip=>true, :mask_passwords=>[:password, :password_confirmation],
+ :completed=>{:controller=>:main, :action=>:finished},
+ :canceled=>{:controller=>:main, :action=>:canceled}
+
+
+end
3 app/helpers/application_helper.rb
@@ -0,0 +1,3 @@
+# Methods added to this helper will be available to all templates in the application.
+module ApplicationHelper
+end
14 app/helpers/callbacks_helper.rb
@@ -0,0 +1,14 @@
+module CallbacksHelper
+
+ def wizardly_submit
+ @@wizardly_submit ||= {}
+ unless @@wizardly_submit[@step]
+ buttons = @wizard.pages[@step].buttons
+ @@wizardly_submit[@step] = buttons.inject(StringIO.new) do |io, button|
+ io << submit_tag(button.name)
+ end.string
+ end
+ @@wizardly_submit[@step]
+ end
+
+end
14 app/helpers/generated_helper.rb
@@ -0,0 +1,14 @@
+module GeneratedHelper
+
+ def wizardly_submit
+ @@wizardly_submit ||= {}
+ unless @@wizardly_submit[@step]
+ buttons = @wizard.pages[@step].buttons
+ @@wizardly_submit[@step] = buttons.inject(StringIO.new) do |io, button|
+ io << submit_tag(button.name)
+ end.string
+ end
+ @@wizardly_submit[@step]
+ end
+
+end
14 app/helpers/scaffold_test_helper.rb
@@ -0,0 +1,14 @@
+module ScaffoldTestHelper
+
+ def wizardly_submit
+ @@wizardly_submit ||= {}
+ unless @@wizardly_submit[@step]
+ buttons = @wizard.pages[@step].buttons
+ @@wizardly_submit[@step] = buttons.inject(StringIO.new) do |io, button|
+ io << submit_tag(button.name)
+ end.string
+ end
+ @@wizardly_submit[@step]
+ end
+
+end
9 app/models/four_step_user.rb
@@ -0,0 +1,9 @@
+class FourStepUser < User
+
+ validation_group :init, :fields=>[:first_name, :last_name]
+ validation_group :second, :fields=>[:age, :gender]
+ validation_group :third, :fields=>[:programmer, :status]
+ validation_group :finish, :fields=>[:username, :password, :password_confirmation]
+
+
+end
22 app/models/user.rb
@@ -0,0 +1,22 @@
+class User < ActiveRecord::Base
+=begin
+ t.string :first_name
+ t.string :last_name
+ t.string :username
+ t.string :password
+ t.integer :age
+ t.string :gender
+ t.boolean :programmer
+ t.string :status
+=end
+
+ validates_confirmation_of :password
+ validates_presence_of :first_name, :last_name, :username, :password, :age, :gender, :status
+ #validates_numercality_of :age
+ #validates_uniqueness_of :username
+
+ wizardly_page :init, :fields=>[:first_name, :last_name]
+ wizardly_page :second, :fields=>[:age, :gender, :programmer, :status]
+ wizardly_page :finish, :fields=>[:username, :password, :password_confirmation]
+
+end
31 app/views/callbacks/finish.html.erb
@@ -0,0 +1,31 @@
+<h1>Finish</h1>
+
+
+<%= "<p style=\"color: green\">#{flash[:notice]}<p>" if flash[:notice] %>
+
+<% form_for :four_step_user, :url=>{:action=>:finish} do |f| %>
+ <%= f.error_messages %>
+
+
+ <p>
+ <%= f.label :username %><br />
+ <%= f.text_field :username %>
+ </p>
+
+ <p>
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </p>
+
+ <p>
+ <%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %>
+ </p>
+ <p>
+ <%= wizardly_submit %>
+ </p>
+<% end %>
+
+<script type='text/javascript'>
+ document.getElementById('four_step_user_username').focus()
+</script>
26 app/views/callbacks/init.html.erb
@@ -0,0 +1,26 @@
+<h1>Init</h1>
+
+
+<%= "<p style=\"color: green\">#{flash[:notice]}<p>" if flash[:notice] %>
+
+<% form_for :four_step_user, :url=>{:action=>:init} do |f| %>
+ <%= f.error_messages %>
+
+
+ <p>
+ <%= f.label :first_name %><br />
+ <%= f.text_field :first_name %>
+ </p>
+
+ <p>
+ <%= f.label :last_name %><br />
+ <%= f.text_field :last_name %>
+ </p>
+ <p>
+ <%= wizardly_submit %>
+ </p>
+<% end %>
+
+<script type='text/javascript'>
+ document.getElementById('four_step_user_first_name').focus()
+</script>
26 app/views/callbacks/second.html.erb
@@ -0,0 +1,26 @@
+<h1>Second</h1>
+
+
+<%= "<p style=\"color: green\">#{flash[:notice]}<p>" if flash[:notice] %>
+
+<% form_for :four_step_user, :url=>{:action=>:second} do |f| %>
+ <%= f.error_messages %>
+
+
+ <p>
+ <%= f.label :age %><br />
+ <%= f.text_field :age %>
+ </p>
+
+ <p>
+ <%= f.label :gender %><br />
+ <%= f.text_field :gender %>
+ </p>
+ <p>
+ <%= wizardly_submit %>
+ </p>
+<% end %>
+
+<script type='text/javascript'>
+ document.getElementById('four_step_user_age').focus()
+</script>
26 app/views/callbacks/third.html.erb
@@ -0,0 +1,26 @@
+<h1>Third</h1>
+
+
+<%= "<p style=\"color: green\">#{flash[:notice]}<p>" if flash[:notice] %>
+
+<% form_for :four_step_user, :url=>{:action=>:third} do |f| %>
+ <%= f.error_messages %>
+
+
+ <p>
+ <%= f.label :programmer %><br />
+ <%= f.check_box :programmer %>
+ </p>
+
+ <p>
+ <%= f.label :status %><br />
+ <%= f.text_field :status %>
+ </p>
+ <p>
+ <%= wizardly_submit %>
+ </p>
+<% end %>
+
+<script type='text/javascript'>
+ document.getElementById('four_step_user_programmer').focus()
+</script>
8 app/views/generated/finish.html.erb
@@ -0,0 +1,8 @@
+<div>
+ <% form_for :user do |f| -%>
+ <div>username: <%= f.text_field :username %> <%= error_message_on :user, :username, {:prepend_text=>'*'} %></div>
+ <div>password: <%= f.password_field :password %> <%= error_message_on :user, :password, {:prepend_text=>'*'} %></div>
+ <div>password confirmation: <%= f.password_field :password_confirmation %> <%= error_message_on :user, :password_confirmation, {:prepend_text=>'*'} %></div>
+ <div><%= wizardly_submit %></div>
+ <% end -%>
+</div>
7 app/views/generated/init.html.erb
@@ -0,0 +1,7 @@
+<div>
+ <% form_for :user do |f| -%>
+ <div>first name: <%= f.text_field :first_name %> <%= error_message_on :user, :first_name, {:prepend_text=>'*'} %></div>
+ <div>last name: <%= f.text_field :last_name %> <%= error_message_on :user, :last_name, {:prepend_text=>'*'} %></div>
+ <div><%= wizardly_submit %></div>
+ <% end -%>
+</div>
10 app/views/generated/second.html.erb
@@ -0,0 +1,10 @@
+<div>
+ <% form_for :user do |f| -%>
+ <div>age: <%= f.text_field :age %> <%= error_message_on :user, :age, {:prepend_text=>'*'} %></div>
+ <div>gender: <%= f.text_field :gender %> <%= error_message_on :user, :gender, {:prepend_text=>'*'} %></div>
+ <div>programmer: <%= f.check_box :programmer %> <%= error_message_on :user, :programmer, {:prepend_text=>'*'} %></div>
+ <div>status: <%= f.text_field :status %> <%=error_message_on :user, :status, {:prepend_text=>'*'} %></div>
+ <div><%= wizardly_submit %></div>
+ <% end -%>
+
+</div>
9 app/views/layouts/application.html.erb
@@ -0,0 +1,9 @@
+<html>
+<head>
+ <title><%=@step%> page</title>
+</head>
+
+<body>
+<%= yield :layout %>
+</body>
+</html>
15 app/views/layouts/callbacks.html.erb
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>CallbacksController: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<%= yield %>
+
+</body>
+</html>
15 app/views/layouts/scaffold_test.html.erb
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>ScaffoldTestController: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<%= yield %>
+
+</body>
+</html>
8 app/views/macro/finish.html.erb
@@ -0,0 +1,8 @@
+<div>
+ <% form_for :user do |f| -%>
+ <div>username: <%= f.text_field :username %> <%= error_message_on :user, :username, {:prepend_text=>'*'} %></div>
+ <div>password: <%= f.password_field :password %> <%= error_message_on :user, :password, {:prepend_text=>'*'} %></div>
+ <div>password confirmation: <%= f.password_field :password_confirmation %> <%= error_message_on :user, :password_confirmation, {:prepend_text=>'*'} %></div>
+ <div><%= submit_tag 'finish' %>&nbsp;<%= submit_tag 'back' %>&nbsp;<%=submit_tag 'cancel' %></div>
+ <% end -%>
+</div>
7 app/views/macro/init.html.erb
@@ -0,0 +1,7 @@
+<div>
+ <% form_for :user do |f| -%>
+ <div>first name: <%= f.text_field :first_name %> <%= error_message_on :user, :first_name, {:prepend_text=>'*'} %></div>
+ <div>last name: <%= f.text_field :last_name %> <%= error_message_on :user, :last_name, {:prepend_text=>'*'} %></div>
+ <div><%= submit_tag 'next' %>&nbsp;<%= submit_tag 'skip' %>&nbsp;<%= submit_tag 'cancel' %></div>
+ <% end -%>
+</div>
10 app/views/macro/second.html.erb
@@ -0,0 +1,10 @@
+<div>
+ <% form_for :user do |f| -%>
+ <div>age: <%= f.text_field :age %> <%= error_message_on :user, :age, {:prepend_text=>'*'} %></div>
+ <div>gender: <%= f.text_field :gender %> <%= error_message_on :user, :gender, {:prepend_text=>'*'} %></div>
+ <div>programmer: <%= f.check_box :programmer %> <%= error_message_on :user, :programmer, {:prepend_text=>'*'} %></div>
+ <div>status: <%= f.text_field :status %> <%=error_message_on :user, :status, {:prepend_text=>'*'} %></div>
+ <div><%= submit_tag 'next' %>&nbsp;<%= submit_tag 'back' %>&nbsp;<%= submit_tag 'skip' %>&nbsp;<%= submit_tag 'finish' %>&nbsp;<%= submit_tag 'cancel' %></div>
+ <% end -%>
+
+</div>
7 app/views/main/canceled.html.erb
@@ -0,0 +1,7 @@
+Referer: <%="#{@referring_controller.to_s.camelize}Controller" %>
+<br/><br/>
+<%=link_to 'signup', :controller=>@referring_controller %>
+
+<!--
+link_to_wizard : provides parameters for cancel and complete page! cool!
+-->
7 app/views/main/finished.html.erb
@@ -0,0 +1,7 @@
+Referer: <%="#{@referring_controller.to_s.camelize}Controller" %>
+<br/><br/>
+<%=link_to 'signup', :controller=>@referring_controller %>
+
+<!--
+link_to_wizard : provides parameters for cancel and complete page! cool!
+-->
3 app/views/main/index.html.erb
@@ -0,0 +1,3 @@
+<% @links.each do |k,v| %>
+<%=link_to k.to_s, v %><br/>
+<% end %>
7 app/views/main/referrer_page.html.erb
@@ -0,0 +1,7 @@
+Referer: <%="#{@referring_controller.to_s.camelize}Controller" %>
+<br/><br/>
+<%=link_to 'signup', :controller=>@referring_controller %>
+
+<!--
+link_to_wizard : provides parameters for cancel and complete page! cool!
+-->
31 app/views/scaffold_test/finish.html.erb
@@ -0,0 +1,31 @@
+<h1>Finish</h1>
+
+
+<%= "<p style=\"color: green\">#{flash[:notice]}<p>" if flash[:notice] %>
+
+<% form_for :user, :url=>{:action=>:finish} do |f| %>
+ <%= f.error_messages %>
+
+
+ <p>
+ <%= f.label :username %><br />
+ <%= f.text_field :username %>
+ </p>
+
+ <p>
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </p>
+
+ <p>
+ <%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %>
+ </p>
+ <p>
+ <%= wizardly_submit %>
+ </p>
+<% end %>
+
+<script type='text/javascript'>
+ document.getElementById('user_username').focus()
+</script>
26 app/views/scaffold_test/init.html.erb
@@ -0,0 +1,26 @@
+<h1>Init</h1>
+
+
+<%= "<p style=\"color: green\">#{flash[:notice]}<p>" if flash[:notice] %>
+
+<% form_for :user, :url=>{:action=>:init} do |f| %>
+ <%= f.error_messages %>
+
+
+ <p>
+ <%= f.label :first_name %><br />
+ <%= f.text_field :first_name %>
+ </p>
+
+ <p>
+ <%= f.label :last_name %><br />
+ <%= f.text_field :last_name %>
+ </p>
+ <p>
+ <%= wizardly_submit %>
+ </p>
+<% end %>
+
+<script type='text/javascript'>
+ document.getElementById('user_first_name').focus()
+</script>
36 app/views/scaffold_test/second.html.erb
@@ -0,0 +1,36 @@
+<h1>Second</h1>
+
+
+<%= "<p style=\"color: green\">#{flash[:notice]}<p>" if flash[:notice] %>
+
+<% form_for :user, :url=>{:action=>:second} do |f| %>
+ <%= f.error_messages %>
+
+
+ <p>
+ <%= f.label :age %><br />
+ <%= f.text_field :age %>
+ </p>
+
+ <p>
+ <%= f.label :gender %><br />
+ <%= f.text_field :gender %>
+ </p>
+
+ <p>
+ <%= f.label :programmer %><br />
+ <%= f.check_box :programmer %>
+ </p>
+
+ <p>
+ <%= f.label :status %><br />
+ <%= f.text_field :status %>
+ </p>
+ <p>
+ <%= wizardly_submit %>
+ </p>
+<% end %>
+
+<script type='text/javascript'>
+ document.getElementById('user_age').focus()
+</script>
110 config/boot.rb
@@ -0,0 +1,110 @@
+# Don't change this file!
+# Configure your app in config/environment.rb and config/environments/*.rb
+
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
+
+module Rails
+ class << self
+ def boot!
+ unless booted?
+ preinitialize
+ pick_boot.run
+ end
+ end
+
+ def booted?
+ defined? Rails::Initializer
+ end
+
+ def pick_boot
+ (vendor_rails? ? VendorBoot : GemBoot).new
+ end
+
+ def vendor_rails?
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
+ end
+
+ def preinitialize
+ load(preinitializer_path) if File.exist?(preinitializer_path)
+ end
+
+ def preinitializer_path
+ "#{RAILS_ROOT}/config/preinitializer.rb"
+ end
+ end
+
+ class Boot
+ def run
+ load_initializer
+ Rails::Initializer.run(:set_load_path)
+ end
+ end
+
+ class VendorBoot < Boot
+ def load_initializer
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
+ Rails::Initializer.run(:install_gem_spec_stubs)
+ Rails::GemDependency.add_frozen_gem_path
+ end
+ end
+
+ class GemBoot < Boot
+ def load_initializer
+ self.class.load_rubygems
+ load_rails_gem
+ require 'initializer'
+ end
+
+ def load_rails_gem
+ if version = self.class.gem_version
+ gem 'rails', version
+ else
+ gem 'rails'
+ end
+ rescue Gem::LoadError => load_error
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
+ exit 1
+ end
+
+ class << self
+ def rubygems_version
+ Gem::RubyGemsVersion rescue nil
+ end
+
+ def gem_version
+ if defined? RAILS_GEM_VERSION
+ RAILS_GEM_VERSION
+ elsif ENV.include?('RAILS_GEM_VERSION')
+ ENV['RAILS_GEM_VERSION']
+ else
+ parse_gem_version(read_environment_rb)
+ end
+ end
+
+ def load_rubygems
+ require 'rubygems'
+ min_version = '1.3.1'
+ unless rubygems_version >= min_version
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
+ exit 1
+ end
+
+ rescue LoadError
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
+ exit 1
+ end
+
+ def parse_gem_version(text)
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
+ end
+
+ private
+ def read_environment_rb
+ File.read("#{RAILS_ROOT}/config/environment.rb")
+ end
+ end
+ end
+end
+
+# All that for this:
+Rails.boot!
22 config/database.yml
@@ -0,0 +1,22 @@
+# SQLite version 3.x
+# gem install sqlite3-ruby (not necessary on OS X Leopard)
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
45 config/environment.rb
@@ -0,0 +1,45 @@
+# Be sure to restart your server when you modify this file
+
+# Specifies gem version of Rails to use when vendor/rails is not present
+RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
+
+# Bootstrap the Rails environment, frameworks, and default configuration
+require File.join(File.dirname(__FILE__), 'boot')
+
+Rails::Initializer.run do |config|
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Add additional load paths for your own custom dirs
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
+
+ # Specify gems that this application depends on and have them installed with rake gems:install
+ # config.gem "bj"
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
+ # config.gem "sqlite3-ruby", :lib => "sqlite3"
+ # config.gem "aws-s3", :lib => "aws/s3"
+# config.gem "validation_group", :version => ">=0.1.1"
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Skip frameworks you're not going to use. To use Rails without a database,
+ # you must remove the Active Record framework.
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
+
+ # Activate observers that should always be running
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names.
+ config.time_zone = 'UTC'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
+ # config.i18n.default_locale = :de
+end
+
+#require 'validation_group'
+require 'wizardly'
17 config/environments/development.rb
@@ -0,0 +1,17 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# In the development environment your application's code is reloaded on
+# every request. This slows down response time but is perfect for development
+# since you don't have to restart the webserver when you make code changes.
+config.cache_classes = false
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_view.debug_rjs = true
+config.action_controller.perform_caching = false
+
+# Don't care if the mailer can't send
+config.action_mailer.raise_delivery_errors = false
28 config/environments/production.rb
@@ -0,0 +1,28 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# The production environment is meant for finished, "live" apps.
+# Code is not reloaded between requests
+config.cache_classes = true
+
+# Full error reports are disabled and caching is turned on
+config.action_controller.consider_all_requests_local = false
+config.action_controller.perform_caching = true
+config.action_view.cache_template_loading = true
+
+# See everything in the log (default is :info)
+# config.log_level = :debug
+
+# Use a different logger for distributed setups
+# config.logger = SyslogLogger.new
+
+# Use a different cache store in production
+# config.cache_store = :mem_cache_store
+
+# Enable serving of images, stylesheets, and javascripts from an asset server
+# config.action_controller.asset_host = "http://assets.example.com"
+
+# Disable delivery errors, bad email addresses will be ignored
+# config.action_mailer.raise_delivery_errors = false
+
+# Enable threaded mode
+# config.threadsafe!
30 config/environments/test.rb
@@ -0,0 +1,30 @@
+# Settings specified here will take precedence over those in config/environment.rb
+
+# The test environment is used exclusively to run your application's
+# test suite. You never need to work with it otherwise. Remember that
+# your test database is "scratch space" for the test suite and is wiped
+# and recreated between test runs. Don't rely on the data there!
+config.cache_classes = true
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_controller.perform_caching = false
+config.action_view.cache_template_loading = true
+
+# Disable request forgery protection in test environment
+config.action_controller.allow_forgery_protection = false
+
+# Tell Action Mailer not to deliver emails to the real world.
+# The :test delivery method accumulates sent emails in the
+# ActionMailer::Base.deliveries array.
+config.action_mailer.delivery_method = :test
+
+# Use SQL instead of Active Record's schema dumper when creating the test database.
+# This is necessary if your schema can't be completely dumped by the schema dumper,
+# like if you have constraints or database-specific column types
+# config.active_record.schema_format = :sql
+
+config.gem "webrat", :version=>">=0.4.3"
7 config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
10 config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
5 config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
19 config/initializers/new_rails_defaults.rb
@@ -0,0 +1,19 @@
+# Be sure to restart your server when you modify this file.
+
+# These settings change the behavior of Rails 2 apps and will be defaults
+# for Rails 3. You can remove this initializer when Rails 3 is released.
+
+if defined?(ActiveRecord)
+ # Include Active Record class name as root for JSON serialized output.
+ ActiveRecord::Base.include_root_in_json = true
+
+ # Store the full class name (including module namespace) in STI type column.
+ ActiveRecord::Base.store_full_sti_class = true
+end
+
+# Use ISO 8601 format for JSON serialized times and dates.
+ActiveSupport.use_standard_json_time_format = true
+
+# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
+# if you're including raw json in an HTML page.
+ActiveSupport.escape_html_entities_in_json = false
15 config/initializers/session_store.rb
@@ -0,0 +1,15 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying cookie session data integrity.
+# If you change this key, all old sessions will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+ActionController::Base.session = {
+ :key => '_wizard_session',
+ :secret => 'bbd1b39720a747639fea9e3b40b5db4d67cabdedab097746587fdd9d390c1ce2108d812fd23054eb9ac0c6d4bbb07357a532cd8cf0e847cac5cc319ab1364175'
+}
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rake db:sessions:create")
+# ActionController::Base.session_store = :active_record_store
5 config/locales/en.yml
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
44 config/routes.rb
@@ -0,0 +1,44 @@
+ActionController::Routing::Routes.draw do |map|
+ # The priority is based upon order of creation: first created -> highest priority.
+ map.root :controller=>'main'
+
+ # Sample of regular route:
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
+ # This route can be invoked with purchase_url(:id => product.id)
+
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
+ # map.resources :products
+
+ # Sample resource route with options:
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
+
+ # Sample resource route with sub-resources:
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
+
+ # Sample resource route with more complex sub-resources
+ # map.resources :products do |products|
+ # products.resources :comments
+ # products.resources :sales, :collection => { :recent => :get }
+ # end
+
+ # Sample resource route within a namespace:
+ # map.namespace :admin do |admin|
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
+ # admin.resources :products
+ # end
+
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
+ # map.root :controller => "welcome"
+
+ # See how all your routes lay out with "rake routes"
+
+ # Install the default routes as the lowest priority.
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
+ # consider removing the them or commenting them out if you're using named routes and resources.
+ map.connect ':controller/:action/:id'
+ map.connect ':controller/:action/:id.:format'
+end
BIN db/development.sqlite3
Binary file not shown.
16 db/migrate/20090718171255_create_sessions.rb
@@ -0,0 +1,16 @@
+class CreateSessions < ActiveRecord::Migration
+ def self.up
+ create_table :sessions do |t|
+ t.string :session_id, :null => false
+ t.text :data
+ t.timestamps
+ end
+
+ add_index :sessions, :session_id
+ add_index :sessions, :updated_at
+ end
+
+ def self.down
+ drop_table :sessions
+ end
+end
20 db/migrate/20090718172749_create_users.rb
@@ -0,0 +1,20 @@
+class CreateUsers < ActiveRecord::Migration
+ def self.up
+ create_table :users do |t|
+ t.string :first_name
+ t.string :last_name
+ t.string :username
+ t.string :password
+ t.integer :age
+ t.string :gender
+ t.boolean :programmer
+ t.string :status
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :users
+ end
+end
0 db/production.sqlite3
No changes.
37 db/schema.rb
@@ -0,0 +1,37 @@
+# This file is auto-generated from the current state of the database. Instead of editing this file,
+# please use the migrations feature of Active Record to incrementally modify your database, and
+# then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your database schema. If you need
+# to create the application database on another system, you should be using db:schema:load, not running
+# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20090718172749) do
+
+ create_table "sessions", :force => true do |t|
+ t.string "session_id", :null => false
+ t.text "data"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
+ add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
+
+ create_table "users", :force => true do |t|
+ t.string "first_name"
+ t.string "last_name"
+ t.string "username"
+ t.string "password"
+ t.integer "age"
+ t.string "gender"
+ t.boolean "programmer"
+ t.string "status"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
BIN db/test.sqlite3
Binary file not shown.
1 init.rb
@@ -0,0 +1 @@
+require 'wizardly'
6 lib/generators/wizardly_app/USAGE
@@ -0,0 +1,6 @@
+Prepares a rails application to use wizardly gem
+
+Moves the wizardly.rake file in to lib/tasks directory
+
+
+
33 lib/generators/wizardly_app/templates/wizardly.rake
@@ -0,0 +1,33 @@
+
+namespace :wizardly do
+ desc "Display wizard configuration details"
+ task :config => :environment do
+ name = ENV['name']
+ return print_usage unless name
+ begin
+ name = name.strip.camelize
+ name += 'Controller' unless name.match('Controller$')
+ controller = name.constantize
+ begin
+ c = controller.wizard_config
+ begin
+ puts
+ puts c.print_config
+ rescue Exception=>e
+ puts "Problem printing configuration: " + e.message
+ end
+ rescue
+ puts "{#{name}} is not a 'wizardly' controller.\nMake sure 'wizard_for_model' is defined in the controller class."
+ puts
+ end
+ rescue
+ puts "{#{name}} does not reference a controller class"
+ puts
+ end
+ end
+
+ def print_usage
+ puts "Usage: rake wizardly:config name={controller_name}"
+ puts
+ end
+end
41 lib/generators/wizardly_app/wizardly_app_generator.rb
@@ -0,0 +1,41 @@
+#require 'wizardly'
+
+class WizardlyAppGenerator < Rails::Generator::Base
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ end
+
+ def manifest
+ record do |m|
+ m.directory "app/lib/tasks"
+
+ m.file "wizardly.rake", "lib/tasks/wizardly.rake"
+
+ end
+ end
+
+ def controller_class_name
+ "#{controller_name.camelize}Controller"
+ end
+ def model_class_name
+ "#{model_name.camelize}"
+ end
+ def action_methods
+ @wizard_config.print_page_action_methods
+ end
+ def callback_methods
+ @wizard_config.print_callbacks
+ end
+ def helper_methods
+ @wizard_config.print_helpers
+ end
+
+ protected
+ # Override with your own usage banner.
+ def banner
+ "Usage: #{$0} wizardly_app"
+ end
+
+
+end
3 lib/generators/wizardly_controller/USAGE
@@ -0,0 +1,3 @@
+Generates a wizard controller with all the code displayed
+
+
45 lib/generators/wizardly_controller/templates/controller.rb.erb
@@ -0,0 +1,45 @@
+#
+# <%= controller_class_name %> class generated by wizardly_controller
+#
+
+class <%= controller_class_name %> < ApplicationController
+ before_filter :guard_entry
+
+ <%= action_methods %>
+
+ <%= callback_methods %>
+
+ <%= helper_methods %>
+
+ private
+ def methodize_button_name(value)
+ value.to_s.strip.squeeze(' ').gsub(/ /, '_').downcase
+ end
+
+ def reset_wizard_session_vars
+ session[:progression] = nil
+ init = session[:initial_referer]
+ session[:initial_referer] = nil
+ init
+ end
+ hide_action :methodize_button_name, :reset_wizard_session_vars
+
+ public
+ def wizard_config; self.class.wizard_config; end
+ hide_action :wizard_config
+
+ private
+
+ def self.wizard_config; @wizard_config; end
+ @wizard_config = Wizardly::Wizard::Configuration.create(:<%=controller_name %>, :<%=model_name %>, :allow_skip=>true) do
+ <%= "when_completed_redirect_to #{Wizardly::Wizard::Utils.formatted_redirect(completed_redirect)}" if completed_redirect %>
+ <%= "when_canceled_redirect_to #{Wizardly::Wizard::Utils.formatted_redirect(canceled_redirect)}" if canceled_redirect %>
+
+ # other things you can configure
+ # change_button(:next).to('Next One')
+ # change_button(:back).to('Previous')
+ # create_button('Help')
+ # set_page(:init).buttons_to :next_one, :previous, :cancel, :help #this removes skip
+ end
+
+end
14 lib/generators/wizardly_controller/templates/helper.rb.erb
@@ -0,0 +1,14 @@
+module <%=controller_name.camelize %>Helper
+
+ def wizardly_submit
+ @@wizardly_submit ||= {}
+ unless @@wizardly_submit[@step]
+ buttons = @wizard.pages[@step].buttons
+ @@wizardly_submit[@step] = buttons.inject(StringIO.new) do |io, button|
+ io << submit_tag(button.name)
+ end.string
+ end
+ @@wizardly_submit[@step]
+ end
+
+end
54 lib/generators/wizardly_controller/wizardly_controller_generator.rb
@@ -0,0 +1,54 @@
+#require 'wizardly'
+
+class WizardlyControllerGenerator < Rails::Generator::Base
+ attr_reader :controller_name, :model_name, :completed_redirect, :canceled_redirect
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ @controller_name = @args[0].underscore
+ @model_name = @args[1].underscore
+ @completed_redirect = @args[2]
+ @canceled_redirect = @args[3]
+ opts = {}
+ opts[:completed] = @completed_redirect if @completed_redirect
+ opts[:canceled] = @canceled_redirect if @canceled_redirect
+
+ @wizard_config = Wizardly::Wizard::Configuration.new(@controller_name.to_sym, opts)
+ @wizard_config.inspect_model!(@model_name.to_sym)
+ end
+
+ def manifest
+ record do |m|
+ m.directory "app/controllers"
+
+ m.template "controller.rb.erb", "app/controllers/#{controller_name}_controller.rb"
+
+ m.template "helper.rb.erb", "app/helpers/#{controller_name}_helper.rb"
+
+ end
+ end
+
+ def controller_class_name
+ "#{controller_name.camelize}Controller"
+ end
+ def model_class_name
+ "#{model_name.camelize}"
+ end
+ def action_methods
+ @wizard_config.print_page_action_methods
+ end
+ def callback_methods
+ @wizard_config.print_callbacks
+ end
+ def helper_methods
+ @wizard_config.print_helpers
+ end
+
+ protected
+ # Override with your own usage banner.
+ def banner
+ "Usage: #{$0} wizardly_controller controller_name model_name [completed_redirect canceled_redirect]"
+ end
+
+
+end
4 lib/generators/wizardly_scaffold/USAGE
@@ -0,0 +1,4 @@
+Generates a wizard scaffold from a wizard controller using wizard_for_model (or wizard_for)
+
+
+
23 lib/generators/wizardly_scaffold/templates/form.html.erb
@@ -0,0 +1,23 @@
+<h1><%= page.title %></h1>
+
+<%= "<p>#{page.description}<p>" if !page.description.blank? %>
+<%%= "<p style=\"color: green\">#{flash[:notice]}<p>" if flash[:notice] %>
+
+<%% form_for :<%= model_name %>, :url=>{:action=>:<%= page.name %>} do |f| %>
+ <%%= f.error_messages %>
+
+<% for field in page.fields -%>
+ <% first_field_id ||= "#{model_name}_#{field.name}" %>
+ <p>
+ <%%= f.label :<%= field.name %> %><br />
+ <%%= f.<%= field.field_type %> :<%= field.name %> %>
+ </p>
+<% end -%>
+ <p>
+ <%%= wizardly_submit %>
+ </p>
+<%% end %>
+
+<script type='text/javascript'>
+ document.getElementById('<%=first_field_id %>').focus()
+</script>
14 lib/generators/wizardly_scaffold/templates/helper.rb.erb
@@ -0,0 +1,14 @@
+module <%=controller_name.camelize %>Helper
+
+ def wizardly_submit
+ @@wizardly_submit ||= {}
+ unless @@wizardly_submit[@step]
+ buttons = @wizard.pages[@step].buttons
+ @@wizardly_submit[@step] = buttons.inject(StringIO.new) do |io, button|
+ io << submit_tag(button.name)
+ end.string
+ end
+ @@wizardly_submit[@step]
+ end
+
+end
15 lib/generators/wizardly_scaffold/templates/layout.html.erb
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+