wicked 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of wicked might be problematic. Click here for more details.

data/README.md CHANGED
@@ -278,6 +278,49 @@ Now when you visit your controller with the proper locale set your url's should
278
278
 
279
279
  Wicked expects your files to be named the same as your keys, so when a user visits `after_signup/dos` with the `es` locale it will render the `second.html.erb` file.
280
280
 
281
+
282
+ **Important:** When you do this the value of `step` as well as
283
+ `next_step` and `previous_step` and all the values within `steps` will
284
+ be translated to what locale you are using. To translate them to the
285
+ "canonical" values that you've have in your controller you'll need so
286
+ use `wizard_value` method.
287
+
288
+ For example, if you had this in your controller, and you converted it to
289
+ a use Wicked translations, so this will not work:
290
+
291
+ ```
292
+ steps :confirm_password, :confirm_profile, :find_friends
293
+
294
+ def show
295
+ case step
296
+ when :find_friends
297
+ @friends = current_user.find_friends
298
+ end
299
+ render_wizard
300
+ end
301
+ ```
302
+
303
+ Instead you need to use `wizard_value` to get the "reverse translation" in your controller code like this:
304
+
305
+
306
+ ```
307
+ steps :confirm_password, :confirm_profile, :find_friends
308
+
309
+ def show
310
+ case wizard_value(step)
311
+ when :find_friends
312
+ @friends = current_user.find_friends
313
+ end
314
+ render_wizard
315
+ end
316
+ ```
317
+
318
+ The important thing to remember is that `step` and the values in `steps` are
319
+ always going to be in the same language if you're using the Wicked translations.
320
+ If you need any values to match the values set directly in your controller,
321
+ or the names of your files (i.e. `views/../confirm_password.html.erb`, then you need
322
+ to use `wizard_value` method.
323
+
281
324
  ## Custom URL's
282
325
 
283
326
  Very similar to using I18n from above but instead of making new files for different languages, you can stick with one language. Make sure you are using the right module:
@@ -301,6 +344,10 @@ Now you can change the values in the URL's to whatever you want without changing
301
344
  ```ruby
302
345
  config.i18n.default_locale = :de
303
346
  ```
347
+ **Important:** Don't forget to use `wizard_value()` method to make
348
+ sure you are using the right cannonical values of `step`,
349
+ `previous_step`, `next_step`, etc. If you are comparing them to non
350
+ wicked generate values.
304
351
 
305
352
  Custom crafted wizard urls: just another way Wicked makes your app a little more saintly.
306
353
 
@@ -324,7 +371,7 @@ def set_steps
324
371
  end
325
372
  ```
326
373
 
327
- Note: Do not pass user submitted params directly into `self.steps` while using the custom or translated urls. The translator calls `to_sym` on steps provided, and if a user is allowed to submit arbitrary symbols, they could flood the take down your production app by filling up the symbol table. So just don't do it.
374
+ Note: Do not pass user submitted params directly into `self.steps` while using the custom or translated urls. The translator calls `to_sym` on steps provided, and if a user is allowed to submit arbitrary symbols, they could flood the take down your production app by filling up the symbol table. So, just don't do it.
328
375
 
329
376
  ## About
330
377
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -8,7 +8,7 @@ module Wicked::Controller::Concerns::RenderRedirect
8
8
  if @skip_to
9
9
  redirect_to wizard_path(@skip_to), options
10
10
  else
11
- render_step @step, options
11
+ render_step wizard_value(step), options
12
12
  end
13
13
  end
14
14
 
data/lib/wicked/wizard.rb CHANGED
@@ -22,6 +22,11 @@ module Wicked
22
22
  redirect_to wizard_path(steps.first, clean_params)
23
23
  end
24
24
 
25
+ # returns the canonical value for a step name, needed for translation support
26
+ def wizard_value(step_name)
27
+ step_name
28
+ end
29
+
25
30
  private
26
31
 
27
32
  def clean_params
@@ -45,12 +50,16 @@ module Wicked
45
50
  raise "Wicked Wizard steps expected but not yet set, if setting via `before_filter` use `prepend_before_filter`" if steps.nil?
46
51
  end
47
52
 
48
- def setup_wizard
49
- @step = setup_step_from(params[:id])
50
- check_steps!(@step)
53
+ def set_previous_next(step)
51
54
  @previous_step = previous_step(@step)
52
55
  @next_step = next_step(@step)
53
56
  end
57
+
58
+ def setup_wizard
59
+ @step = setup_step_from(params[:id])
60
+ check_steps!(@step)
61
+ set_previous_next(@step)
62
+ end
54
63
  public
55
64
  end
56
65
  end
@@ -2,28 +2,65 @@ module Wicked
2
2
  module Wizard
3
3
  module Translated
4
4
  extend ActiveSupport::Concern
5
+ include Wicked::Wizard
5
6
 
6
7
  included do
7
- include Wicked::Wizard
8
8
  skip_before_filter :setup_wizard
9
9
  before_filter :setup_wizard_translated
10
+
11
+ helper_method :wizard_translate, :wizard_value
10
12
  end
11
13
 
12
14
  # creates a hash where keys are translated steps, values are the name of the view file
13
- # {:first => "first", :second => "second"}
14
- # {:uno => "first", :dos => "second"}
15
+ #
16
+ # es:
17
+ # hello: "hola mundo"
18
+ # wicked:
19
+ # first: "uno"
20
+ # second: "dos"
21
+ #
22
+ # steps :first, :second
23
+ #
24
+ # {:uno => :first, :dos => :second} # spanish
25
+ # {:first => :first, :second => :second} # english
15
26
  #
16
27
  def wizard_translations
17
28
  @wizard_translations ||= steps.inject(ActiveSupport::OrderedHash.new) do |hash, step|
18
- step = step.to_s.split(".").last
19
- translation = I18n.t("wicked.#{step}").to_sym
29
+ step = step.to_s.split(".").last
30
+ translation = wizard_translate(step)
20
31
  hash[translation] = step.to_sym
21
32
  hash
22
33
  end
23
34
  end
24
35
 
25
- private
36
+ # takes a canonical wizard value and translates to correct language
37
+ #
38
+ # es.yml
39
+ # wicked:
40
+ # first: "uno"
41
+ #
42
+ # wizard_translate(:first) # => :uno
43
+ def wizard_translate(step_name)
44
+ I18n.t("wicked.#{step_name}", :raise => true).to_sym
45
+ rescue I18n::MissingTranslationData
46
+ # don't symbolize if key doesn't exist
47
+ I18n.t("wicked.#{step_name}")
48
+ end
49
+
50
+ # takes an already translated value and converts to a canonical wizard value
51
+ #
52
+ # es.yml
53
+ # wicked:
54
+ # first: "uno"
55
+ #
56
+ # wizard_value(step) # => :first
57
+ #
58
+ def wizard_value(step_name)
59
+ wizard_translations[step]
60
+ end
61
+
26
62
 
63
+ private
27
64
  # sets up a translated wizard controller
28
65
  # translations are expected under the 'wicked' namespace
29
66
  #
@@ -41,14 +78,13 @@ module Wicked
41
78
  # steps "wicked.first", "wicked.second"
42
79
  #
43
80
  def setup_wizard_translated
44
- self.steps = wizard_translations.keys # must come before setting previous/next steps
45
- step_name = setup_step_from(params[:id])
46
- check_steps!(step_name)
47
- @previous_step = previous_step(step_name)
48
- @next_step = next_step(step_name)
49
- @step = wizard_translations[step_name] # translates step name to url
81
+ self.steps = wizard_translations.keys # must come before setting previous/next steps
82
+ @step = setup_step_from(params[:id])
83
+ check_steps!(@step)
84
+ set_previous_next(@step)
50
85
  end
51
86
  public
52
87
  end
53
88
  end
54
89
  end
90
+
@@ -1,7 +1,7 @@
1
1
  class I18nController < ApplicationController
2
2
  include Wicked::Wizard::Translated
3
3
 
4
- steps :first, :second
4
+ steps :first, :second, :last_step
5
5
 
6
6
  def show
7
7
  render_wizard
@@ -1,4 +1,5 @@
1
- <%= I18n.t('wicked.first') %>
1
+ <%= "Hey ya'll we're looking at: #{I18n.t('wicked.first')}" %>
2
2
 
3
+ <%= render :partial => "step_positions/step_position" %>
3
4
 
4
- <%= link_to "hello", next_wizard_path %>
5
+ <%= link_to "hello", next_wizard_path %>
@@ -0,0 +1,9 @@
1
+
2
+ <%= "Hey ya'll we're looking at: #{I18n.t('wicked.last_step')}" %>
3
+
4
+
5
+ <%= render :partial => "step_positions/step_position" %>
6
+
7
+
8
+
9
+
@@ -1 +1,7 @@
1
- <%= I18n.t('wicked.second') %>
1
+ <%= "Hey ya'll we're looking at: #{I18n.t('wicked.second')}" %>
2
+
3
+
4
+
5
+ <%= render :partial => "step_positions/step_position" %>
6
+
7
+
@@ -1,9 +1,10 @@
1
1
  <% wizard_steps.each do |s| %>
2
2
  <p>
3
- <%= "#{s} step is the current step" if current_step?(s) %><br />
4
- <%= "#{s} step is a past step" if past_step?(s) %><br />
5
- <%= "#{s} step is a future step" if future_step?(s) %><br />
6
- <%= "#{s} step was the previous step" if previous_step?(s) %><br />
7
- <%= "#{s} step is the next step" if next_step?(s) %><br />
3
+ <strong><u><%= s.inspect %></u></strong><br />
4
+ <%= current_step?(s) ? "#{s} step is the current step" : "nope" %><br />
5
+ <%= past_step?(s) ? "#{s} step is a past step" : "nope" %><br />
6
+ <%= future_step?(s) ? "#{s} step is a future step" : "nope" %><br />
7
+ <%= previous_step?(s) ? "#{s} step was the previous step" : "nope" %><br />
8
+ <%= next_step?(s) ? "#{s} step is the next step" : "nope" %><br />
8
9
  </p>
9
- <% end %>
10
+ <% end %>
@@ -5,4 +5,5 @@ en:
5
5
  hello: "Hello world"
6
6
  wicked:
7
7
  first: "first"
8
- second: "second"
8
+ second: "second"
9
+ last_step: "last_step"
@@ -5,4 +5,6 @@ es:
5
5
  hello: "hola mundo"
6
6
  wicked:
7
7
  first: "uno"
8
- second: "dos"
8
+ second: "dos"
9
+ last_step: "último_paso"
10
+
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class I18nTest < ActiveSupport::IntegrationCase
@@ -5,14 +7,27 @@ class I18nTest < ActiveSupport::IntegrationCase
5
7
  test 'renders in spanish' do
6
8
  step = :uno
7
9
  visit(i18n_path(step, :locale => :es))
8
- assert has_content?('uno')
10
+ assert has_content?("Hey ya'll we're looking at: uno")
9
11
  assert has_link?('hello', :href => i18n_path(:dos))
12
+ assert has_content?('uno step is the current step') # current_step?
13
+ assert true # past_step?
14
+ assert has_content?('dos step is a future step') # future_step?
15
+ assert has_content?('último_paso step is a future step') # future_step?
16
+ assert true # previous_step?
17
+ assert has_content?('dos step is the next step') # next_step?
10
18
  end
11
19
 
12
20
  test 'renders in english' do
13
21
  step = :first
14
22
  visit(i18n_path(step, :locale => :en))
15
- assert has_content?('first')
23
+ assert has_content?("Hey ya'll we're looking at: first")
16
24
  assert has_link?('hello', :href => i18n_path(:second))
25
+
26
+ assert has_content?('first step is the current step') # current_step?
27
+ assert true # past_step?
28
+ assert has_content?('last_step step is a future step') # future_step?
29
+ assert has_content?('second step is a future step') # future_step?
30
+ assert true # previous_step?
31
+ assert has_content?('second step is the next step') # next_step?
17
32
  end
18
33
  end
data/wicked.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wicked"
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["schneems"]
12
- s.date = "2013-01-16"
12
+ s.date = "2013-01-27"
13
13
  s.description = "Wicked is a Rails engine for producing easy wizard controllers"
14
14
  s.email = "richard.schneeman@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -49,6 +49,7 @@ Gem::Specification.new do |s|
49
49
  "test/dummy/app/views/bar/second.html.erb",
50
50
  "test/dummy/app/views/dynamic_steps/first.html.erb",
51
51
  "test/dummy/app/views/i18n/first.html.erb",
52
+ "test/dummy/app/views/i18n/last_step.html.erb",
52
53
  "test/dummy/app/views/i18n/second.html.erb",
53
54
  "test/dummy/app/views/jump/first.html.erb",
54
55
  "test/dummy/app/views/jump/last_step.html.erb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wicked
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-16 00:00:00.000000000Z
12
+ date: 2013-01-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70204702345240 !ruby/object:Gem::Requirement
16
+ requirement: &70274032800580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70204702345240
24
+ version_requirements: *70274032800580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70204702344580 !ruby/object:Gem::Requirement
27
+ requirement: &70274032799480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.7
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70204702344580
35
+ version_requirements: *70274032799480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70204702343980 !ruby/object:Gem::Requirement
38
+ requirement: &70274032798600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70204702343980
46
+ version_requirements: *70274032798600
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70204702341060 !ruby/object:Gem::Requirement
49
+ requirement: &70274032797260 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70204702341060
57
+ version_requirements: *70274032797260
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70204702340560 !ruby/object:Gem::Requirement
60
+ requirement: &70274032795260 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70204702340560
68
+ version_requirements: *70274032795260
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: capybara
71
- requirement: &70204702340040 !ruby/object:Gem::Requirement
71
+ requirement: &70274032793220 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.4.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70204702340040
79
+ version_requirements: *70274032793220
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: launchy
82
- requirement: &70204702339560 !ruby/object:Gem::Requirement
82
+ requirement: &70274032791980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70204702339560
90
+ version_requirements: *70274032791980
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: sqlite3
93
- requirement: &70204702339020 !ruby/object:Gem::Requirement
93
+ requirement: &70274032790300 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70204702339020
101
+ version_requirements: *70274032790300
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: activerecord-jdbcsqlite3-adapter
104
- requirement: &70204702338540 !ruby/object:Gem::Requirement
104
+ requirement: &70274032789360 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70204702338540
112
+ version_requirements: *70274032789360
113
113
  description: Wicked is a Rails engine for producing easy wizard controllers
114
114
  email: richard.schneeman@gmail.com
115
115
  executables: []
@@ -150,6 +150,7 @@ files:
150
150
  - test/dummy/app/views/bar/second.html.erb
151
151
  - test/dummy/app/views/dynamic_steps/first.html.erb
152
152
  - test/dummy/app/views/i18n/first.html.erb
153
+ - test/dummy/app/views/i18n/last_step.html.erb
153
154
  - test/dummy/app/views/i18n/second.html.erb
154
155
  - test/dummy/app/views/jump/first.html.erb
155
156
  - test/dummy/app/views/jump/last_step.html.erb
@@ -217,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
218
  version: '0'
218
219
  segments:
219
220
  - 0
220
- hash: -2935823026133279485
221
+ hash: 3061735520943754362
221
222
  required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  none: false
223
224
  requirements: