jeffp-wizardly 0.1.8.5 → 0.1.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -533,16 +533,32 @@ The default button names can be customized in the +act_wizardly_for+ code block
533
533
  end
534
534
 
535
535
  With the above code, the 'Back' button will now be named 'Previous Page' and the 'Finish'
536
- button is renamed to the longer name 'Save and Return'. Notice that symbols are used
536
+ button is renamed to the longer name 'Save and Return'.
537
+
538
+ Notice that symbols are used
537
539
  to determine the default button, but the customized name is passed. A new symbol
538
540
  representing the change is created for each change, hence, for our buttons above :back
539
541
  is now referred to as :previous_page and :finish is now referred to as :save_and_return.
540
542
 
541
543
  === Action Callbacks for Customized Buttons
542
544
 
543
- Changing the name of a default button also changes the name of its callback macro.
544
- For instance, the on_back() and on_finish() callback macros are replaced by the following
545
- for the above example
545
+ Changing the name of a default button does not change the name of its callback macro.
546
+ For instance, the renamed :back and :finish buttons above (to 'Previous Page' and 'Save and Return', respectively)
547
+ still use the on_back() and on_finish() callback macros despite the name change.
548
+
549
+ Perhaps though you want to change the symbol used to represent the button for consistancy
550
+ across your MVC. You can use the :id option when renaming to do so.
551
+
552
+ class UserSignupController < ApplicationController
553
+ act_wizardly_for :user, :redirect=>'/main/index' do
554
+ change_button(:back).name_to('Previous Page', :id=>:previous_page)
555
+ change_button(:finish).name_to('Save and Return', :id=>save_and_return)
556
+ end
557
+ end
558
+
559
+ Coding the above causes the :back button's ID to be replaced with :previous_page and so forth
560
+ for the :finish button. Thereafter, each button is referred to with the new ID. For instance,
561
+ the corresponding callback macros would be
546
562
 
547
563
  on_previous_page(:step3) do
548
564
  ...
@@ -573,6 +589,13 @@ button must be defined by the on_help() callback macros for each and every page.
573
589
  end
574
590
  end
575
591
 
592
+ Sometimes you may want to use the default ID given to the button. You can specify the ID
593
+ with the :id option. This is particularly useful for international languages.
594
+
595
+ create_button('Helfen', :id=>:help)
596
+
597
+ Now the help button will be called 'Helfen' in German and will be represented by :help in the code.
598
+
576
599
  === Setting Buttons for a Wizard Page
577
600
 
578
601
  Any new button needs to be explicitly added to every page it will show up on. Each
@@ -16,14 +16,12 @@ module Wizardly
16
16
  def user_defined?; @user_defined; end
17
17
 
18
18
  #used in the dsl
19
- def name_to(name)
20
- if name.is_a?(String)
21
- @name = name.strip.squeeze(' ')
22
- @id = button_name_to_symbol(name)
23
- elsif name.is_a?(Symbol)
24
- @id = name
25
- @name = symbol_to_button_name(name)
19
+ def name_to(name, opts={})
20
+ case name
21
+ when String then @name = name.strip.squeeze(' ')
22
+ when Symbol then @name = symbol_to_button_name(name)
26
23
  end
24
+ @id = opts[:id] if (opts[:id] && opts[:id].is_a?(Symbol))
27
25
  end
28
26
  end
29
27
 
@@ -126,13 +126,14 @@ module Wizardly
126
126
  def _when_completed_redirect_to(redir); @completed_redirect = redir; end
127
127
  def _when_canceled_redirect_to(redir); @canceled_redirect = redir; end
128
128
  def _change_button(name)
129
- raise(WizardConfigurationError, "Button :#{name} in _change_button() call does not exist", caller) unless @default_buttons.key?(name)
130
- @buttons = nil
131
- @default_buttons[name]
129
+ raise(WizardConfigurationError, "Button :#{name} in _change_button() call does not exist", caller) unless self.buttons.key?(name)
130
+ _buttons = self.buttons
131
+ @buttons = nil # clear the buttons for regeneration after change in next line
132
+ _buttons[name]
132
133
  end
133
- def _create_button(name)
134
- id = button_name_to_symbol(name)
135
- raise(WizardConfigurationError, "Button '#{name}' with id :#{id} cannot be created. The ID already exists.", caller) if @default_buttons.key?(id)
134
+ def _create_button(name, opts)
135
+ id = opts[:id] || button_name_to_symbol(name)
136
+ raise(WizardConfigurationError, "Button '#{name}' with id :#{id} cannot be created. The ID already exists.", caller) if self.buttons.key?(id)
136
137
  @buttons=nil
137
138
  @default_buttons[id] = UserDefinedButton.new(id, name)
138
139
  end
@@ -279,7 +279,7 @@ SANDBOX
279
279
  redirect_to redirect if (redirect && !self.performed?)
280
280
  return if @wizard_completed_flag
281
281
  _on_wizard_#{finish_button}
