helmsman 0.0.5 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cd0afaa2f3e70cd6119aaad852ccaa0fc8f196f
4
- data.tar.gz: 694f7a96e46ac89ded713cedb864c046e1b44358
3
+ metadata.gz: a6b701adb066d32088971a3e5daa6e1ea70a61cc
4
+ data.tar.gz: 079e0a5d62c8205a7f60cdbbb15573acf7bc5224
5
5
  SHA512:
6
- metadata.gz: 7ea788e7d2f08d2d73cc6d21c7b3bd9d458df3e095148ef8f59e035e9813112c1aa5f4d53f4cb2ad908aad0fcc25c02ea9a49bc54498d24e4647147b2849aa50
7
- data.tar.gz: b799ba1db4cc5dad3ad1acd6e8d4e30c31495b9f3aa1b923eab7e03dae48faf24e324f0b2a033efd2f809a4e93e9ecf52e409d3f500696271c0fd26c0c1d7189
6
+ metadata.gz: 2b8142ba64141f62d0a0163f7b063d92b27e90353cf4942393a1d46ad720c11610ff004ddf7cec7192347805bacfedaa99be945352a1c98676c4a7ea185e8e62
7
+ data.tar.gz: 6b3532ef9ceac4bf2a9d43cd5d863dbb15196ae800b2dd9ddb3a449fa77e186e00a469c55bca013234aa9656de27685a26c32b4b10879170c1cc1438b28ee051
data/README.md CHANGED
@@ -63,6 +63,7 @@ e.g. `helm :edit` called from `app/views/pictures/_menu.html.*` uses the followi
63
63
 
64
64
  - en.pictures.menu.edit
65
65
  - en.pictures.menu.edit_disabled_tooltip
66
+ - en.pictures.menu.disabled_tooltip
66
67
 
67
68
  ### Highlight current
68
69
 
@@ -73,10 +74,10 @@ Per default the first parameter will be treated as the controller name: `helm :p
73
74
  You may customize the highlight options by providing a set of controller and/or action names in the `highlight` options. Here are some examples:
74
75
 
75
76
  ```ruby
76
- helm :bridge, highlight: :screens # on any screens controller action
77
- helm :bridge, highlight: [:screens, :sensors] # on any screens and sensors controller action
78
- helm :bridge, highlight: { screens: :show } # on bridges controller show action
79
- helm :bridge, highlight: :screens, sensors: [:show, :index] # only on screens controller #show and #index
77
+ helm :bridge, highlight: :screens # on any screens controller action
78
+ helm :bridge, highlight: [:screens, :sensors] # on any screens and sensors controller action
79
+ helm :bridge, highlight: { screens: :show } # on bridges controller show action
80
+ helm :bridge, highlight: [:screens, { sensors: [:show, :index] }] # all screens controller actions and sensors controller #show and #index
80
81
  ```
81
82
 
82
83
  Anyway you are not forced to use that mechanism, you can also set `current` by hand:
@@ -87,16 +88,16 @@ helm :bridge, current: true
87
88
 
88
89
  ### Disabling and visibility
89
90
 
90
- To set a helm disabled you may use the `disabled` option. It will then add a tooltip to that entry to explain why it was disabled.
91
+ To set a helm disabled you may use the `disabled` option. It will then add a tooltip to that entry to explain why it was disabled (´.pictures_disabled_tooltip´).
91
92
 
92
93
  ```ruby
93
- admin_sidebar_entry :pictures, url: pictures_url, disabled: user_signed_in?
94
+ helm :pictures, url: pictures_url, disabled: user_signed_in?
94
95
  ```
95
96
 
96
97
  If you want it to not be visible at all set the `visible` option to false.
97
98
 
98
99
  ```ruby
99
- admin_sidebar_entry :pictures, url: pictures_url, visible: user_signed_in?
100
+ helm :pictures, url: pictures_url, visible: user_signed_in?
100
101
  ```
101
102
 
102
103
  ### Additional content and nesting
@@ -114,7 +115,7 @@ You can always use the current helm during that yield, so finding out whether it
114
115
 
115
116
 
116
117
  ```ruby
117
- admin_sidebar_entry :pictures, disabled: true, current: false do |entry|
118
+ helm :pictures, disabled: true, current: false do |entry|
118
119
  puts entry.enabled? # false
