active_link_to 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,128 @@
1
+ active\_link\_to
2
+ ================
3
+
4
+ Creates a link tag of the given name using a URL created by the set of
5
+ options. Please see documentation for `link_to`, as `active_link_to` is
6
+ basically a wrapper for it. This method accepts an optional :active
7
+ parameter that dictates if the given link will have an extra css class
8
+ attached that marks it as 'active'.
9
+
10
+ ## Install
11
+ ### In Rails 3.*
12
+
13
+ In Gemfile
14
+
15
+ gem 'active_link_to'
16
+
17
+ and run `bundle install`
18
+
19
+ ### In older Rails
20
+
21
+ $ sudo gem install active_link_to
22
+
23
+ Then you probably want to declare it in your environment.rb
24
+
25
+ config.gem 'active_link_to'
26
+
27
+ and freeze it (preferably):
28
+
29
+ $ rake gems:unpack GEM=active_link_to
30
+
31
+ ### Super Simple Example
32
+ Here's a link that will have class attached if it happens to be rendered
33
+ on page with path `/people` or any child of that page like `/people/123`
34
+
35
+ active_link_to 'People', '/people'
36
+ # => <a href="/people" class="active">People</a>
37
+
38
+ This is exactly the same as:
39
+
40
+ active_link_to 'People', '/people', :active => { :when => :self }
41
+ # => <a href="/people" class="active">People</a>
42
+
43
+ ### Options
44
+ Here's available options that can be inserted into `:active` hash
45
+
46
+ * `:when => predefined symbol || Regexp || Array tuple of controller/actions || Boolean` - This controls
47
+ when link is considered to be 'active'
48
+ * `:active_class => 'class_name'` - When link is 'active', css
49
+ class of that link is set to the default 'active'. This parameter
50
+ allows it to be changed
51
+ * `:inactive_class => 'class_name'` - Opposite of the :active_class
52
+ By default it's blank. However you can change it to whatever you want.
53
+ * `:disable_link => Boolean` - When link is active, sometimes you
54
+ want to render span tag instead of the link. This parameter is for that.
55
+
56
+ ### Examples
57
+ Most of the functionality of `active_link_to` depends on the current
58
+ url. Specifically, `request.fullpath` value. We covered the basic example
59
+ already, so let's try something more fun.
60
+
61
+ We want to highlight the link that matches immediate url, and not the children
62
+ nodes as well
63
+
64
+ # For URL: /people/24
65
+ active_link_to 'People', people_path, :active => { :when => :self_only }
66
+ # => <a href="/people">People</a>
67
+
68
+ # For URL: /people
69
+ active_link_to 'People', people_path, :active => { :when => :self_only }
70
+ # => <a href="/people" class="active">People</a>
71
+
72
+ If we need to set link to be active based on some regular expression, we can do
73
+ that as well. Let's try to activate links urls of which begin with 'peop':
74
+
75
+ # For URL: /people/44
76
+ active_link_to 'People', people_path, :active => { :when => /^peop/ }
77
+ # => <a href="/people" class="active">People</a>
78
+
79
+ # For URL: /aliens/9
80
+ active_link_to 'People', people_path, :active => { :when => /^peop/ }
81
+ # => <a href="/people">People</a>
82
+
83
+ What if we need to mark link active for all URLs that match a particular controller,
84
+ or action, or both? Or any number of those at the same time? Sure, why not:
85
+
86
+ # For URL: /people/56/edit
87
+ # For matching multiple controllers and actions:
88
+ active_link_to 'Person Edit', edit_person_path(@person), :active => {
89
+ :when => [['people', 'aliens'], ['show', 'edit']]
90
+ }
91
+
92
+ # for matching all actions under given controllers:
93
+ active_link_to 'Person Edit', edit_person_path(@person), :active => {
94
+ :when => [['people', 'aliens'], []]
95
+ }
96
+
97
+ # for matching all controllers for a particular action
98
+ active_link_to 'Person Edit', edit_person_path(@person), :active => {
99
+ :when => [[], ['edit']]
100
+ }
101
+ # => <a href="/people" class="active">People</a>
102
+
103
+ Sometimes it should be easy as setting a true or false:
104
+
105
+ active_link_to 'People', people_path, :active => { :when => true }
106
+ # => <a href="/people" class="active">People</a>
107
+
108
+ active_link_to 'People', people_path, :active => { :when => false }
109
+ # => <a href="/people">People</a>
110
+
111
+ Lets see what happens when we push some css class modifier parameters
112
+
113
+ # For URL: /people/12
114
+ active_link_to 'People', people_path, :active => { :active_link => 'awesome_selected' }
115
+ # => <a href="/people" class="awesome_selected">People</a>
116
+
117
+ active_link_to 'Aliens', aliens_path, :active => { :inactive_link => 'bummer_inactive' }
118
+ # => <a href="/aliens" class="bummer_inactive">Aliens</a>
119
+
120
+ Some weird people think that link should change to a span if it indicated current page:
121
+
122
+ # For URL: /people
123
+ active_link_to 'People', people_path, :active => { :disable_link => true }
124
+ # => <span class="active">People</span>
125
+
126
+ ### Copyright
127
+
128
+ Copyright (c) 2009 Oleg Khabarov, The Working Group Inc. See LICENSE for details.
data/Rakefile CHANGED
@@ -8,14 +8,8 @@ begin
8
8
  gem.summary = 'Marks currently active links'
