Class: Wizardly::Wizard::Configuration

Inherits:
Object
  • Object
show all
Includes:
TextHelpers
Defined in:
lib/wizardly/wizard/configuration.rb,
lib/wizardly/wizard/configuration/methods.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, opts) ⇒ Configuration

enum_attr :persistance, %w(sandbox session database)

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wizardly/wizard/configuration.rb', line 15

def initialize(controller, opts) #completed_redirect = nil, canceled_redirect = nil)
  @controller_class_name = controller.to_s.camelcase
  @controller_class_name += 'Controller' unless @controller_class_name =~ /Controller$/
  @controller_path = @controller_class_name.sub(/Controller$/,'').underscore
  @controller_name = @controller_class_name.demodulize.sub(/Controller$/,'').underscore
  @completed_redirect = opts[:completed] || opts[:when_completed] || opts[:redirect] #format_redirect(completed_redirect)
  @canceled_redirect = opts[:canceled] || opts[:when_canceled] || opts[:redirect]
  @include_skip_button = opts[:skip] || opts[:allow_skip] || opts[:allow_skipping] || false
  @include_cancel_button = opts.key?(:cancel) ? opts[:cancel] : true
  @guard_entry = opts.key?(:guard) ? opts[:guard] : true
  @password_fields = opts[:mask_fields] || opts[:mask_passwords] || [:password, :password_confirmation]
  @persist_model = opts[:persist_model] || :per_page
  @form_data = opts[:form_data] || :session
  raise(ArgumentError, ":persist_model option must be one of :once or :per_page", caller) unless [:once, :per_page].include?(@persist_model)
  raise(ArgumentError, ":form_data option must be one of :sandbox or :session", caller) unless [:sandbox, :session].include?(@form_data)
  @page_order = []
  @pages = {}
  @buttons = nil
  @default_buttons = Hash[*[:next, :back, :cancel, :finish, :skip].collect {|default| [default, Button.new(default)] }.flatten]
end

Instance Attribute Details

#canceled_redirectObject (readonly)

Returns the value of attribute canceled_redirect.



11
12
13
# File 'lib/wizardly/wizard/configuration.rb', line 11

def canceled_redirect
  @canceled_redirect
end

#completed_redirectObject (readonly)

Returns the value of attribute completed_redirect.



11
12
13
# File 'lib/wizardly/wizard/configuration.rb', line 11

def completed_redirect
  @completed_redirect
end

#controller_class_nameObject (readonly)

Returns the value of attribute controller_class_name.



11
12
13
# File 'lib/wizardly/wizard/configuration.rb', line 11

def controller_class_name
  @controller_class_name
end

#controller_nameObject (readonly)

Returns the value of attribute controller_name.



11
12
13
# File 'lib/wizardly/wizard/configuration.rb', line 11

def controller_name
  @controller_name
end

#controller_pathObject (readonly)

Returns the value of attribute controller_path.



11
12
13
# File 'lib/wizardly/wizard/configuration.rb', line 11

def controller_path
  @controller_path
end

#page_orderObject (readonly)

Returns the value of attribute page_order.



11
12
13
# File 'lib/wizardly/wizard/configuration.rb', line 11

def page_order
  @page_order
end

#pagesObject (readonly)

Returns the value of attribute pages.



11
12
13
# File 'lib/wizardly/wizard/configuration.rb', line 11

def pages
  @pages
end

Class Method Details

.create(controller_name, model_name, opts = {}, &block) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/wizardly/wizard/configuration.rb', line 63

def self.create(controller_name, model_name, opts={}, &block)
  # controller_name = controller_name.to_s.underscore.sub(/_controller$/, '').to_sym
  model_name = model_name.to_s.underscore.to_sym
  config = Wizardly::Wizard::Configuration.new(controller_name, opts)
  config.inspect_model!(model_name)
  Wizardly::Wizard::DSL.new(config).instance_eval(&block) if block_given?
  config
end

Instance Method Details

#_change_button(name) ⇒ Object



129
130
131
132
133
134
# File 'lib/wizardly/wizard/configuration.rb', line 129

def _change_button(name)
  raise(WizardConfigurationError, "Button :#{name} in _change_button() call does not exist", caller) unless self.buttons.key?(name)
  _buttons = self.buttons
  @buttons = nil # clear the buttons for regeneration after change in next line
  _buttons[name]
end

#_create_button(name, opts) ⇒ Object



