helmsman 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +6 -6
- data/lib/helmsman/version.rb +1 -1
- data/lib/helmsman/view_helper.rb +30 -7
- data/spec/lib/helmsman/view_helper_spec.rb +29 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ca11064fdfec0f066477aa210a1a911cc1d9a6e
|
4
|
+
data.tar.gz: 6b6bd3981fc0454aac7028905abbfcadd2b23924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e613a1a3378e25f4902a1040ad32366e1090273efc12dd83fc40d87a0b33588260389e67f64939765dbdbd084c3dc109083ac982421804b4ef6b29a40148096
|
7
|
+
data.tar.gz: 13b4562b71d09d2fe379d204dc319b95a3b1fe6ae97e9d1bf3e093982d9ae244bc5373a2bc27861debea0043251d357ba37638175a77ea54c87bb394c93e02df
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Helmsman
|
2
2
|
|
3
|
-
[](https://travis-ci.org/xijo/helmsman) [](http://badge.fury.io/rb/helmsman)
|
3
|
+
[](https://travis-ci.org/xijo/helmsman) [](http://badge.fury.io/rb/helmsman)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -70,13 +70,13 @@ Helmsman will highlight the current entry by using the controller and action nam
|
|
70
70
|
|
71
71
|
Per default the first parameter will be treated as the controller name: `helm :pictures, url: pictures_url` highlights on every controller action of the pictures_controller.
|
72
72
|
|
73
|
-
You may customize the highlight options by providing a set of controller and/or action names. Here are some examples:
|
73
|
+
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
74
|
|
75
75
|
```ruby
|
76
|
-
helm :bridge,
|
77
|
-
helm :bridge,
|
78
|
-
helm :bridge,
|
79
|
-
helm :bridge,
|
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
|
80
80
|
```
|
81
81
|
|
82
82
|
Anyway you are not forced to use that mechanism, you can also set `current` by hand:
|
data/lib/helmsman/version.rb
CHANGED
data/lib/helmsman/view_helper.rb
CHANGED
@@ -12,6 +12,29 @@ module Helmsman
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
# Indicates if for the given conditions the helm should be highlighted.
|
16
|
+
# Examples:
|
17
|
+
# Given we are in pictures controller and action index
|
18
|
+
# highlight_helm?(:pictures) # true
|
19
|
+
# highlight_helm?(:foobar) # false
|
20
|
+
# highlight_helm?(pictures: :index) # true
|
21
|
+
# highlight_helm?(pictures: [:index, :show]) # true
|
22
|
+
# highlight_helm?(pictures: [:index, :show], :foobar) # true
|
23
|
+
def highlight_helm?(conditions)
|
24
|
+
Array(conditions).any? do |condition|
|
25
|
+
case condition
|
26
|
+
when Symbol, String
|
27
|
+
condition.to_s == controller_name
|
28
|
+
when Array
|
29
|
+
if condition.first.to_s == controller_name
|
30
|
+
Array(condition.last).any? { |given| given.to_s == action_name }
|
31
|
+
end
|
32
|
+
else
|
33
|
+
raise TypeError, "invalid format for highlight options, expected Symbol, Array or Hash got #{conditions.class.name}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
15
38
|
# Private part of actionpack/lib/action_view/helpers/translation_helper.rb
|
16
39
|
# Wrapped for clarification what that does.
|
17
40
|
def expand_i18n_key(key)
|
@@ -19,13 +42,13 @@ module Helmsman
|
|
19
42
|
end
|
20
43
|
|
21
44
|
def helm(key, options = {}, &block)
|
22
|
-
actions
|
23
|
-
|
24
|
-
disabled
|
25
|
-
current
|
26
|
-
visible
|
27
|
-
url
|
28
|
-
i18n_key
|
45
|
+
actions = options.fetch(:actions) { [] }
|
46
|
+
highlight_opts = options.fetch(:highlight) { key }
|
47
|
+
disabled = options.fetch(:disabled) { false }
|
48
|
+
current = options.fetch(:current) { highlight_helm?(highlight_opts) }
|
49
|
+
visible = options.fetch(:visible) { true }
|
50
|
+
url = options[:url]
|
51
|
+
i18n_key = expand_i18n_key(".#{key}")
|
29
52
|
|
30
53
|
entry = Helm.new(disabled: disabled, current: current, visible: visible, i18n_key: i18n_key, url: url)
|
31
54
|
|
@@ -36,9 +36,9 @@ describe Helmsman::ViewHelper do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'highlights by action name as well' do
|
39
|
-
result = helper.helm(:pictures,
|
39
|
+
result = helper.helm(:pictures, highlight: { pictures: :show })
|
40
40
|
result.should_not be_current
|
41
|
-
result = helper.helm(:pictures,
|
41
|
+
result = helper.helm(:pictures, highlight: { pictures: :index })
|
42
42
|
result.should be_current
|
43
43
|
end
|
44
44
|
|
@@ -80,5 +80,32 @@ describe Helmsman::ViewHelper do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
describe '#highlight_helm?' do
|
85
|
+
it 'highlights for a given controller' do
|
86
|
+
helper.highlight_helm?(:pictures).should be_true
|
87
|
+
helper.highlight_helm?(:romulans).should be_false
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'accepts multiple controllers as highlight options' do
|
91
|
+
helper.highlight_helm?([:pictures, :romulans]).should be_true
|
92
|
+
helper.highlight_helm?([:borg, :romulans]).should be_false
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'takes a flat conditions hash and treats it correctly' do
|
96
|
+
helper.highlight_helm?(pictures: :index).should be_true
|
97
|
+
helper.highlight_helm?(romulans: :attack).should be_false
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'can highlight on multiple action names' do
|
101
|
+
helper.highlight_helm?(pictures: [:show, :index]).should be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'raises an type error for something unknown' do
|
105
|
+
expect {
|
106
|
+
helper.highlight_helm?(3)
|
107
|
+
}.to raise_error(TypeError)
|
108
|
+
end
|
109
|
+
end
|
83
110
|
end
|
84
111
|
end
|