nav_link_to 0.0.1 → 0.0.2
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.
- data/lib/nav_link_to.rb +22 -1
- data/lib/nav_link_to/version.rb +1 -1
- data/nav_link_to.gemspec +1 -1
- metadata +2 -2
data/lib/nav_link_to.rb
CHANGED
@@ -6,7 +6,7 @@ module NavLinkTo
|
|
6
6
|
|
7
7
|
p = properties.collect do |k, v|
|
8
8
|
if(k == :class)
|
9
|
-
%(#{k}="#{v}#{ " " if v and
|
9
|
+
%(#{k}="#{v}#{ " " if v and is_active_link? path}#{ "active" if is_active_link? path }" )
|
10
10
|
else
|
11
11
|
%(#{k}="#{v}" )
|
12
12
|
end
|
@@ -15,6 +15,27 @@ module NavLinkTo
|
|
15
15
|
%(<li#{ " #{p}" if p.length > 0}>#{link_to text, path}</li>).html_safe
|
16
16
|
end
|
17
17
|
|
18
|
+
def is_active_link?(url, condition = nil)
|
19
|
+
url = url_for(url).sub(/\?.*/, '') # ignore GET params
|
20
|
+
case condition
|
21
|
+
when :inclusive, nil
|
22
|
+
!request.fullpath.match(/^#{Regexp.escape(url)}(\/.*|\?.*)?$/).blank?
|
23
|
+
when :exclusive
|
24
|
+
!request.fullpath.match(/^#{Regexp.escape(url)}\/?(\?.*)?$/).blank?
|
25
|
+
when Regexp
|
26
|
+
!request.fullpath.match(condition).blank?
|
27
|
+
when Array
|
28
|
+
controllers = [*condition[0]]
|
29
|
+
actions = [*condition[1]]
|
30
|
+
(controllers.blank? || controllers.member?(params[:controller])) &&
|
31
|
+
(actions.blank? || actions.member?(params[:action]))
|
32
|
+
when TrueClass
|
33
|
+
true
|
34
|
+
when FalseClass
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
18
39
|
end
|
19
40
|
|
20
41
|
ActionView::Base.send :include, NavLinkTo
|
data/lib/nav_link_to/version.rb
CHANGED
data/nav_link_to.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["franciscomxs@gmail.com"]
|
7
7
|
gem.description = %q{Create link inside <li> element and gives it a 'active' class if current page}
|
8
8
|
gem.summary = %q{Create a menu link}
|
9
|
-
gem.homepage = "
|
9
|
+
gem.homepage = "https://github.com/franciscomxs/nav_link_to"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nav_link_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,7 +27,7 @@ files:
|
|
27
27
|
- lib/nav_link_to.rb
|
28
28
|
- lib/nav_link_to/version.rb
|
29
29
|
- nav_link_to.gemspec
|
30
|
-
homepage:
|
30
|
+
homepage: https://github.com/franciscomxs/nav_link_to
|
31
31
|
licenses: []
|
32
32
|
post_install_message:
|
33
33
|
rdoc_options: []
|