helmsman 0.0.9 → 0.1.0

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: 2c4b143c57977a78c91d041062e78e1630382b07
4
- data.tar.gz: cd64f69c0b678199ca4aa8cbf68d1582a4ebd98b
3
+ metadata.gz: 22ea9eb486378b8fdd42100f7a4a0394846eb9c1
4
+ data.tar.gz: 95755650dd2099182189afdd695932049f3b2ef9
5
5
  SHA512:
6
- metadata.gz: 762a534747d8cb1e80f412ead8ca1a5d85a5e9fca44a1690aa1019d1cb125d09cf70e8bec9c4d2d28fb9887b59f0cd63f9fe2cefd485058e7ecdda229f39a08f
7
- data.tar.gz: bdf16c685f4510105d6c24cabde76514941db4dfb6ea850b6dcb5af29bba28864cd00b4e649d96b7b5c9d941106526e172bd7f704839dc14ac0b2ece2cc9877d
6
+ metadata.gz: dc2261720f3961c2b79c19de1de6d7f2d22df3e6d8f5a929937bd26929223aff0d3e796c7a3e0eb8069c3cf4846545c14a897f75dac781f7112c0c3dc60442c9
7
+ data.tar.gz: 9b9ae038b5bfbc3489fcdba587f5b66c7363828a0b5f897c7e09c83b0aea144538e88b32958e3562b50330ba87e6c70130760497aa30c943049e990b851bac7e
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  rvm:
2
- - 2.0.0
3
-
4
- script: "bundle exec rspec"
2
+ - 2.0
3
+ - 2.1
4
+ - 2.2
5
5
 
6
6
  notifications:
7
7
  disabled: false
data/Rakefile CHANGED
@@ -1 +1,17 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ require 'irb'
5
+ require 'irb/completion'
6
+ require 'helmsman'
7
+ ARGV.clear
8
+ IRB.start
9
+ end
10
+
11
+ begin
12
+ require 'rspec/core/rake_task'
13
+ RSpec::Core::RakeTask.new(:spec)
14
+ rescue LoadError
15
+ end
16
+
17
+ task :default => :spec
data/helmsman.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'actionpack'
21
+ spec.add_dependency 'rails'
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.3'
24
24
  spec.add_development_dependency 'rake'
data/lib/helmsman/helm.rb CHANGED
@@ -7,9 +7,10 @@ module Helmsman
7
7
  include ActionView::Helpers::UrlHelper
8
8
 
9
9
  def initialize(options = {})
10
- @disabled = options.fetch(:disabled) { false }
11
- @visible = options.fetch(:visible) { true }
12
- @current = options.fetch(:current) { false }
10
+ @disabled = options.fetch(:disabled) { false }
11
+ @visible = options.fetch(:visible) { true }
12
+ @current = options.fetch(:current) { false }
13
+ @li_class = options[:li_class] || []
13
14
  @i18n_scope = options.fetch(:i18n_scope)
14
15
  @i18n_key = options.fetch(:i18n_key)
15
16
  @url = options[:url]
@@ -32,11 +33,36 @@ module Helmsman
32
33
  disabled? ? link : "#{link}#{additional}".html_safe
33
34
  end
34
35
 
36
+ def configure_li_class
37
+ if @li_class.respond_to?(:to_ary)
38
+ @li_class.to_ary
39
+ else
40
+ @li_class.to_s.split(/\s+/)
41
+ end.tap do |li_class|
42
+ yield li_class
43
+ end.select(&:present?).uniq.sort * ' '
44
+ end
45
+
35
46
  def li_options
36
47
  if enabled?
37
- { class: (Helmsman.current_css_class if current?) }
48
+ li_class = configure_li_class do |li_class|
49
+ if current?
50
+ li_class << Helmsman.current_css_class
51
+ end
52
+ end
53
+ {
54
+ class: li_class
55
+ }
38
56
  else
39
- { rel: 'tooltip', title: disabled_title, class: Helmsman.disabled_css_class, data: { placement: 'bottom' } }
57
+ li_class = configure_li_class do |li_class|
58
+ li_class << Helmsman.disabled_css_class
59
+ end
60
+ {
61
+ rel: 'tooltip',
62
+ title: disabled_title,
63
+ class: li_class,
64
+ data: { placement: 'bottom' }
65
+ }
40
66
  end
41
67
  end
42
68
 
@@ -1,3 +1,3 @@
1
1
  module Helmsman
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -30,7 +30,9 @@ module Helmsman
30
30
  Array(condition.last).any? { |given| given.to_s == action_name }
31
31
  end
32
32
  else
