navigation_builder 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +29 -0
- data/LICENSE.txt +20 -0
- data/README.md +11 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/action_view/helpers/navigation_builder.rb +126 -0
- data/lib/navigation_builder.rb +9 -0
- data/navigation_builder.gemspec +57 -0
- data/test/helper.rb +25 -0
- data/test/test_navigation_builder.rb +214 -0
- metadata +128 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem "jeweler", "~> 1.6.0"
|
5
|
+
gem "bundler", "~> 1.0.0"
|
6
|
+
gem "rcov", ">= 0"
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'redgreen', '~> 1.2.2'
|
11
|
+
gem "shoulda", "~> 2.11.3"
|
12
|
+
gem 'activesupport', '~> 2.3.11'
|
13
|
+
gem 'actionpack', '~> 2.3.11'
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionpack (2.3.11)
|
5
|
+
activesupport (= 2.3.11)
|
6
|
+
rack (~> 1.1.0)
|
7
|
+
activesupport (2.3.11)
|
8
|
+
git (1.2.5)
|
9
|
+
jeweler (1.6.0)
|
10
|
+
bundler (~> 1.0.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
rack (1.1.2)
|
14
|
+
rake (0.9.0)
|
15
|
+
rcov (0.9.9)
|
16
|
+
redgreen (1.2.2)
|
17
|
+
shoulda (2.11.3)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
actionpack (~> 2.3.11)
|
24
|
+
activesupport (~> 2.3.11)
|
25
|
+
bundler (~> 1.0.0)
|
26
|
+
jeweler (~> 1.6.0)
|
27
|
+
rcov
|
28
|
+
redgreen (~> 1.2.2)
|
29
|
+
shoulda (~> 2.11.3)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 CustomInk, LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "navigation_builder"
|
18
|
+
gem.homepage = "http://github.com/customink/navigation_builder"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Just like a Rails FormBuilder, but for Navigation}
|
21
|
+
gem.description = %Q{NavigationBuilder makes creating navigational links in a Rails application a breeze.}
|
22
|
+
gem.email = "dlindahl@customink.com"
|
23
|
+
gem.authors = ["Derek Lindahl"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "navigation_builder #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0.beta1
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
module NavigationBuilderHelper
|
5
|
+
|
6
|
+
def navigation_builder
|
7
|
+
@navigation_builder ||= { :main => nil }
|
8
|
+
end
|
9
|
+
|
10
|
+
# <% navigation_for :popup do |n| %>
|
11
|
+
# <%= nav_to 'Design', :action => :design %>
|
12
|
+
# <% end %>
|
13
|
+
#
|
14
|
+
# <%= navigation_select 'Design', :in => :popup %>
|
15
|
+
def navigation_for( nav_name, options = {}, &block )
|
16
|
+
raise ArgumentError, "Missing block" unless block_given?
|
17
|
+
|
18
|
+
builder = options[:builder] || ActionView::Base.default_navigation_builder
|
19
|
+
|
20
|
+
options.reverse_merge!(
|
21
|
+
:wrapper_tag => :ul,
|
22
|
+
:nav_item_tag => :li,
|
23
|
+
:selected_class => 'selected',
|
24
|
+
:html => {}
|
25
|
+
)
|
26
|
+
|
27
|
+
concat( tag(options[:wrapper_tag], options[:html], true) ) if navigation_has_wrapper?( options )
|
28
|
+
yield builder.new(self, nav_name, options, block)
|
29
|
+
concat("</#{options[:wrapper_tag]}>".html_safe) if navigation_has_wrapper?( options )
|
30
|
+
end
|
31
|
+
|
32
|
+
def navigation_select( link_name, options = {} )
|
33
|
+
options.reverse_merge!( :in => :main )
|
34
|
+
navigation_builder[options[:in]] = link_name
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def navigation_has_wrapper?( options )
|
40
|
+
options[:wrapper_tag] and options[:nav_item_tag].to_s == 'li'
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
class NavigationBuilder
|
46
|
+
|
47
|
+
def initialize( template, nav_name, options, proc )
|
48
|
+
@template, @nav_name, @options, @proc = template, nav_name, options, proc
|
49
|
+
end
|
50
|
+
|
51
|
+
def link_to( *args, &link_block )
|
52
|
+
if block_given?
|
53
|
+
name = @template.capture(&link_block)
|
54
|
+
options = args.first || {}
|
55
|
+
html_options = args.second
|
56
|
+
|
57
|
+
link_to_in_block( name, options, html_options, &link_block )
|
58
|
+
else
|
59
|
+
name = args[0]
|
60
|
+
options = args[1] || {}
|
61
|
+
html_options = args[2]
|
62
|
+
|
63
|
+
link_to_in_html( name, options, html_options )
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def link_to_in_block( name, options, html_options, &link_block )
|
70
|
+
item_html_options = extract_item_options!( html_options )
|
71
|
+
|
72
|
+
set_selected_link( name, item_html_options ) if is_selected?( name )
|
73
|
+
|
74
|
+
@template.concat( @template.tag( @options[:nav_item_tag], item_html_options, true) ) if @options[:nav_item_tag]
|
75
|
+
@template.link_to(options, html_options, &link_block)
|
76
|
+
@template.concat( "</#{@options[:nav_item_tag]}>".html_safe ) if @options[:nav_item_tag]
|
77
|
+
end
|
78
|
+
|
79
|
+
def link_to_in_html( name, options, html_options )
|
80
|
+
item_html_options = extract_item_options!( html_options )
|
81
|
+
|
82
|
+
set_selected_link( name, item_html_options ) if is_selected?( name )
|
83
|
+
|
84
|
+
link_html = @template.link_to(name, options, html_options)
|
85
|
+
|
86
|
+
if @options[:nav_item_tag]
|
87
|
+
@template.content_tag(@options[:nav_item_tag], link_html, item_html_options )
|
88
|
+
else
|
89
|
+
link_html
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def extract_item_options!( options )
|
94
|
+
options.try(:delete, :item_html) || {}
|
95
|
+
end
|
96
|
+
|
97
|
+
def set_selected_link( name, item_html_options )
|
98
|
+
((item_html_options[:class] ||= '') << " #{@options[:selected_class]}").strip!
|
99
|
+
end
|
100
|
+
|
101
|
+
def is_selected?( name )
|
102
|
+
if @template.navigation_builder[@nav_name].is_a? String
|
103
|
+
name == @template.navigation_builder[@nav_name]
|
104
|
+
else
|
105
|
+
name =~ @template.navigation_builder[@nav_name]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
class Base
|
114
|
+
cattr_accessor :default_navigation_builder
|
115
|
+
self.default_navigation_builder = ::ActionView::Helpers::NavigationBuilder
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
# For Rails 3?
|
121
|
+
# ActiveSupport.on_load(:action_view) do
|
122
|
+
# class ActionView::Base
|
123
|
+
# cattr_accessor :default_navigation_builder
|
124
|
+
# @@default_navigation_builder = ::ActionView::Helpers::NavigationBuilder
|
125
|
+
# end
|
126
|
+
# end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{navigation_builder}
|
8
|
+
s.version = "1.0.0.beta1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Derek Lindahl"]
|
12
|
+
s.date = %q{2011-05-23}
|
13
|
+
s.description = %q{NavigationBuilder makes creating navigational links in a Rails application a breeze.}
|
14
|
+
s.email = %q{dlindahl@customink.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/action_view/helpers/navigation_builder.rb",
|
28
|
+
"lib/navigation_builder.rb",
|
29
|
+
"navigation_builder.gemspec",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_navigation_builder.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/customink/navigation_builder}
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.4.0}
|
37
|
+
s.summary = %q{Just like a Rails FormBuilder, but for Navigation}
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
44
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
45
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
48
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
53
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :test)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'test/unit'
|
12
|
+
require 'redgreen'
|
13
|
+
require 'shoulda'
|
14
|
+
|
15
|
+
# require 'active_support/deprecation' # For Rails 3
|
16
|
+
require 'action_pack'
|
17
|
+
require 'action_view'
|
18
|
+
require 'action_controller' # For Rails 2
|
19
|
+
|
20
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
21
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
22
|
+
require 'navigation_builder'
|
23
|
+
|
24
|
+
class Test::Unit::TestCase
|
25
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
require 'action_view'
|
4
|
+
require 'action_view/template'
|
5
|
+
require 'action_view/test_case'
|
6
|
+
|
7
|
+
class TestNavigationBuilder < ActionView::TestCase
|
8
|
+
|
9
|
+
tests ActionView::Helpers::NavigationBuilderHelper
|
10
|
+
|
11
|
+
should "set the default NavigationBuilder" do
|
12
|
+
assert_equal ActionView::Helpers::NavigationBuilder, ActionView::Base.default_navigation_builder
|
13
|
+
end
|
14
|
+
|
15
|
+
should "generate HTML that contains navigation" do
|
16
|
+
navigation_for :main do |nav|
|
17
|
+
concat nav.link_to( 'Foo', '#' )
|
18
|
+
end
|
19
|
+
|
20
|
+
expected = [
|
21
|
+
"<ul>",
|
22
|
+
"<li>",
|
23
|
+
"<a href=\"#\">Foo</a>",
|
24
|
+
"</li>",
|
25
|
+
"</ul>"
|
26
|
+
].join('')
|
27
|
+
|
28
|
+
assert_dom_equal expected, output_buffer
|
29
|
+
end
|
30
|
+
|
31
|
+
should "generate HTML with custom wrapper tag name" do
|
32
|
+
navigation_for :main, :wrapper_tag => :ol do |nav|
|
33
|
+
concat nav.link_to( 'Foo', '#' )
|
34
|
+
end
|
35
|
+
|
36
|
+
expected = [
|
37
|
+
"<ol>",
|
38
|
+
"<li>",
|
39
|
+
"<a href=\"#\">Foo</a>",
|
40
|
+
"</li>",
|
41
|
+
"</ol>"
|
42
|
+
].join('')
|
43
|
+
|
44
|
+
assert_dom_equal expected, output_buffer
|
45
|
+
end
|
46
|
+
|
47
|
+
should "generate HTML with no wrapper" do
|
48
|
+
navigation_for :main, :wrapper_tag => false do |nav|
|
49
|
+
concat nav.link_to( 'Foo', '#' )
|
50
|
+
end
|
51
|
+
|
52
|
+
expected = [
|
53
|
+
"<li>",
|
54
|
+
"<a href=\"#\">Foo</a>",
|
55
|
+
"</li>"
|
56
|
+
].join('')
|
57
|
+
|
58
|
+
assert_dom_equal expected, output_buffer
|
59
|
+
end
|
60
|
+
|
61
|
+
should "generate HTML with no wrapper and a custom nav item tag name" do
|
62
|
+
navigation_for :main, :nav_item_tag => 'div' do |nav|
|
63
|
+
concat nav.link_to( 'Foo', '#' )
|
64
|
+
end
|
65
|
+
|
66
|
+
expected = [
|
67
|
+
"<div>",
|
68
|
+
"<a href=\"#\">Foo</a>",
|
69
|
+
"</div>"
|
70
|
+
].join('')
|
71
|
+
|
72
|
+
assert_dom_equal expected, output_buffer
|
73
|
+
end
|
74
|
+
|
75
|
+
should "generate HTML with no wrapper and a no nav item tag" do
|
76
|
+
navigation_for :main, :nav_item_tag => false do |nav|
|
77
|
+
concat nav.link_to( 'Foo', '#' )
|
78
|
+
end
|
79
|
+
|
80
|
+
expected = [
|
81
|
+
"<a href=\"#\">Foo</a>"
|
82
|
+
].join('')
|
83
|
+
|
84
|
+
assert_dom_equal expected, output_buffer
|
85
|
+
end
|
86
|
+
|
87
|
+
should "generate HTML that contains user-defined attributes" do
|
88
|
+
navigation_for :main, :html => { :class => 'bar', 'data-more' => 'baz' } do |nav|
|
89
|
+
concat nav.link_to( 'Foo', '#' )
|
90
|
+
end
|
91
|
+
|
92
|
+
expected = [
|
93
|
+
"<ul class=\"bar\" data-more=\"baz\">",
|
94
|
+
"<li>",
|
95
|
+
"<a href=\"#\">Foo</a>",
|
96
|
+
"</li>",
|
97
|
+
"</ul>"
|
98
|
+
].join('')
|
99
|
+
|
100
|
+
assert_dom_equal expected, output_buffer
|
101
|
+
end
|
102
|
+
|
103
|
+
should "generate HTML with links that were created with blocks" do
|
104
|
+
# lambda {
|
105
|
+
navigation_for :main do |nav|
|
106
|
+
# concat nav.link_to( '#' ) { "<span>Foo</span>".html_safe } # For Rails 3?
|
107
|
+
nav.link_to( '#' ) { "<span>Foo</span>".html_safe }
|
108
|
+
end
|
109
|
+
# }.call(ActionView::Base.new) # For Rails 3: Scoped call so that the capture call works inside the Builder
|
110
|
+
|
111
|
+
expected = [
|
112
|
+
"<ul>",
|
113
|
+
"<li>",
|
114
|
+
"<a href=\"#\"><span>Foo</span></a>",
|
115
|
+
"</li>",
|
116
|
+
"</ul>"
|
117
|
+
].join('')
|
118
|
+
|
119
|
+
assert_dom_equal expected, output_buffer
|
120
|
+
end
|
121
|
+
|
122
|
+
should "generate HTML with links that contain user-defined classes" do
|
123
|
+
navigation_for :main do |nav|
|
124
|
+
concat nav.link_to( 'Foo', '#', :class => 'bar' )
|
125
|
+
end
|
126
|
+
|
127
|
+
expected = [
|
128
|
+
"<ul>",
|
129
|
+
"<li>",
|
130
|
+
"<a href=\"#\" class=\"bar\">Foo</a>",
|
131
|
+
"</li>",
|
132
|
+
"</ul>"
|
133
|
+
].join('')
|
134
|
+
|
135
|
+
assert_dom_equal expected, output_buffer
|
136
|
+
end
|
137
|
+
|
138
|
+
should "generate HTML with links that contain user-defined classes on the container items" do
|
139
|
+
navigation_for :main do |nav|
|
140
|
+
concat nav.link_to( 'Foo', '#', :item_html => { :class => 'bar' } )
|
141
|
+
end
|
142
|
+
|
143
|
+
expected = [
|
144
|
+
"<ul>",
|
145
|
+
"<li class=\"bar\">",
|
146
|
+
"<a href=\"#\">Foo</a>",
|
147
|
+
"</li>",
|
148
|
+
"</ul>"
|
149
|
+
].join('')
|
150
|
+
|
151
|
+
assert_dom_equal expected, output_buffer
|
152
|
+
end
|
153
|
+
|
154
|
+
should "generate HTML that highlights the currently selected navigation link" do
|
155
|
+
navigation_select 'Foo', :in => :main
|
156
|
+
|
157
|
+
navigation_for :main do |nav|
|
158
|
+
concat nav.link_to( 'Foo', '#' )
|
159
|
+
end
|
160
|
+
|
161
|
+
expected = [
|
162
|
+
"<ul>",
|
163
|
+
"<li class=\"selected\">",
|
164
|
+
"<a href=\"#\">Foo</a>",
|
165
|
+
"</li>",
|
166
|
+
"</ul>"
|
167
|
+
].join('')
|
168
|
+
|
169
|
+
assert_dom_equal expected, output_buffer
|
170
|
+
end
|
171
|
+
|
172
|
+
should "generate HTML that highlights the currently selected navigation link with a custom class name" do
|
173
|
+
navigation_select 'Foo', :in => :main
|
174
|
+
|
175
|
+
navigation_for :main, :selected_class => 'current-page' do |nav|
|
176
|
+
concat nav.link_to( 'Foo', '#' )
|
177
|
+
end
|
178
|
+
|
179
|
+
expected = [
|
180
|
+
"<ul>",
|
181
|
+
"<li class=\"current-page\">",
|
182
|
+
"<a href=\"#\">Foo</a>",
|
183
|
+
"</li>",
|
184
|
+
"</ul>"
|
185
|
+
].join('')
|
186
|
+
|
187
|
+
assert_dom_equal expected, output_buffer
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
# TODO: Add test for "selected" class when there is no item tag
|
192
|
+
|
193
|
+
should "generate HTML that highlights the currently selected navigation link by using a Regular Expression" do
|
194
|
+
navigation_select /Foo/, :in => :main
|
195
|
+
|
196
|
+
# lambda {
|
197
|
+
navigation_for :main do |nav|
|
198
|
+
# concat nav.link_to( '#' ) { "<span>Foo</span>".html_safe } # For Rails 3?
|
199
|
+
nav.link_to( '#' ) { "<span>Foo</span>".html_safe }
|
200
|
+
end
|
201
|
+
# }.call(ActionView::Base.new) # For Rails 3: Scoped call so that the capture call works inside the Builder
|
202
|
+
|
203
|
+
expected = [
|
204
|
+
"<ul>",
|
205
|
+
"<li class=\"selected\">",
|
206
|
+
"<a href=\"#\"><span>Foo</span></a>",
|
207
|
+
"</li>",
|
208
|
+
"</ul>"
|
209
|
+
].join('')
|
210
|
+
|
211
|
+
assert_dom_equal expected, output_buffer
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: navigation_builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 62196353
|
5
|
+
prerelease: 6
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
- beta
|
11
|
+
- 1
|
12
|
+
version: 1.0.0.beta1
|
13
|
+
platform: ruby
|
14
|
+
authors:
|
15
|
+
- Derek Lindahl
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2011-05-23 00:00:00 -04:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 6
|
33
|
+
- 0
|
34
|
+
version: 1.6.0
|
35
|
+
requirement: *id001
|
36
|
+
prerelease: false
|
37
|
+
name: jeweler
|
38
|
+
type: :development
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 0
|
49
|
+
- 0
|
50
|
+
version: 1.0.0
|
51
|
+
requirement: *id002
|
52
|
+
prerelease: false
|
53
|
+
name: bundler
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
requirement: *id003
|
66
|
+
prerelease: false
|
67
|
+
name: rcov
|
68
|
+
type: :development
|
69
|
+
description: NavigationBuilder makes creating navigational links in a Rails application a breeze.
|
70
|
+
email: dlindahl@customink.com
|
71
|
+
executables: []
|
72
|
+
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
files:
|
79
|
+
- .document
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- VERSION
|
86
|
+
- lib/action_view/helpers/navigation_builder.rb
|
87
|
+
- lib/navigation_builder.rb
|
88
|
+
- navigation_builder.gemspec
|
89
|
+
- test/helper.rb
|
90
|
+
- test/test_navigation_builder.rb
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://github.com/customink/navigation_builder
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 25
|
115
|
+
segments:
|
116
|
+
- 1
|
117
|
+
- 3
|
118
|
+
- 1
|
119
|
+
version: 1.3.1
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.4.0
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: Just like a Rails FormBuilder, but for Navigation
|
127
|
+
test_files: []
|
128
|
+
|