135
136
137
138
139
140
# File 'lib/wizardly/wizard/configuration.rb', line 135

def _create_button(name, opts)
  id = opts[:id] || button_name_to_symbol(name)
  raise(WizardConfigurationError, "Button '#{name}' with id :#{id} cannot be created. The ID already exists.", caller) if self.buttons.key?(id)
  @buttons=nil
  @default_buttons[id] = UserDefinedButton.new(id, name)
end

#_mask_passwords(passwords) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/wizardly/wizard/configuration.rb', line 142

def _mask_passwords(passwords)
  case passwords
  when String
    passwords = [passwords.to_sym]
  when Symbol
    passwords = [passwords]
  when Array
  else
    raise(WizardlyConfigurationError, "mask_passwords method only accepts string, symbol or array of password fields")
  end
  @password_fields.push(*passwords).uniq!
end

#_set_page(name) ⇒ Object



141
# File 'lib/wizardly/wizard/configuration.rb', line 141

def _set_page(name); @pages[name]; end

#_when_canceled_redirect_to(redir) ⇒ Object



128
# File 'lib/wizardly/wizard/configuration.rb', line 128

def _when_canceled_redirect_to(redir); @canceled_redirect = redir; end

#_when_completed_redirect_to(redir) ⇒ Object

internal DSL method handlers



127
# File 'lib/wizardly/wizard/configuration.rb', line 127

def _when_completed_redirect_to(redir); @completed_redirect = redir; end

#button_for_function(name) ⇒ Object



56
# File 'lib/wizardly/wizard/configuration.rb', line 56

def button_for_function(name); @default_buttons[name]; end

#buttonsObject



57
58
59
60
61
# File 'lib/wizardly/wizard/configuration.rb', line 57

def buttons
  return @buttons if @buttons
  # reduce buttons
  @buttons = Hash[*@default_buttons.collect{|k,v|[v.id, v]}.flatten]
end

#first_page?(name) ⇒ Boolean



44
# File 'lib/wizardly/wizard/configuration.rb', line 44

def first_page?(name); @page_order.first == name; end

#form_data_keep_in_session?Boolean



38
# File 'lib/wizardly/wizard/configuration.rb', line 38

def form_data_keep_in_session?; @form_data == :session; end

#guard?Boolean



36
# File 'lib/wizardly/wizard/configuration.rb', line 36

def guard?; @guard_entry; end

#initial_referer_keyObject



74
75
76
# File 'lib/wizardly/wizard/configuration/methods.rb', line 74

def initial_referer_key
  @initial_referer_key ||= "#{self.controller_path.sub(/\//, '')}_irk".to_sym
end

#inspect_model!(model) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/wizardly/wizard/configuration.rb', line 73

def inspect_model!(model)
  # first examine the model symbol, transform and see if the constant
  # exists
  begin
    @wizard_model_sym = model.to_sym
    @wizard_model_class_name = model.to_s.camelize
    @wizard_model_const = @wizard_model_class_name.constantize
  rescue Exception=>e
    raise ModelNotFoundError, "Cannot convert :#{@wizard_model_sym} to model constant for #{@wizard_model_class_name}: " + e.message, caller
  end

  begin
    @page_order = @wizard_model_const.validation_group_order 
  rescue Exception => e
    raise ValidationGroupError, "Unable to read validation groups from #{@wizard_model_class_name}: " + e.message, caller
  end
  raise(ValidationGroupError, "No validation groups defined for model #{@wizard_model_class_name}", caller) unless (@page_order && !@page_order.empty?)

  begin
    groups = @wizard_model_const.validation_groups
    enum_attrs = @wizard_model_const.respond_to?(:enumerated_attributes) ? @wizard_model_const.enumerated_attributes.collect {|k,v| k } : []
    model_inst = @wizard_model_const.new
    last_index = @page_order.size-1
    @page_order.each_with_index do |p, index|
      fields = groups[p].map do |f|
        column = model_inst.column_for_attribute(f)
        type = case
        when enum_attrs.include?(f) then :enum
        when (@password_fields && @password_fields.include?(f)) then :password
        else
          column ? column.type : :string
        end
        PageField.new(f, type)
      end
      page = Page.new(self, p, fields)

      # default button settings based on order, can be altered by
      # set_page(@id).buttons_to []
      buttons = []
      buttons << @default_buttons[:next] unless index >= last_index
      buttons << @default_buttons[:finish] if index == last_index
      buttons << @default_buttons[:back] unless index == 0
      buttons << @default_buttons[:skip] if (@include_skip_button && index != last_index)
      buttons << @default_buttons[:cancel] if (@include_cancel_button)
      page.buttons = buttons
      @pages[page.id] = page
    end
  rescue Exception => e
    raise ValidationGroupError, "Failed to configure wizard from #{@wizard_model_class_name} validation groups: " + e.message, caller
  end
