helmsman 0.0.7 → 0.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d3ab528da63035fe88a5e681ff8f5b784673dde
4
- data.tar.gz: 6c13eb1db5464e344582dcbeeefd9ab81375c011
3
+ metadata.gz: e267300084ce4f8e33e158fa766cca8bba95aa84
4
+ data.tar.gz: dbb9e507ec5b46d6b66c4b129af9b420924950ff
5
5
  SHA512:
6
- metadata.gz: ee820e7a0284fed73ef31ce96e792ed38c5a5db40ee00085e60ae9bd18d3223133c3b773eb8b11b323b75d6155bc276b4c9319f26e87ef90ba4302fa875e2467
7
- data.tar.gz: d25e5afe9ad7373ec40f919a802ac43b85bc24cce33600de778033c23a7bfe9fa2c6c4ffcbc1ef4bf3044cc91a8c02eff3bc8d588d9d096ec082d216c0de0782
6
+ metadata.gz: 2a7cb10fc14086ee58a315b956ea668ca8e57a93219680dab4dc649e56cb4af09e3fabcb2c4d211f96e3963b2427f1ca80799a198ed4cb1bb2acc3aab2c2931a
7
+ data.tar.gz: b4321b2cb64cccc317653d2d6078bae3cfb37aedbed70388caeae852927d4716849817ae0bdc4d808dedb2d4b9661393bc1c7884cf0701cbad4381db61754869
data/README.md CHANGED
@@ -32,28 +32,28 @@ The above call will produce the following html output
32
32
 
33
33
  There are multiple ways to build the link:
34
34
 
35
- 1. provide the url parameter. The link will then be build by using the translation and that url.
35
+ 1. Provide the url parameter. The link will then be build by using the translation and that url.
36
36
 
37
- ```ruby
38
- helm :pictures, url: 'http://randompictures.com'
39
- ```
37
+ ```ruby
38
+ helm :pictures, url: 'http://randompictures.com'
39
+ ```
40
40
 
41
- 2. set helm values in a block.
41
+ 2. Set helm values in a block. (This works for name and url only.)
42
42
 
43
- ```ruby
44
- helm :pictures do |entry|
45
- entry.name = 'Some pictures'
46
- entry.url = 'http://randompictures.com'
47
- end
48
- ```
43
+ ```ruby
44
+ helm :pictures do |entry|
45
+ entry.name = 'Some pictures'
46
+ entry.url = 'http://randompictures.com'
47
+ end
48
+ ```
49
49
 
50
- 3. build everything manually
50
+ 3. Build everything manually
51
51
 
52
- ```ruby
53
- helm :pictures do |_|
54
- link_to 'Some pictures', 'http://randompictures.com'
55
- end
56
- ```
52
+ ```ruby
53
+ helm :pictures do |_|
54
+ link_to 'Some pictures', 'http://randompictures.com'
55
+ end
56
+ ```
57
57
 
58
58
  ### Translation lookup
59
59
 
@@ -65,6 +65,16 @@ e.g. `helm :edit` called from `app/views/pictures/_menu.html.*` uses the followi
65
65
  - en.pictures.menu.edit_disabled_tooltip
66
66
  - en.pictures.menu.disabled_tooltip
67
67
 
68
+ ### Translation scope
69
+
70
+ To wrap a group of navigation elements into the same translation namespace use the `helm_i18n_scope` method:
71
+
72
+ ```ruby
73
+ helm_i18n_scope 'bridge' do
74
+ helm :sensors # will use 'bridge.sensors' for translation lookup
75
+ end
76
+ ```
77
+
68
78
  ### Highlight current
69
79
 
70
80
  Helmsman will highlight the current entry by using the controller and action name.
data/lib/helmsman/helm.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  module Helmsman
2
2
  class Helm
