nav_link_to 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,7 +6,7 @@ Simple <li> creator with css 'active' class if current page.
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'nav_link_to'
9
+ gem "nav_link_to", "~> 0.0.3"
10
10
 
11
11
  And then execute:
12
12
 
@@ -18,13 +18,17 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- nav_link_to 'Home', root_path, class:'myClass'
22
- nav_link_to 'Admin', admin_root_path
21
+ nav_link_to 'Home', root_path
22
+ nav_link_to 'Home', root_path, 'myClass'
23
+ nav_link_to 'Home', root_path, nil, id:'myId'
24
+ # Class is a necessary param if you want to use another attribute after, even if nil
25
+
23
26
 
24
27
  will return
25
28
 
29
+ <li class="active"><a href="/admin">Home</a></li>
26
30
  <li class="active myClass"><a href="/">Home</a></li>
27
- <li><a href="/admin">Admin</a></li>
31
+ <li class="active" id="myId"><a href="/admin">Home</a></li>
28
32
 
29
33
  ## Contributing
30
34
 
@@ -32,4 +36,4 @@ Or install it yourself as:
32
36
  2. Create your feature branch (`git checkout -b my-new-feature`)
33
37
  3. Commit your changes (`git commit -am 'Added some feature'`)
34
38
  4. Push to the branch (`git push origin my-new-feature`)
35
- 5. Create new Pull Request
39
+ 5. Create new Pull Request
data/lib/nav_link_to.rb CHANGED
@@ -2,17 +2,16 @@ require "nav_link_to/version"
2
2
 
3
3
  module NavLinkTo
4
4
 
5
- def nav_link_to(text, path, properties = {})
5
+ def nav_link_to(text, path, css_class=nil, properties = {})
6
6
 
7
7
  p = properties.collect do |k, v|
8
- if(k == :class)
9
- %(#{k}="#{v}#{ " " if v and is_active_link? path}#{ "active" if is_active_link? path }" )
10
- else
11
- %(#{k}="#{v}" )
12
- end
8
+ %( #{k}="#{v}") unless k == :class
13
9
  end.join
14
10
 
15
- %(<li#{ " #{p}" if p.length > 0}>#{link_to text, path}</li>).html_safe
11
+ tag_class = %( class="#{css_class unless css_class.nil? }#{' ' if current_page? path and !css_class.nil?}#{'active' if current_page? path}") if current_page? path or !css_class.nil?
12
+
13
+ %(<li#{tag_class}#{p}>#{link_to text, path}</li>).html_safe
14
+
16
15
  end
17
16
 
18
17
  def is_active_link?(url, condition = nil)
@@ -1,3 +1,3 @@
1
1
  module NavLinkTo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-27 00:00:00.000000000 Z
12
+ date: 2012-09-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Create link inside <li> element and gives it a 'active' class if current
15
15
  page
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  version: '0'
48
48
  requirements: []
49
49
  rubyforge_project:
50
- rubygems_version: 1.8.24
50
+ rubygems_version: 1.8.23
51
51
  signing_key:
52
52
  specification_version: 3
53
53
  summary: Create a menu link