end

#last_page?(name) ⇒ Boolean



45
# File 'lib/wizardly/wizard/configuration.rb', line 45

def last_page?(name); @page_order.last == name; end

#modelObject



39
# File 'lib/wizardly/wizard/configuration.rb', line 39

def model; @wizard_model_sym; end

#model_class_nameObject



41
# File 'lib/wizardly/wizard/configuration.rb', line 41

def model_class_name; @wizard_model_class_name; end

#model_constObject



42
# File 'lib/wizardly/wizard/configuration.rb', line 42

def model_const; @wizard_model_const; end

#model_instance_variableObject



40
# File 'lib/wizardly/wizard/configuration.rb', line 40

def model_instance_variable; "@#{@wizard_model_sym.to_s}"; end

#next_page(name) ⇒ Object



46
47
48
49
50
# File 'lib/wizardly/wizard/configuration.rb', line 46

def next_page(name)
  index = @page_order.index(name)
  index += 1 unless self.last_page?(name)
  @page_order[index]
end

#persist_keyObject



77
78
79
# File 'lib/wizardly/wizard/configuration/methods.rb', line 77

def persist_key;
  @persist_key ||= "#{self.controller_path.sub(/\//, '')}_dat".to_sym 
end

#persist_model_per_page?Boolean



37
# File 'lib/wizardly/wizard/configuration.rb', line 37

def persist_model_per_page?; @persist_model == :per_page; end

#previous_page(name) ⇒ Object



51
52
53
54
55
# File 'lib/wizardly/wizard/configuration.rb', line 51

def previous_page(name)
  index = @page_order.index(name)
  index -= 1 unless self.first_page?(name)
  @page_order[index]
end


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/wizardly/wizard/configuration/methods.rb', line 5

def print_callback_macros
  macros = [ 
    %w(on_post _on_post_%s_form),
    %w(on_get _on_get_%s_form),
    %w(on_errors _on_invalid_%s_form)
  ]
  self.buttons.each do |id, button|
    macros << ['on_'+ id.to_s, '_on_%s_form_'+ id.to_s ]
  end
  mb = StringIO.new
  macros.each do |macro|
    mb << "  def self.\#{macro.first}(*args, &block)\n    self._define_action_callback_macro('\#{macro.first}', '\#{macro.last}', *args, &block)\n  end\n"
  end
  mb << "  def self._define_action_callback_macro(macro_first, macro_last, *args, &block)\n    return if args.empty?\n    all_forms = \#{page_order.inspect}\n    if args.include?(:all)\nforms = all_forms\n    else\nforms = args.map do |fa|\n  unless all_forms.include?(fa)\n    raise(ArgumentError, \":\"+fa.to_s+\" in callback '\" + macro_first + \"' is not a form defined for the wizard\", caller)\n  end\n  fa\nend\n    end\n    forms.each do |form|\nself.send(:define_method, sprintf(macro_last, form.to_s), &block )\nhide_action macro_last.to_sym\n    end\n  end\n\n"
  
  [
    %w(on_completed _after_wizard_save)
  ].each do |macro|
    mb << "  def self.\#{macro.first}(&block)\n    self.send(:define_method, :\#{macro.last}, &block )\n  end\n"
  end
  mb.string
end


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/wizardly/wizard/configuration/methods.rb', line 153

def print_callbacks
  finish = self.button_for_function(:finish).id
  skip = self.button_for_function(:skip).id
  back = self.button_for_function(:back).id
  cancel = self.button_for_function(:cancel).id
