wizardry 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,7 +4,7 @@ Simple step-by-step wizard for Rails.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add this line to your application's `Gemfile`:
8
8
 
9
9
  ```ruby
10
10
  gem 'wizardry'
@@ -63,7 +63,7 @@ To get name of the next and previous steps:
63
63
  @product.previous_step
64
64
  ```
65
65
 
66
- If not exists next/previous step then `nil` will be returned.
66
+ If not exists **next/previous** step then `nil` will be returned.
67
67
 
68
68
  Class methods are accessible:
69
69
 
@@ -85,5 +85,39 @@ end
85
85
  wizardry_resources :products
86
86
  ```
87
87
 
88
- will replace default *:id/edit* path with *:id/edit/:step* (and `:step => /initial|middle|final/` in our example).
88
+ will replace default `:id/edit` path with `:id/edit/:step` (and `:step => /initial|middle|final/` in our example).
89
89
  `has_wizardry` is also acceptable for singular resources. And `wizardry_resource` herper is here for that.
90
+
91
+ ## I18n
92
+
93
+ ```
94
+ en:
95
+ wizardry:
96
+ steps:
97
+ initial: 'Product details'
98
+ middle: 'Upload images'
99
+ ```
100
+
101
+ To get the translated step name:
102
+
103
+ ```ruby
104
+ @product.step_title(:middle) # => 'Upload images'
105
+ ```
106
+
107
+ If you are passing nonexistent step name, then will be returned `nil`.
108
+
109
+ Without providing the step name, you will get the translation for `current_step`:
110
+
111
+ ```ruby
112
+ @product.step_title # => 'Product details'
113
+ ```
114
+
115
+ In case of absence of step translation:
116
+
117
+ ```ruby
118
+ @product.step_title(:final) # => 'Final'
119
+ ```
120
+
121
+ ## License
122
+
123
+ MIT License. Copyright 2012 Aleksey Magusev.
@@ -36,16 +36,21 @@ module Wizardry
36
36
  end
37
37
 
38
38
  def next_step
39
- steps[current_step_index + 1] unless last_step?
39
+ steps[current_step_idx + 1] unless last_step?
40
40
  end
41
41
 
42
42
  def previous_step
43
- steps[current_step_index - 1] unless first_step?
43
+ steps[current_step_idx - 1] unless first_step?
44
+ end
45
+
46
+ def step_title(step = current_step)
47
+ return nil if step !~ steps_regexp
48
+ I18n.translate(step, scope: 'wizardry.steps', default: step.to_s.humanize)
44
49
  end
45
50
 
46
51
  private
47
52
 
48
- def current_step_index
53
+ def current_step_idx
49
54
  steps.index(current_step)
50
55
  end
51
56
  end
@@ -1,3 +1,3 @@
1
1
  module Wizardry
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -2,4 +2,7 @@
2
2
  # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
3
 
4
4
  en:
5
- hello: "Hello world"
5
+ wizardry:
6
+ steps:
7
+ initial: Product details
8
+ middle: Upload images
@@ -77,5 +77,24 @@ describe Wizardry::Base do
77
77
  @product.current_step = :middle
78
78
  assert_equal @product.previous_step, 'initial'
79
79
  end
80
+
81
+ it 'must return translated name of step' do
82
+ assert_equal @product.step_title(:middle), 'Upload images'
83
+ end
84
+
85
+ it 'must return translated name of current step if no step passed' do
86
+ assert_equal @product.step_title, 'Product details'
87
+ @product.current_step = :middle
88
+ assert_equal @product.step_title, 'Upload images'
89
+ end
90
+
91
+ it 'must fall back to default name of step' do
92
+ assert_equal @product.step_title(:final), 'Final'
93
+ assert_equal @product.step_title('final'), 'Final'
94
+ end
95
+
96
+ it 'must return `nil` for nonexistent step name' do
97
+ assert_nil @product.step_title(:fictional)
98
+ end
80
99
  end
81
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wizardry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-13 00:00:00.000000000 Z
12
+ date: 2012-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  segments:
130
130
  - 0
131
- hash: -4094284250890369797
131
+ hash: -1406875781771055287
132
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  none: false
134
134
  requirements:
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  segments:
139
139
  - 0
140
- hash: -4094284250890369797
140
+ hash: -1406875781771055287
141
141
  requirements: []
142
142
  rubyforge_project:
143
143
  rubygems_version: 1.8.24