33
- raise TypeError, "invalid format for highlight options, expected Symbol, Array or Hash got #{conditions.class.name}"
33
+ raise TypeError,
34
+ "invalid format for highlight options, "\
35
+ "expected Symbol, Array or Hash got #{conditions.class.name}"
34
36
  end
35
37
  end
36
38
  end
@@ -52,15 +54,25 @@ module Helmsman
52
54
  end
53
55
 
54
56
  def helm(key, options = {}, &block)
55
- actions = options.fetch(:actions) { [] }
56
- highlight_opts = options.fetch(:highlight) { key }
57
- disabled = options.fetch(:disabled) { false }
58
- current = options.fetch(:current) { highlight_helm?(highlight_opts) }
59
- visible = options.fetch(:visible) { true }
57
+ actions = options.fetch(:actions) { [] }
58
+ highlight_opts = options.fetch(:highlight) { key }
59
+ disabled = options.fetch(:disabled) { false }
60
+ current = options.fetch(:current) {
61
+ highlight_helm?(highlight_opts)
62
+ }
63
+ visible = options.fetch(:visible) { true }
60
64
  url = options[:url]
61
65
  i18n_scope = helm_expand_i18n_key('.')
62
66
 
63
- entry = Helm.new(disabled: disabled, current: current, visible: visible, i18n_key: key, i18n_scope: i18n_scope, url: url)
67
+ entry = Helm.new(
68
+ disabled: disabled,
69
+ current: current,
70
+ visible: visible,
71
+ i18n_key: key,
72
+ i18n_scope: i18n_scope,
73
+ url: url,
74
+ li_class: options[:li_class]
75
+ )
64
76
 
65
77
  entry.additional = capture(entry, &block) if block_given?
66
78
  entry
@@ -4,30 +4,67 @@ describe Helmsman::Helm do
4
4
  let(:helm) { Helmsman::Helm.new(i18n_scope: 'helmsman.', i18n_key: 'foo') }
5
5
 
6
6
  it 'is always html_safe' do
7
- helm.should be_html_safe
7
+ expect(helm).to be_html_safe
8
8
  end
9
9
 
10
10
  context 'translations' do
11
11
  it 'treats translations as html safe' do
12
- helm.name.should be_html_safe
13
- helm.disabled_title.should be_html_safe
12
+ expect(helm.name).to be_html_safe
13
+ expect(helm.disabled_title).to be_html_safe
14
14
  end
15
15
 
16
16
  it '#name_translation_key returns the right thing' do
17
- helm.name_translation_key.should eq 'helmsman.foo'
17
+ expect(helm.name_translation_key).to eq 'helmsman.foo'
18
18
  end
19
19
 
20
20
  it '#disabled_tooltip_translation_key' do
21
- helm.disabled_tooltip_translation_key.should eq 'helmsman.foo_disabled_tooltip'
21
+ expect(helm.disabled_tooltip_translation_key).to\
22
+ eq 'helmsman.foo_disabled_tooltip'
22
23
  end
23
24
 
24
25
  it '#default_disabled_tooltip_translation_key' do
25
- helm.default_disabled_tooltip_translation_key.should eq 'helmsman.disabled_tooltip'
26
+ expect(helm.default_disabled_tooltip_translation_key).to\
27
+ eq 'helmsman.disabled_tooltip'
26
28
  end
27
29
 
28
30
  it '#name returns the setted name before the i18n fallback' do
29
31
  helm.name = 'Foobar'
30
- helm.name.should eq 'Foobar'
32
+ expect(helm.name).to eq 'Foobar'
33
+ end
34
+ end
35
+
36
+ context '#li_options' do
37
+ it 'contains li_class if enabled' do
38
+ helm = Helmsman::Helm.new(
39
+ i18n_scope: 'helmsman.',
40
+ i18n_key: 'key',
41
+ li_class: 'foo bar'
42
+ )
43
+ expect(helm.li_options[:class]).to respond_to :to_str
44
+ expect(helm.li_options[:class]).to include 'foo'
45
+ expect(helm.li_options[:class]).to include 'bar'
46
+ end
47
+
48
+ it 'contains li_class if disabled' do
49
+ helm = Helmsman::Helm.new(
50
+ i18n_scope: 'helmsman.',
51
+ i18n_key: 'key',
52
+ li_class: 'bar foo',
53
+ disabled: true
54
+ )
55
+ expect(helm.li_options[:class]).to respond_to :to_str
56
+ expect(helm.li_options[:class]).to include 'foo'
57
+ expect(helm.li_options[:class]).to include 'bar'
58
+ end
59
+
60
+ it 'contains li_class if passed as an array' do
61
+ helm = Helmsman::Helm.new(
62
+ i18n_scope: 'helmsman.',
63
+ i18n_key: 'key',
64
+ li_class: %w[foo bar] << ' ' << nil
65
+ )
66
+ expect(helm.li_options[:class]).to respond_to :to_str
67
+ expect(helm.li_options[:class]).to eq 'bar foo'
31
68
  end