"  protected\n  def _on_wizard_\#{finish}\n    return if @wizard_completed_flag\n    @\#{self.model}.save_without_validation! if @\#{self.model}.changed?\n    @wizard_completed_flag = true\n    reset_wizard_form_data\n    _wizard_final_redirect_to(:completed)\n  end\n  def _on_wizard_\#{skip}\n    self.progression = self.progression - [@step]\n    redirect_to(:action=>wizard_config.next_page(@step)) unless self.performed?\n  end\n  def _on_wizard_\#{back} \n    redirect_to(:action=>(previous_in_progression_from(@step) || :\#{self.page_order.first})) unless self.performed?\n  end\n  def _on_wizard_\#{cancel}\n    _wizard_final_redirect_to(:canceled)\n  end\n  def _wizard_final_redirect_to(type)\n    init = (type == :canceled && wizard_config.form_data_keep_in_session?) ?\nself.initial_referer :\nreset_wizard_session_vars\n    unless self.performed?\nredir = (type == :canceled ? wizard_config.canceled_redirect : wizard_config.completed_redirect) || init\nreturn redirect_to(redir) if redir\nraise Wizardly::RedirectNotDefinedError, \"No redirect was defined for completion or canceling the wizard.  Use :completed and :canceled options to define redirects.\", caller\n    end\n  end\n  hide_action :_on_wizard_\#{finish}, :_on_wizard_\#{skip}, :_on_wizard_\#{back}, :_on_wizard_\#{cancel}, :_wizard_final_redirect_to\n" 
end


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/wizardly/wizard/configuration.rb', line 155

def print_config
  io = StringIO.new
  class_name = controller_name.to_s.camelize
  class_name += 'Controller' unless class_name =~ /Controller$/
  io.puts "#{class_name} wizard configuration"
  io.puts
  io.puts "model: #{model_class_name}"
  io.puts "instance: @#{model}"
  io.puts
  io.puts "pages:"
  self.page_order.each do |pid|
    page = pages[pid]
    # io.puts "  #{index+1}. '#{page.title}' page (:#{page.id}) has"
    io.puts "  '#{page.title}' page (:#{page.id}) has"
    io.puts "    --fields: #{page.fields.inject([]){|a, f| a << '"'+f.name.to_s.titleize+'" [:'+f.column_type.to_s+']'}.join(', ')}"
    io.puts "    --buttons: #{page.buttons.inject([]){|a, b| a << b.name.to_s }.join(', ')}"
  end
  io.puts
  io.puts "redirects:"
  io.puts "  when completed: #{completed_redirect ? completed_redirect.inspect : 'redirects to initial referer by default (specify :completed=>url to override)'}"
  io.puts "  when canceled: #{canceled_redirect ? canceled_redirect.inspect : 'redirects to initial referer by default (specify :canceled=>url to override)'}"
  io.puts   
  io.puts "buttons:"
  self.buttons.each do |k, b|
    bs = StringIO.new
    bs << "  #{b.name} (:#{b.id}) "
    if (b.user_defined?)
      bs << "-- user defined button and function"
    else
      dk = @default_buttons.index(b)
      bs << "-- used for internal <#{dk}> functionality"
    end
    io.puts bs.string
  end
  io.puts 
  io.string      
end


191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/wizardly/wizard/configuration/methods.rb', line 191