3
- attr_accessor :name, :url, :additional, :i18n_key, :i18n_scope
3
+ attr_accessor :url, :additional, :i18n_key, :i18n_scope
4
+ attr_writer :name
5
+
4
6
  include ActionView::Helpers::TagHelper
5
7
  include ActionView::Helpers::UrlHelper
6
8
 
@@ -39,7 +41,7 @@ module Helmsman
39
41
  end
40
42
 
41
43
  def name
42
- I18n.translate("#{i18n_scope}#{i18n_key}").html_safe
44
+ @name || I18n.translate("#{i18n_scope}#{i18n_key}").html_safe
43
45
  end
44
46
 
45
47
  def disabled_title
@@ -1,3 +1,3 @@
1
1
  module Helmsman
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -35,10 +35,20 @@ module Helmsman
35
35
  end
36
36
  end
37
37
 
38
+ def helm_i18n_scope(scope, &block)
39
+ @helm_i18n_scope = scope
40
+ yield
41
+ @helm_i18n_scope = nil
42
+ end
43
+
38
44
  # Private part of actionpack/lib/action_view/helpers/translation_helper.rb
39
45
  # Wrapped for clarification what that does.
40
- def expand_i18n_key(key)
41
- scope_key_by_partial(key)
46
+ def helm_expand_i18n_key(key)
47
+ if @helm_i18n_scope
48
+ [@helm_i18n_scope, key].join('.')
49
+ else
50
+ scope_key_by_partial(key)
51
+ end
42
52
  end
43
53
 
44
54
  def helm(key, options = {}, &block)
@@ -48,7 +58,7 @@ module Helmsman
48
58
  current = options.fetch(:current) { highlight_helm?(highlight_opts) }
49
59
  visible = options.fetch(:visible) { true }
50
60
  url = options[:url]
51
- i18n_scope = expand_i18n_key('.')
61
+ i18n_scope = helm_expand_i18n_key('.')
52
62
 
53
63
  entry = Helm.new(disabled: disabled, current: current, visible: visible, i18n_key: key, i18n_scope: i18n_scope, url: url)
54
64
 
@@ -24,5 +24,10 @@ describe Helmsman::Helm do
24
24
  it '#default_disabled_tooltip_translation_key' do
25
25
  helm.default_disabled_tooltip_translation_key.should eq 'helmsman.disabled_tooltip'
26
26
  end
27
+
28
+ it '#name returns the setted name before the i18n fallback' do
29
+ helm.name = 'Foobar'
30
+ helm.name.should eq 'Foobar'
31
+ end
27
32
  end
28
33
  end
@@ -107,5 +107,29 @@ describe Helmsman::ViewHelper do
107
107
  }.to raise_error(TypeError)
108
108
  end
109
109
  end
110
+
111
+ describe '#helm_i18n_scope' do
112
+ it 'raises an error if called without block' do
113
+ expect {
114
+ helper.helm_i18n_scope 'foobar'
115
+ }.to raise_error(LocalJumpError)
116
+ end
117
+
118
+ it 'sets and resets the helm_i18n_scope' do
119
+ helper.instance_variable_get(:@helm_i18n_scope).should be_nil
120
+ helper.helm_i18n_scope 'foobar' do
121
+ helper.instance_variable_get(:@helm_i18n_scope).should eq 'foobar'
122
+ end
123
+ helper.instance_variable_get(:@helm_i18n_scope).should be_nil
124
+ end
125
+
126
+ it 'influences #helm_expand_i18n_key' do
127
+ helper.helm_expand_i18n_key('picard').should eq 'i18n_path'
128
+
129
+ helper.helm_i18n_scope 'captain' do
130
+ helper.helm_expand_i18n_key('picard').should eq 'captain.picard'
131
+ end
132
+ end
133
+ end
110
134
  end
111
135
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helmsman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Opper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-30 00:00:00.000000000 Z
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.0.3
128
+ rubygems_version: 2.1.11
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Steers your navigation through the ocean of your application