9
9
  gem.description = 'Extremely helpful when you need to add some logic that figures out if the link (or more often navigation item) is selected based on the current page or other arbitrary condition'
10
10
  gem.email = "oleg@theworkinggroup.ca"
11
- gem.homepage = "http://github.com/theworkinggroup/active_link_to"
11
+ gem.homepage = "http://github.com/twg/active_link_to"
12
12
  gem.authors = ["Oleg Khabarov"]
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
- gem.rubyforge_project = 'active-link-to'
15
- end
16
-
17
- Jeweler::RubyforgeTasks.new do |rubyforge|
18
- rubyforge.doc_task = "rdoc"
19
13
  end
20
14
 
21
15
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -1,49 +1,45 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active_link_to}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oleg Khabarov"]
12
- s.date = %q{2010-07-01}
12
+ s.date = %q{2011-05-10}
13
13
  s.description = %q{Extremely helpful when you need to add some logic that figures out if the link (or more often navigation item) is selected based on the current page or other arbitrary condition}
14
14
  s.email = %q{oleg@theworkinggroup.ca}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
- ".gitignore",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "active_link_to.gemspec",
26
- "init.rb",
27
- "lib/active_link_to.rb",
28
- "test/active_link_to_test.rb",
29
- "test/test_helper.rb"
20
+ "LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "active_link_to.gemspec",
25
+ "init.rb",
26
+ "lib/active_link_to.rb",
27
+ "test/active_link_to_test.rb",
28
+ "test/test_helper.rb"
30
29
  ]