def print_helpers
  next_id = self.button_for_function(:next).id
  finish_id = self.button_for_function(:finish).id
  first_page = self.page_order.first
  finish_button = self.button_for_function(:finish).id        
  guard_line = self.guard? ? '' : 'return check_progression #guard entry disabled'
  mb = StringIO.new
  mb << "  protected\n  def do_not_complete; @do_not_complete = true; end\n  def previous_in_progression_from(step)\n    po = \#{self.page_order.inspect}\n    p = self.progression\n    p -= po[po.index(step)..-1]\n    self.progression = p\n    p.last\n  end\n  def check_progression\n    p = self.progression\n    a = params[:action].to_sym\n    return if p.last == a\n    po = \#{self.page_order.inspect}\n    return unless (ai = po.index(a))\n    p -= po[ai..-1]\n    p << a\n    self.progression = p\n  end        \n"
  if self.form_data_keep_in_session?
    mb << "  # for :form_data=>:session\n  def guard_entry \n    if (r = request.env['HTTP_REFERER'])\nbegin\n  h = ::ActionController::Routing::Routes.recognize_path(URI.parse(r).path, {:method=>:get})\nrescue\nelse\n  return check_progression if (h[:controller]||'') == '\#{self.controller_path}'\n  self.initial_referer = h unless self.initial_referer\nend\n    end\n    # coming from outside the controller or no route for GET\n    \#{guard_line}\n    if (params[:action] == '\#{first_page}' || params[:action] == 'index')\nreturn check_progression\n    elsif self.wizard_form_data\np = self.progression\nreturn check_progression if p.include?(params[:action].to_sym)\nreturn redirect_to(:action=>(p.last||:\#{first_page}))\n    end\n    redirect_to :action=>:\#{first_page}\n  end\n  hide_action :guard_entry\n\n"
  else
    mb << "  # for :form_data=>:sandbox            \n  def guard_entry \n    if (r = request.env['HTTP_REFERER'])\nbegin\n  h = ::ActionController::Routing::Routes.recognize_path(URI.parse(r).path, {:method=>:get})\nrescue\nelse\n  return check_progression if (h[:controller]||'') == '\#{self.controller_path}'\n  self.initial_referer = h\nend\n    else\nself.initial_referer = nil \n    end\n    # coming from outside the controller\n    reset_wizard_form_data \n    \#{guard_line}\n    return redirect_to(:action=>:\#{first_page}) unless (params[:action] || '') == '\#{first_page}'\n    check_progression\n  end\n  hide_action :guard_entry\n\n"
  end
  mb << "  def render_and_return\n    return if callback_performs_action?('_on_get_'[email protected]_s+'_form')\n    render_wizard_form\n    render unless self.performed?\n  end\n\n  def complete_wizard(redirect = nil)\n    unless @wizard_completed_flag\n@\#{self.model}.save_without_validation!\ncallback_performs_action?(:_after_wizard_save)\n    end\n    redirect_to redirect if (redirect && !self.performed?)\n    return if @wizard_completed_flag\n    _on_wizard_\#{finish_button}\n    redirect_to(\#{Utils.formatted_redirect(self.completed_redirect)}) unless self.performed?\n  end\n  def _build_wizard_model\n    if self.wizard_config.persist_model_per_page?\nh = self.wizard_form_data\nif (h && model_id = h['id'])\n    _model = \#{self.model_class_name}.find(model_id)\n    _model.attributes = params[:\#{self.model}]||{}\n    @\#{self.model} = _model\n    return\nend\n@\#{self.model} = \#{self.model_class_name}.new(params[:\#{self.model}])\n    else # persist data in session or flash\nh = (self.wizard_form_data||{}).merge(params[:\#{self.model}] || {})\n@\#{self.model} = \#{self.model_class_name}.new(h)\n    end\n  end\n  def _preserve_wizard_model\n    return unless (@\#{self.model} && !@wizard_completed_flag)\n    if self.wizard_config.persist_model_per_page?\n@\#{self.model}.save_without_validation!\nif request.get?\n  @\#{self.model}.errors.clear\nelse\n  @\#{self.model}.reject_non_validation_group_errors\nend\nself.wizard_form_data = {'id'=>@\#{self.model}.id}\n    else\nself.wizard_form_data = @\#{self.model}.attributes\n    end\n  end\n  hide_action :_build_wizard_model, :_preserve_wizard_model\n\n  def initial_referer\n    session[:\#{self.initial_referer_key}]\n  end\n  def initial_referer=(val)\n    session[:\#{self.initial_referer_key}] = val\n  end\n  def progression=(array)\n    session[:\#{self.progression_key}] = array\n  end\n  def progression\n    session[:\#{self.progression_key}]||[]\n  end\n  hide_action :progression, :progression=, :initial_referer, :initial_referer=\n\n  def wizard_form_data=(hash)\n    if wizard_config.form_data_keep_in_session?\nsession[:\#{self.persist_key}] = hash\n    else\nif hash\n  flash[:\#{self.persist_key}] = hash\nelse\n  flash.discard(:\#{self.persist_key})\nend\n    end\n  end\n\n  def reset_wizard_form_data; self.wizard_form_data = nil; end\n  def wizard_form_data\n    wizard_config.form_data_keep_in_session? ? session[:\#{self.persist_key}] : flash[:\#{self.persist_key}]\n  end\n  hide_action :wizard_form_data, :wizard_form_data=, :reset_wizard_form_data\n\n  def render_wizard_form\n  end\n  hide_action :render_wizard_form\n\n  def performed?; super; end\n  hide_action :performed?\n\n  def underscore_button_name(value)\n    value.to_s.strip.squeeze(' ').gsub(/ /, '_').downcase\n  end\n  hide_action :underscore_button_name\n\n  def reset_wizard_session_vars\n    self.progression = nil\n    init = self.initial_referer\n    self.initial_referer = nil\n    init\n  end\n  hide_action :reset_wizard_session_vars\n\n  def check_action_for_button\n    button_id = nil\n    case \n    when params[:commit]\nbutton_name = params[:commit]\nbutton_id = underscore_button_name(button_name).to_sym\n    when ((b_ar = self.wizard_config.buttons.find{|k,b| params[k]}) && params[b_ar.first] == b_ar.last.name)\nbutton_name = b_ar.last.name\nbutton_id = b_ar.first\n    end\n    if button_id\nunless [:\#{next_id}, :\#{finish_id}].include?(button_id) \n  action_method_name = \"_on_\" + params[:action].to_s + \"_form_\" + button_id.to_s\n  callback_performs_action?(action_method_name)\n  unless ((btn_obj = self.wizard_config.buttons[button_id]) == nil || btn_obj.user_defined?)\n    method_name = \"_on_wizard_\" + button_id.to_s\n    if (self.method(method_name))\n      self.__send__(method_name)\n    else\n      raise MissingCallbackError, \"Callback method either '\" + action_method_name + \"' or '\" + method_name + \"' not defined\", caller\n    end\n  end\nend\n    end\n    button_id\n  end\n  hide_action :check_action_for_button\n\n  @wizard_callbacks ||= []\n  def self.wizard_callbacks; @wizard_callbacks; end\n\n  def callback_performs_action?(methId)\n    cache = self.class.wizard_callbacks\n    return false if cache.include?(methId)\n\n    if self.respond_to?(methId, true)\nself.send(methId)\n    else\ncache << methId\nreturn false\n    end\n    \n    self.performed?\n  end\n  hide_action :callback_performs_action?\n\n"
  mb.string
