navigasmic 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70153f61b5f76bfd27e5b04b8f2b3e71fd484f80
4
+ data.tar.gz: 8ac4854b4efbd94da58792528704e488a0152d86
5
+ SHA512:
6
+ metadata.gz: cf71e215bb4f5b375908c92c54e74daca77b364efcf7237f74065823b1e410f26fb6462036b1415d52638b0997cf99abce1dbcf422f37d2890ae28e4ec8a2d3e
7
+ data.tar.gz: 2e78a8e92bf78900890a1d7aa20758de6ccedc9d9e23bc0aa4a914778cf53616105fa794a557bddffdb59904e360b2c37e6f7a261b0dea0f7a5b868228ee1342
@@ -23,27 +23,26 @@ class Navigasmic::Item
23
23
 
24
24
  def highlights_on?(path, params)
25
25
  return false unless @rules.any?
26
- params = clean_unwanted_keys(params)
27
- @rules.each do |rule|
26
+ params = params.except(*unwanted_keys)
27
+ !!@rules.detect do |rule|
28
28
  case rule
29
29
  when String
30
- return false unless path == rule
30
+ path == rule
31
31
  when Regexp
32
- return false unless path.match(rule)
32
+ path.match(rule)
33
33
  when TrueClass
34
- # no-op
34
+ true
35
35
  when FalseClass
36
- return false
36
+ false
37
37
  when Hash
38
- clean_unwanted_keys(rule).each do |key, value|
39
- value.gsub(/^\//, '') if key == :controller
40
- return false unless value == params[key].to_s
38
+ rule.except(*unwanted_keys).detect do |key, value|
39
+ value = value.gsub(/^\//, '') if key == :controller
40
+ value == params[key].to_s
41
41
  end
42
42
  else
43
43
  raise ArgumentError, 'Highlighting rules should be an array containing any of/or a Boolean, String, Regexp, Hash or Proc'
44
44
  end
45
45
  end
46
- true
47
46
  end
48
47
 
49
48
  private
@@ -58,9 +57,7 @@ class Navigasmic::Item
58
57
  end
59
58
  end
60
59
 
61
- def clean_unwanted_keys(hash)
62
- ignored_keys = [:only_path, :use_route]
63
- hash.dup.delete_if { |key, value| ignored_keys.include?(key) }
60
+ def unwanted_keys
61
+ [:only_path, :use_routes]
64
62
  end
65
-
66
63
  end
@@ -1,3 +1,3 @@
1
1
  module Navigasmic
2
- VERSION = '1.0.5'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -73,6 +73,13 @@ describe Navigasmic::Item do
73
73
  item.highlights_on?('/other_path', {controller: 'bar'}).should be(false)
74
74
  end
75
75
 
76
+ it "highlights on multiple controllers" do
77
+ item = subject.new 'Label', '/foo', true, highlights_on: [{controller: 'foo'}, {controller: 'bar'}]
78
+ item.highlights_on?('/path', {controller: 'foo'}).should be(true)
79
+ item.highlights_on?('/other_path', {controller: 'bar'}).should be(true)
80
+ item.highlights_on?('/other_path_entirely', {controller: 'baz'}).should be(false)
81
+ end
82
+
76
83
  it "handles strings" do
77
84
  item = subject.new 'Label', '/foo', true, highlights_on: '/path'
78
85
  item.highlights_on?('/path', {}).should be(true)
@@ -42,13 +42,14 @@
42
42
  <% end %>
43
43
 
44
44
  <% n.group 'Highlighting under various situations' do %>
45
- <% n.item 'When the highlight param is set', highlights_on: params[:highlight].present? %>
45
+ <% n.item 'When the highlight param is set', highlights_on: [params[:highlight].present?] %>
46
46
  <% n.item 'Always (using an array)', highlights_on: [true, false, false] %>
47
47
  <% n.item 'When the highlight param is set (using a proc)', highlights_on: proc{ params[:highlight].present? } %>
48
48
  <% n.item 'When the highlight param is set (using a proc in an array)', highlights_on: [proc{ params[:highlight].present? }] %>
49
49
  <% n.item 'When on any path beginning with "my_aw" (using regexp)', highlights_on: [/^\/my_aw/] %>
50
- <% n.item 'When on "/my_awesome_blog" (using string)', highlights_on: '/my_awesome_blog' %>
51
- <% n.item 'When on any action in the application controller', highlights_on: {controller: 'application'} %>
50
+ <% n.item 'When on "/my_awesome_blog" (using string)', highlights_on: ['/my_awesome_blog'] %>
51
+ <% n.item 'When on any action in the application controller', highlights_on: [{controller: 'application'}] %>
52
+ <% n.item 'When on any action in the blog/posts or blog/links controller', highlights_on: [{controller: '/blog/posts'}, {controller: 'blog/links'}] %>
52
53
  <% end %>
53
54
 
54
55
  <!-- Examples of disabling items -->
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navigasmic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jeremy Jackson
@@ -77,34 +76,27 @@ files:
77
76
  homepage: http://github.com/jejacks0n/navigasmic
78
77
  licenses:
79
78
  - MIT
79
+ metadata: {}
80
80
  post_install_message:
81
81
  rdoc_options: []
82
82
  require_paths:
83
83
  - lib
84
84
  required_ruby_version: !ruby/object:Gem::Requirement
85
- none: false
86
85
  requirements:
87
- - - ! '>='
86
+ - - '>='
88
87
  - !ruby/object:Gem::Version
89
88
  version: '0'
90
- segments:
91
- - 0
92
- hash: -2345431105268640909
93
89
  required_rubygems_version: !ruby/object:Gem::Requirement
94
- none: false
95
90
  requirements:
96
- - - ! '>='
91
+ - - '>='
97
92
  - !ruby/object:Gem::Version
98
93
  version: '0'
99
- segments:
100
- - 0
101
- hash: -2345431105268640909
102
94
  requirements: []
103
95
  rubyforge_project:
104
- rubygems_version: 1.8.24
96
+ rubygems_version: 2.0.14
105
97
  signing_key:
106
- specification_version: 3
107
- summary: ! 'Navigasmic: Semantic navigation for Rails'
98
+ specification_version: 4
99
+ summary: 'Navigasmic: Semantic navigation for Rails'
108
100
  test_files:
109
101
  - spec/builders/list_builder_spec.rb
110
102
  - spec/builders/map_builder_spec.rb