32
69
  end
33
70
  end
@@ -27,78 +27,82 @@ describe Helmsman::ViewHelper do
27
27
  describe '#helm' do
28
28
  it 'highlights per class name on a given controller name' do
29
29
  result = helper.helm(:pictures)
30
- result.should be_current
30
+ expect(result).to be_current
31
31
  end
32
32
 
33
33
  it 'is possible to override the current state' do
34
34
  result = helper.helm(:not_pictures, current: true)
35
- result.should be_current
35
+ expect(result).to be_current
36
36
  end
37
37
 
38
38
  it 'highlights by action name as well' do
39
39
  result = helper.helm(:pictures, highlight: { pictures: :show })
40
- result.should_not be_current
40
+ expect(result).not_to be_current
41
41
  result = helper.helm(:pictures, highlight: { pictures: :index })
42
- result.should be_current
42
+ expect(result).to be_current
43
43
  end
44
44
 
45
45
  it 'passing disabled option disables the link' do
46
46
  result = helper.helm(:pictures, disabled: true)
47
- result.to_s.should_not include '<a href'
48
- result.to_s.should include 'disabled'
47
+ expect(result.to_s).not_to include '<a href'
48
+ expect(result.to_s).to include 'disabled'
49
49
  end
50
50
 
51
51
  it 'adds block results to the result' do
52
52
  result = helper.helm(:pictures) { |entry| 'jambalaia' }
53
- result.to_s.should include 'jambalaia'
53
+ expect(result.to_s).to include 'jambalaia'
54
54
  end
55
55
 
56
56
  it 'generates a link if it got a url' do
57
57
  result = helper.helm(:pictures, url: 'hellofoo.com')
58
- result.to_s.should include '<a href="hellofoo.com">'
58
+ expect(result.to_s).to include '<a href="hellofoo.com">'
59
59
  end
60
60
 
61
61
  it 'generates html_safe output' do
62
62
  result = helper.helm(:pictures)
63
- result.to_s.should be_html_safe
63
+ expect(result.to_s).to be_html_safe
64
64
  end
65
65
 
66
66
  it 'setting visible to false will output nothing' do
67
- result = helper.helm(:pictures, url: 'http://defiant.ncc/pictures', visible: false)
68
- result.to_s.should eq ''
67
+ result = helper.helm(
68
+ :pictures,
69
+ url: 'http://defiant.ncc/pictures',
70
+ visible: false
71
+ )
72
+ expect(result.to_s).to eq ''
69
73
  end
70
74
 
71
75
  describe 'yield the entry' do
72
76
  it 'knows if its the current' do
73
- helper.helm(:foo, current: true) { |e| e.should be_current }
77
+ helper.helm(:foo, current: true) { |e| expect(e).to be_current }
74
78
  end
75
79
 
76
80
  it 'knows if it is disabled' do
77
81
  helper.helm(:foo, disabled: true) do |entry|
78
- entry.should be_disabled
79
- entry.should_not be_enabled
82
+ expect(entry).to be_disabled
83
+ expect(entry).not_to be_enabled
80
84
  end
81
85
  end
82
86
  end
83
87
 
84
88
  describe '#highlight_helm?' do
85
89
  it 'highlights for a given controller' do
86
- helper.highlight_helm?(:pictures).should be_true
87
- helper.highlight_helm?(:romulans).should be_false
90
+ expect(helper.highlight_helm?(:pictures)).to be_truthy
91
+ expect(helper.highlight_helm?(:romulans)).to be_falsey
88
92
  end
89
93
 
90
94
  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
95
+ expect(helper.highlight_helm?([:pictures, :romulans])).to be_truthy
96
+ expect(helper.highlight_helm?([:borg, :romulans])).to be_falsey
93
97
  end
94
98
 
95
99
  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
100
+ expect(helper.highlight_helm?(pictures: :index)).to be_truthy
101
+ expect(helper.highlight_helm?(romulans: :attack)).to be_falsey
98
102
  end
99
103
 
100
104
  it 'can highlight on multiple action names' do
101
- helper.highlight_helm?(pictures: [:show, :index]).should be_true
105
+ expect(helper.highlight_helm?(pictures: [:show, :index])).to be_truthy
102
106
  end
103
107
 
104
108
  it 'raises an type error for something unknown' do
@@ -116,24 +120,28 @@ describe Helmsman::ViewHelper do
116
120
  end
117
121
 
118
122
  it 'sets and resets the helm_i18n_scope' do