end


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/wizardly/wizard/configuration/methods.rb', line 84

def print_page_action_method(id)
  page = @pages[id]
  finish_button = self.button_for_function(:finish).id
  next_button = self.button_for_function(:next).id

  (mb = StringIO.new) << "  def \#{page.name}\n    begin\n@step = :\#{id}\n@wizard = wizard_config\n@title = '\#{page.title}'\n@description = '\#{page.description}'\n_build_wizard_model\nif request.post? && callback_performs_action?(:_on_post_\#{id}_form)\n  raise CallbackError, \"render or redirect not allowed in :on_post(:\#{id}) callback\", caller\nend\nbutton_id = check_action_for_button\nreturn if performed?\nif request.get?\n  return if callback_performs_action?(:_on_get_\#{id}_form)\n  render_wizard_form\n  return\nend\n\n# @\#{self.model}.enable_validation_group :\#{id}\nunless @\#{self.model}.valid?(:\#{id})\n  return if callback_performs_action?(:_on_invalid_\#{id}_form)\n  render_wizard_form\n  return\nend\n\n@do_not_complete = false\n  ONE\n  if self.last_page?(id)\n    mb << <<-TWO\ncallback_performs_action?(:_on_\#{id}_form_\#{finish_button})\ncomplete_wizard unless @do_not_complete\n  TWO\n  elsif self.first_page?(id)\n    mb << <<-THREE\nif button_id == :\#{finish_button}\n  callback_performs_action?(:_on_\#{id}_form_\#{finish_button})\n  complete_wizard unless @do_not_complete\n  return\nend\nreturn if callback_performs_action?(:_on_\#{id}_form_\#{next_button})\nredirect_to :action=>:\#{self.next_page(id)}\n  THREE\n  else \n    mb << <<-FOUR\nif button_id == :\#{finish_button}\n  callback_performs_action?(:_on_\#{id}_form_\#{finish_button})\n  complete_wizard unless @do_not_complete\n  return\nend\nreturn if callback_performs_action?(:_on_\#{id}_form_\#{next_button})\nredirect_to :action=>:\#{self.next_page(id)}\n  FOUR\n  end\n  \n  mb << <<-ENSURE\n    ensure\n_preserve_wizard_model\n    end\n  end        \nENSURE\n  mb.string\nend\n"


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/wizardly/wizard/configuration/methods.rb', line 56

def print_page_action_methods
  mb = StringIO.new
  self.pages.each do |id, p|
    mb << "\n  # \#{id} action method\n\#{self.print_page_action_method(id)}\n    COMMENT\n  end\n  mb << <<-INDEX\n  def index\n    redirect_to :action=>:\#{self.page_order.first}\n  end\n\n  INDEX\n  mb.string\nend\n"

#progression_keyObject



80
81
82
# File 'lib/wizardly/wizard/configuration/methods.rb', line 80

def progression_key
  @progression_key ||= "#{self.controller_path.sub(/\//, '')}_prg".to_sym
end