119
120
  puts entry.disabled? # true
120
121
  puts entry.visible? # true
data/lib/helmsman/helm.rb CHANGED
@@ -1,15 +1,16 @@
1
1
  module Helmsman
2
2
  class Helm
3
- attr_accessor :name, :url, :additional, :i18n_key
3
+ attr_accessor :name, :url, :additional, :i18n_key, :i18n_scope
4
4
  include ActionView::Helpers::TagHelper
5
5
  include ActionView::Helpers::UrlHelper
6
6
 
7
7
  def initialize(options = {})
8
- @disabled = options.fetch(:disabled) { false }
9
- @visible = options.fetch(:visible) { true }
10
- @current = options.fetch(:current) { false }
11
- @i18n_key = options.fetch(:i18n_key) { 'helmsman.helm.fallback' }
12
- @url = options[:url]
8
+ @disabled = options.fetch(:disabled) { false }
9
+ @visible = options.fetch(:visible) { true }
10
+ @current = options.fetch(:current) { false }
11
+ @i18n_scope = options.fetch(:i18n_scope)
12
+ @i18n_key = options.fetch(:i18n_key)
13
+ @url = options[:url]
13
14
  end
14
15
 
15
16
  def to_s
@@ -38,11 +39,23 @@ module Helmsman
38
39
  end
39
40
 
40
41
  def name
41
- I18n.translate(i18n_key).html_safe
42
+ I18n.translate("#{i18n_scope}#{i18n_key}").html_safe
42
43
  end
43
44
 
44
45
  def disabled_title
45
- I18n.translate("#{i18n_key}_disabled_tooltip").html_safe
46
+ I18n.translate(disabled_tooltip_translation_key, default: default_disabled_tooltip_translation_key).html_safe
47
+ end
48
+
49
+ def name_translation_key
50
+ "#{i18n_scope}#{i18n_key}"
51
+ end
52
+
53
+ def disabled_tooltip_translation_key
54
+ "#{i18n_scope}#{i18n_key}_disabled_tooltip"
55
+ end
56
+
57
+ def default_disabled_tooltip_translation_key
58
+ "#{i18n_scope}disabled_tooltip"
46
59
  end
47
60
 
48
61
  def disabled?
@@ -1,3 +1,3 @@
1
1
  module Helmsman
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -48,9 +48,9 @@ module Helmsman
48
48
  current = options.fetch(:current) { highlight_helm?(highlight_opts) }
49
49
  visible = options.fetch(:visible) { true }
50
50
  url = options[:url]
51
- i18n_key = expand_i18n_key(".#{key}")
51
+ i18n_scope = expand_i18n_key('.')
52
52
 
53
- entry = Helm.new(disabled: disabled, current: current, visible: visible, i18n_key: i18n_key, url: url)
53
+ entry = Helm.new(disabled: disabled, current: current, visible: visible, i18n_key: key, i18n_scope: i18n_scope, url: url)
54
54
 
55
55
  entry.additional = capture(entry, &block) if block_given?
56
56
  entry
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Helmsman::Helm do
4
- let(:helm) { Helmsman::Helm.new }
4
+ let(:helm) { Helmsman::Helm.new(i18n_scope: 'helmsman.', i18n_key: 'foo') }
5
5
 
6
6
  it 'is always html_safe' do
7
7
  helm.should be_html_safe
@@ -13,5 +13,16 @@ describe Helmsman::Helm do
13
13
  helm.disabled_title.should be_html_safe
14
14
  end
15
15
 
16
+ it '#name_translation_key returns the right thing' do
17
+ helm.name_translation_key.should eq 'helmsman.foo'
18
+ end
19
+
20
+ it '#disabled_tooltip_translation_key' do
21
+ helm.disabled_tooltip_translation_key.should eq 'helmsman.foo_disabled_tooltip'
22
+ end
23
+
24
+ it '#default_disabled_tooltip_translation_key' do
25
+ helm.default_disabled_tooltip_translation_key.should eq 'helmsman.disabled_tooltip'
26
+ end
16
27
  end
17
28
  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.5
4
+ version: 0.0.6
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-23 00:00:00.000000000 Z
11
+ date: 2013-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack