theworkinggroup-active_link_helper 0.0.1

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/README.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ = ActiveLinkHelper
2
+
3
+ A step closer to managing 'currenty selected links'
4
+
5
+
6
+ == Usage
7
+
8
+ 1. active_link('Link', '/some_controller/action', :self_only)
9
+ Will create a link marked as active for that page only:
10
+
11
+ <a class="active" href="/some_controller/action">Link</a>
12
+
13
+ 2. active_link('Link', '/some_controller/action', :self)
14
+ Will create a link marked as active for that page and every sub-page
15
+ so /some_controller/action and /some_controller/action/blah will both be marked active
16
+
17
+ <a class="active" href="/some_controller/action">Link</a>
18
+ <a class="active" href="/some_controller/action/blah">Link</a>
19
+
20
+ 3. active_link('Link', '/some_link', custom_regex)
21
+ Will be marked as active if regex matches current uri
22
+
23
+ 4. active_link 'Label', link_path, 'users' => ['new', 'create']
24
+ Will be marked as active if controller and action from params match provided hash pairs
25
+ Alternatively:
26
+ active_link 'Label', link_path, {
27
+ 'users' => ['new', 'create'],
28
+ 'books' => 'edit',
29
+ 'trees' => ['edit', 'update']
30
+ }
31
+
32
+ 5. active_class('/some_link', :self_only)
33
+ Returns only the string 'active' using the same rules as in active_link
34
+ Usefull when you need to activate other elements.
35
+
36
+ <li class="active">ng of currently active elements
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('active_link_helper', '0.0.1') do |p|
6
+ p.description = "Easily manage currently active links"
7
+ p.url = "http://theworkinggroup.ca"
8
+ p.author = "Oleg Khabarov"
9
+ p.email = "oleg@theworkinggroup.ca"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each{|ext| load ext}
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{active_link_helper}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Oleg Khabarov"]
9
+ s.date = %q{2009-03-18}
10
+ s.description = %q{Easily manage currently active links}
11
+ s.email = %q{oleg@theworkinggroup.ca}
12
+ s.extra_rdoc_files = ["lib/active_link_helper.rb", "README.rdoc"]
13
+ s.files = ["lib/active_link_helper.rb", "Rakefile", "README.rdoc", "Manifest", "active_link_helper.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://theworkinggroup.ca}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Active_link_helper", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{active_link_helper}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Easily manage currently active links}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
@@ -0,0 +1,41 @@
1
+ module ActiveLinkHelper
2
+
3
+ def active_link(label, link, value = nil, options = { })
4
+ options[:class] ||= ''
5
+ options[:class] += active_class(link, value)
6
+ options.delete(:class) if options[:class].empty?
7
+ link_to(content_tag(:span, label), link, options)
8
+ end
9
+
10
+ def is_active_link?(link, value = nil)
11
+ link.gsub!(/^(https?:\/\/).*?\//, '/')
12
+ link = link.to_s.split('?').first.to_s
13
+ case value
14
+ when :self:
15
+ regex = /^#{Regexp.escape(link)}(\/?.*)?/
16
+ when :self_only:
17
+ regex = /^#{Regexp.escape(link)}\/?(\?.*)?$/
18
+ when TrueClass
19
+ return true
20
+ when FalseClass
21
+ return false
22
+ when Hash
23
+ value.each do |controller, actions|
24
+ return true if (controller == params[:controller] && [actions].flatten.member?(params[:action]))
25
+ end
26
+ return false
27
+ end
28
+
29
+ if (regex and request.request_uri.match(regex))
30
+ return true
31
+ else
32
+ return false
33
+ end
34
+ end
35
+
36
+ def active_class(link, value = nil)
37
+ is_active_link?(link, value) ? ' active' : ''
38
+ end
39
+ end
40
+
41
+ ActionView::Base.send :include, ActiveLinkHelper
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: theworkinggroup-active_link_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Oleg Khabarov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Easily manage currently active links
17
+ email: oleg@theworkinggroup.ca
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - lib/active_link_helper.rb
24
+ - README.rdoc
25
+ files:
26
+ - lib/active_link_helper.rb
27
+ - Rakefile
28
+ - README.rdoc
29
+ - Manifest
30
+ - active_link_helper.gemspec
31
+ has_rdoc: true
32
+ homepage: http://theworkinggroup.ca
33
+ post_install_message:
34
+ rdoc_options:
35
+ - --line-numbers
36
+ - --inline-source
37
+ - --title
38
+ - Active_link_helper
39
+ - --main
40
+ - README.rdoc
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "1.2"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project: active_link_helper
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Easily manage currently active links
62
+ test_files: []
63
+