282
- redirect_to #{Utils.formatted_redirect(self.completed_redirect)} unless self.performed?
282
+ redirect_to(#{Utils.formatted_redirect(self.completed_redirect)}) unless self.performed?
283
283
  end
284
284
  def build_wizard_model(params)
285
285
  if (wizard_config.persist_model_per_page? && (model_id = params['id']))
@@ -348,14 +348,20 @@ SANDBOX
348
348
 
349
349
  def check_action_for_button
350
350
  button_id = nil
351
- #check if params[:commit] has returned a button from submit_tag
352
- unless (params[:commit] == nil)
353
- button_name = underscore_button_name(params[:commit])
354
- unless [:#{next_id}, :#{finish_id}].include?(button_id = button_name.to_sym)
355
- action_method_name = "_on_" + params[:action].to_s + "_form_" + button_name
351
+ case
352
+ when params[:commit]
353
+ button_name = params[:commit]
354
+ button_id = underscore_button_name(button_name).to_sym
355
+ when ((b_ar = self.wizard_config.buttons.find{|k,b| params[k]}) && params[b_ar.first] == b_ar.last.name)
356
+ button_name = b_ar.last.name
357
+ button_id = b_ar.first
358
+ end
359
+ if button_id
360
+ unless [:#{next_id}, :#{finish_id}].include?(button_id)
361
+ action_method_name = "_on_" + params[:action].to_s + "_form_" + button_id.to_s
356
362
  callback_performs_action?(action_method_name)
357
363
  unless ((btn_obj = self.wizard_config.buttons[button_id]) == nil || btn_obj.user_defined?)
358
- method_name = "_on_wizard_" + button_name
364
+ method_name = "_on_wizard_" + button_id.to_s
359
365
  if (self.method(method_name))
360
366
  self.__send__(method_name)
361
367
  else
@@ -364,25 +370,24 @@ SANDBOX
364
370
  end
365
371
  end
366
372
  end
367
- #add other checks here or above
368
373
  button_id
369
374
  end
370
375
  hide_action :check_action_for_button
371
376
 
372
- @wizard_callbacks ||= {}
377
+ @wizard_callbacks ||= []
373
378
  def self.wizard_callbacks; @wizard_callbacks; end
374
379
 
375
380
  def callback_performs_action?(methId)
376
381
  cache = self.class.wizard_callbacks
377
- return false if ((m = cache[methId]) == :none)
378
- unless m == :found
379
- unless self.methods.include?(methId.to_s)
380
- cache[methId] = :none
381
- return false
382
- end
383
- cache[methId] = :found
382
+ return false if cache.include?(methId)
383
+
384
+ begin
385
+ self.send(methId)
386
+ rescue NoMethodError
387
+ cache << methId
388
+ return false
384
389
  end
385
- self.method(methId).call
390
+
386
391
  self.performed?
387
392
  end
388
393
  hide_action :callback_performs_action?
@@ -12,8 +12,8 @@ module Wizardly
12
12
  def change_button(name)
13
13
  @config._change_button(name)
14
14
  end
15
- def create_button(name)
16
- @config._create_button(name)
15
+ def create_button(name, opts)
16
+ @config._create_button(name, opts)
17
17
  end
18
18
  def set_page(name);
19
19
  @config._set_page(name)
@@ -6,7 +6,7 @@ module <%=controller_name.camelize %>Helper
6
6
  unless @@wizardly_submit[step_id]
7
7
  buttons = @wizard.pages[@step].buttons
8
8
  @@wizardly_submit[step_id] = buttons.inject(StringIO.new) do |io, button|
9
- io << submit_tag(button.name)
9
+ io << submit_tag(button.name, :name=>button.id.to_s)
10
10
  end.string
11
11
  end
12
12
  @@wizardly_submit[step_id]
@@ -18,9 +18,9 @@ module <%=controller_name.camelize %>Helper
18
18
  unless @@wizardly_image_submit[step_id]
19
19
  asset_dir = asset_dir ? "#{asset_dir}/".squeeze("/").sub(/^\//,'') : "wizardly/"
20
20
  buttons = @wizard.pages[@step].buttons
21
- opts[:name] = 'commit'
22
21
  @@wizardly_image_submit[step_id] = buttons.inject(StringIO.new) do |io, button|
23
22
  opts[:value] = button.name
23
+ opts[:name] = button.id.to_s
24
24
  io << image_submit_tag("#{asset_dir}#{button.id}.png", opts)
25
25
  end.string
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeffp-wizardly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8.5
4
+ version: 0.1.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Patmon
@@ -71,7 +71,6 @@ files:
71
71
  - README.rdoc
72
72
  has_rdoc: false
73
73
  homepage: http://github.com/jeffp/wizardly/tree/master
74
- licenses:
75
74
  post_install_message:
76
75
  rdoc_options: []
77
76
 
@@ -92,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
91
  requirements: []
93
92
 
94
93
  rubyforge_project:
95
- rubygems_version: 1.3.5
94
+ rubygems_version: 1.2.0
96
95
  signing_key:
97
96
  specification_version: 3
98
97
  summary: Produces controllers and wizard scaffolding for models with validation_groups