119
- helper.instance_variable_get(:@helm_i18n_scope).should be_nil
123
+ expect(helper.instance_variable_get(:@helm_i18n_scope)).to be_nil
120
124
  helper.helm_i18n_scope 'foobar' do
121
- helper.instance_variable_get(:@helm_i18n_scope).should eq 'foobar'
125
+ scope = helper.instance_variable_get(:@helm_i18n_scope)
126
+ expect(scope).to eq 'foobar'
122
127
  end
123
- helper.instance_variable_get(:@helm_i18n_scope).should be_nil
128
+ scope = helper.instance_variable_get(:@helm_i18n_scope)
129
+ expect(scope).to be_nil
124
130
  end
125
131
 
126
132
  it 'influences #helm_expand_i18n_key' do
127
- helper.helm_expand_i18n_key('picard').should eq 'i18n_path'
133
+ expect(helper.helm_expand_i18n_key('picard')).to eq 'i18n_path'
128
134
 
129
135
  helper.helm_i18n_scope 'captain' do
130
- helper.helm_expand_i18n_key('.picard').should eq 'captain.picard'
136
+ key = helper.helm_expand_i18n_key('.picard')
137
+ expect(key).to eq 'captain.picard'
131
138
  end
132
139
  end
133
140
 
134
141
  it 'is used by #helm in the end' do
135
142
  helper.helm_i18n_scope 'captain' do
136
- helper.helm(:picard, url: 'hello-jean-luc.com').to_s.should include 'captain.picard'
143
+ helm = helper.helm(:picard, url: 'hello-jean-luc.com').to_s
144
+ expect(helm).to include 'captain.picard'
137
145
  end
138
146
  end
139
147
  end
@@ -5,12 +5,12 @@ describe Helmsman do
5
5
  after { Helmsman.current_css_class = 'active' }
6
6
 
7
7
  it 'defaults to active' do
8
- Helmsman.current_css_class.should eq 'active'
8
+ expect(Helmsman.current_css_class).to eq 'active'
9
9
  end
10
10
 
11
11
  it 'is settable and gettable' do
12
12
  Helmsman.current_css_class = 'foo'
13
- Helmsman.current_css_class.should eq 'foo'
13
+ expect(Helmsman.current_css_class).to eq 'foo'
14
14
  end
15
15
  end
16
16
 
@@ -18,12 +18,12 @@ describe Helmsman do
18
18
  after { Helmsman.disabled_css_class = 'disabled' }
19
19
 
20
20
  it 'defaults to disabled' do
21
- Helmsman.disabled_css_class.should eq 'disabled'
21
+ expect(Helmsman.disabled_css_class).to eq 'disabled'
22
22
  end
23
23
 
24
24
  it 'is settable and gettable' do
25
25
  Helmsman.disabled_css_class = 'foo'
26
- Helmsman.disabled_css_class.should eq 'foo'
26
+ expect(Helmsman.disabled_css_class).to eq 'foo'
27
27
  end
28
28
  end
29
29
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'simplecov'
2
2
 
3
- SimpleCov.adapters.define 'gem' do
3
+ SimpleCov.profiles.define 'gem' do
4
4
  add_filter '/spec/'
5
5
  add_group 'Libraries', '/lib/'
6
6
  end
@@ -9,5 +9,5 @@ SimpleCov.start 'gem'
9
9
  require 'helmsman'
10
10
 
11
11
  RSpec.configure do |config|
12
- config.color_enabled = true
12
+ config.color = true
13
13
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helmsman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Opper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 00:00:00.000000000 Z
11
+ date: 2015-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: actionpack
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Steers your navigation through the ocean of your application
@@ -87,10 +87,8 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .ruby-gemset
92
- - .ruby-version
93
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".travis.yml"
94
92
  - Gemfile
95
93
  - LICENSE.txt
96
94
  - README.md
@@ -115,17 +113,17 @@ require_paths:
115
113
  - lib
116
114
  required_ruby_version: !ruby/object:Gem::Requirement
117
115
  requirements:
118
- - - '>='
116
+ - - ">="
119
117
  - !ruby/object:Gem::Version
120
118
  version: '0'
121
119
  required_rubygems_version: !ruby/object:Gem::Requirement
122
120
  requirements:
123
- - - '>='
121
+ - - ">="
124
122
  - !ruby/object:Gem::Version
125
123
  version: '0'
126
124
  requirements: []
127
125
  rubyforge_project:
128
- rubygems_version: 2.1.11
126
+ rubygems_version: 2.2.2
129
127
  signing_key:
130
128
  specification_version: 4
131
129
  summary: Steers your navigation through the ocean of your application
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- helmsman
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.0.0