31
- s.homepage = %q{http://github.com/theworkinggroup/active_link_to}
32
- s.rdoc_options = ["--charset=UTF-8"]
30
+ s.homepage = %q{http://github.com/twg/active_link_to}
33
31
  s.require_paths = ["lib"]
34
- s.rubyforge_project = %q{active-link-to}
35
- s.rubygems_version = %q{1.3.6}
32
+ s.rubygems_version = %q{1.7.2}
36
33
  s.summary = %q{Marks currently active links}
37
34
  s.test_files = [
38
35
  "test/active_link_to_test.rb",
39
- "test/test_helper.rb"
36
+ "test/test_helper.rb"
40
37
  ]
41
38
 
42
39
  if s.respond_to? :specification_version then
43
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
40
  s.specification_version = 3
45
41
 
46
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
43
  else
48
44
  end
49
45
  else
@@ -142,7 +142,7 @@ module ActiveLinkTo
142
142
  def is_active_link?(url, options = {})
143
143
  case options[:when]
144
144
  when :self, nil
145
- !request.fullpath.match(/^#{Regexp.escape(url)}(\/?.*)?$/).blank?
145
+ !request.fullpath.match(/^#{Regexp.escape(url)}(\/.*|\?.*)?$/).blank?
146
146
  when :self_only
147
147
  !request.fullpath.match(/^#{Regexp.escape(url)}\/?(\?.*)?$/).blank?
148
148
  when Regexp
@@ -12,10 +12,19 @@ class ActiveLinkToTest < Test::Unit::TestCase
12
12
  assert_equal '<a href="/not-test">name</a>', out
13
13
  end
14
14
 
15
+ def test_matching_self_with_similar_url
16
+ request.fullpath = '/test/19'
17
+ out = active_link_to 'name', '/test/1'
18
+ assert_equal '<a href="/test/1">name</a>', out
19
+ end
20
+
15
21
  def test_matching_self_with_extra_parameters
16
22
  request.fullpath = '/test?status=what'
17
23
  out = active_link_to 'name', '/test'
18
24
  assert_equal '<a href="/test" class="active">name</a>', out
25
+ request.fullpath = '/test/?status=what'
26
+ out = active_link_to 'name', '/test'
27
+ assert_equal '<a href="/test" class="active">name</a>', out
19
28
  end
20
29
 
21
30
  def test_matching_self_only
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_link_to
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 6
9
- version: 0.0.6
4
+ prerelease:
5
+ version: 0.0.7
10
6
  platform: ruby
11
7
  authors:
12
8
  - Oleg Khabarov
@@ -14,8 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-07-01 00:00:00 -04:00
18
- default_executable:
13
+ date: 2011-05-10 00:00:00 Z
19
14
  dependencies: []
20
15
 
21
16
  description: Extremely helpful when you need to add some logic that figures out if the link (or more often navigation item) is selected based on the current page or other arbitrary condition
@@ -26,11 +21,10 @@ extensions: []
26
21
 
27
22
  extra_rdoc_files:
28
23
  - LICENSE
29
- - README.rdoc
24
+ - README.md
30
25
  files:
31
- - .gitignore
32
26
  - LICENSE
33
- - README.rdoc
27
+ - README.md
34
28
  - Rakefile
35
29
  - VERSION
36
30
  - active_link_to.gemspec
@@ -38,33 +32,30 @@ files:
38
32
  - lib/active_link_to.rb
39
33
  - test/active_link_to_test.rb
40
34
  - test/test_helper.rb
41
- has_rdoc: true
42
- homepage: http://github.com/theworkinggroup/active_link_to
35
+ homepage: http://github.com/twg/active_link_to
43
36
  licenses: []
44
37
 
45
38
  post_install_message:
46
- rdoc_options:
47
- - --charset=UTF-8
39
+ rdoc_options: []
40
+
48
41
  require_paths:
49
42
  - lib
50
43
  required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
51
45
  requirements:
52
46
  - - ">="
53
47
  - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
48
  version: "0"
57
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
58
51
  requirements:
59
52
  - - ">="
60
53
  - !ruby/object:Gem::Version
61
- segments:
62
- - 0
63
54
  version: "0"
64
55
  requirements: []
65
56
 
66
- rubyforge_project: active-link-to
67
- rubygems_version: 1.3.6
57
+ rubyforge_project:
58
+ rubygems_version: 1.7.2
68
59
  signing_key:
69
60
  specification_version: 3
70
61
  summary: Marks currently active links
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg
data/README.rdoc DELETED
@@ -1,117 +0,0 @@
1
- = active_link_to
2
-
3
- Creates a link tag of the given +name+ using a URL created by the set of
4
- options. Please see documentation for link_to, as active_link_to is
5
- basically a wrapper for it. This method accepts an optional :active
6
- parameter that dictates if the given link will have an extra css class
7
- attached that marks it as 'active'.
8
-
9
- === Install
10
-
11
- $ sudo gem install active_link_to
12
-
13
- Then you probably want to declare it in your environment.rb
14
-
15
- config.gem 'active_link_to'
16
-
17
- and freeze it (preferably):
18
-
19
- $ rake gems:unpack GEM=active_link_to
20
-
21
- === Super Simple Example
22
- Here's a link that will have class attached if it happens to be rendered
23
- on page with path /people or any child of that page like /people/123
24
-
25
- active_link_to 'People', '/people'
26
- # => <a href="/people" class="active">People</a>
27
-
28
- This is exactly the same as:
29
-
30
- active_link_to 'People', '/people', :active => { :when => :self }
31
- # => <a href="/people" class="active">People</a>
32
-
33
- === Options
34
- Here's available options that can be inserted into :active hash
35
- * <tt>:when => predefined symbol || Regexp || Array tuple of controller/actions || Boolean</tt> - This controls
36
- when link is considered to be 'active'
37
- * <tt>:active_class => 'class_name'</tt> - When link is 'active', css
38
- class of that link is set to the default 'active'. This parameter
39
- allows it to be changed
40
- * <tt>:inactive_class => 'class_name'</tt> - Opposite of the :active_class
41
- By default it's blank. However you can change it to whatever you want.
42
- * <tt>:disable_link => Boolean</tt> - When link is active, sometimes you
43
- want to render span tag instead of the link. This parameter is for that.
44
-
45
- === Examples
46
- Most of the functionality of active_link_helper depends on the current
47
- url. Specifically, request.request_uri value. We covered the basic example
48
- already, so let's try sometihng more fun
49
-
50
- We want to highlight the link that matches immidiate url, and not the children
51
- nodes as well
52
-
53
- # For URL: /people/24
54
- active_link_to 'People', people_path, :active => { :when => :self_only }
55
- # => <a href="/people">People</a>
56
-
57
- # For URL: /people
58
- active_link_to 'People', people_path, :active => { :when => :self_only }
59
- # => <a href="/people" class="active">People</a>
60
-
61
- If we need to set link to be active based on some regular expression, we can do
62
- that as well. Let's try to activate links urls of which begin with 'peop':
63
-
64
- # For URL: /people/44
65
- active_link_to 'People', people_path, :active => { :when => /^peop/ }
66
- # => <a href="/people" class="active">People</a>
67
-
68
- # For URL: /aliens/9
69
- active_link_to 'People', people_path, :active => { :when => /^peop/ }
70
- # => <a href="/people">People</a>
71
-
72
- What if we need to mark link active for all URLs that match a particular controller,
73
- or action, or both? Or any number of those at the same time? Sure, why not:
74
-
75
- # For URL: /people/56/edit
76
- # For matching multiple controllers and actions:
77
- active_link_to 'Person Edit', edit_person_path(@person), :active => {
78
- :when => [['people', 'aliens'], ['show', 'edit']]
79
- }
80
-
81
- # for matching all actions under given controllers:
82
- active_link_to 'Person Edit', edit_person_path(@person), :active => {
83
- :when => [['people', 'aliens'], []]
84
- }
85
-
86
- # for matching all controllers for a particular action
87
- active_link_to 'Person Edit', edit_person_path(@person), :active => {
88
- :when => [[], ['edit']]
89
- }
90
- # => <a href="/people" class="active">People</a>
91
-
92
- Sometimes it should be easy as setting a true or false:
93
-
94
- active_link_to 'People', people_path, :active => { :when => true }
95
- # => <a href="/people" class="active">People</a>
96
-
97
- active_link_to 'People', people_path, :active => { :when => false }
98
- # => <a href="/people">People</a>
99
-
100
- Lets see what happens when we push some css class modifier parameters
101
-
102
- # For URL: /people/12
103
- active_link_to 'People', people_path, :active => { :active_link => 'awesome_selected' }
104
- # => <a href="/people" class="awesome_selected">People</a>
105
-
106
- active_link_to 'Aliens', aliens_path, :active => { :inactive_link => 'bummer_inactive' }
107
- # => <a href="/aliens" class="bummer_inactive">Aliens</a>
108
-
109
- Some wierd people think that link should change to a span if it indicated current page:
110
-
111
- # For URL: /people
112
- active_link_to 'People', people_path, :active => { :disable_link => true }
113
- # => <span class="active">People</span>
114
-
115
- == Copyright
116
-
117
- Copyright (c) 2009 Oleg Khabarov, The Working Group Inc. See LICENSE for details.