navigasmic 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.textile +203 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/builders/html_builder.rb +62 -0
- data/lib/builders/xml_builder.rb +62 -0
- data/lib/navigasmic.rb +126 -0
- data/navigasmic.gemspec +55 -0
- data/test/navigasmic_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +77 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jeremy Jackson
|
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.textile
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
h1. Navigasmic
|
2
|
+
|
3
|
+
Semantic navigation; a semantic way to build beautifully simple navigation structures in Rails.
|
4
|
+
|
5
|
+
h2. The Story
|
6
|
+
|
7
|
+
Most of the navigation styles I've done over the years pretty much boil down to this idea: Use simple markup, and do the rest with css (and javascript if you need it). So, yeah, the default markup is beautifully simple (UL and LI tags).
|
8
|
+
|
9
|
+
I wanted something that allowed for customization and ended up deciding that Rails forms outline that nicely. With some ideas taken from formtastic, I setup navigasmic to work a lot like how Rails forms work, in that it uses builders. For example, there are two builders that are provided (HTML for ERB, HAML, etc. and XML for ERB, Builder, etc), and these builders can be extended or replaced if you need more custom markup.
|
10
|
+
|
11
|
+
Currently the HTML builder generates UL and LI tags, which helps with SEO, and the XML builder generates tags that can be used for XML site maps.
|
12
|
+
|
13
|
+
h2. Installation
|
14
|
+
|
15
|
+
The gem is hosted on gemcutter, so *if you haven't already*, add it as a gem source:
|
16
|
+
|
17
|
+
<pre>
|
18
|
+
sudo gem sources -a http://gemcutter.org/
|
19
|
+
</pre>
|
20
|
+
|
21
|
+
Then install the navigasmic gem:
|
22
|
+
|
23
|
+
<pre>
|
24
|
+
sudo gem install navigasmic
|
25
|
+
</pre>
|
26
|
+
|
27
|
+
h2. Usage
|
28
|
+
|
29
|
+
h3. HAML
|
30
|
+
|
31
|
+
*Simple Usage*
|
32
|
+
|
33
|
+
<pre>
|
34
|
+
- semantic_navigation :main do |n|
|
35
|
+
= n.group 'Media', :html => {:class => 'media'} do
|
36
|
+
= n.item 'Image Gallery', :link => {:controller => 'media/images'}
|
37
|
+
= n.item 'Videos', :link => {:controller => 'media/videos'}
|
38
|
+
= n.group 'Info' do
|
39
|
+
= n.item 'About Us', :link => '/about_us', :html => {:title => 'we are the coolest'}
|
40
|
+
= n.item 'Nothing Here'
|
41
|
+
</pre>
|
42
|
+
...produces...
|
43
|
+
<pre>
|
44
|
+
<ul id="main" class="semantic-navigation">
|
45
|
+
<li class="media with-group">
|
46
|
+
<span>Media<span>
|
47
|
+
<ul>
|
48
|
+
<li id="image_gallery"><a href="/media/images"><span>Image Gallery</span></a></li>
|
49
|
+
<li id="videos"><a href="/media/videos"><span>Videos</span></a></li>
|
50
|
+
</ul>
|
51
|
+
</li>
|
52
|
+
<li class="with-group">
|
53
|
+
<span>Info<span>
|
54
|
+
<ul>
|
55
|
+
<li id="about_us" title="we are the coolest"><a href="/about_us/"><span>About Us</span></a></li>
|
56
|
+
<li id="videos"><span>Nothing Here</span></li>
|
57
|
+
</ul>
|
58
|
+
</li>
|
59
|
+
</ul>
|
60
|
+
</pre>
|
61
|
+
|
62
|
+
*Nesting of items and additional markup*
|
63
|
+
|
64
|
+
<pre>
|
65
|
+
- semantic_navigation :main, :html => { :class => 'primary' } do |n|
|
66
|
+
= n.group 'Media' do
|
67
|
+
= n.item 'Image Gallery', :link => {:controller => 'media/images', :action => 'index'}
|
68
|
+
= n.item 'Videos', :link => {:controller => 'media/videos'}
|
69
|
+
.secondary
|
70
|
+
= n.group 'Info' do
|
71
|
+
= n.item 'About Us', :link => '/about_us' do
|
72
|
+
%ul
|
73
|
+
= n.item 'Nothing Here'
|
74
|
+
</pre>
|
75
|
+
...produces...
|
76
|
+
<pre>
|
77
|
+
<ul id="main" class="primary semantic-navigation">
|
78
|
+
<li id="media" class="with-group">
|
79
|
+
<span>Media</span>
|
80
|
+
<ul>
|
81
|
+
<li id="image_gallery"><a href="/media/images"><span>Image Gallery</span></a></li>
|
82
|
+
<li id="videos"><a href="/media/videos"><span>Videos</span></a></li>
|
83
|
+
</ul>
|
84
|
+
</li>
|
85
|
+
<div class="secondary">
|
86
|
+
<li id="info" class="with-group">
|
87
|
+
<span>Info</span>
|
88
|
+
<ul>
|
89
|
+
<li id="about_us">
|
90
|
+
<a href="/about_us"><span>About Us</span></a>
|
91
|
+
<ul>
|
92
|
+
<li id="nothing_here"><span>Nothing Here</span></li>
|
93
|
+
</ul>
|
94
|
+
</li>
|
95
|
+
</ul>
|
96
|
+
</li>
|
97
|
+
</div>
|
98
|
+
</ul>
|
99
|
+
</pre>
|
100
|
+
|
101
|
+
*Highlighting* -- highlights on the media controller (or any that inherit from it), on the /images path, and on mondays
|
102
|
+
|
103
|
+
<pre>
|
104
|
+
- semantic_navigation :main do
|
105
|
+
= n.item 'Image Gallery', :link => 'media/images'
|
106
|
+
:highlights_on => [{:controller => 'media'}, '/images', proc { Time.now.wday == 1 }]
|
107
|
+
</pre>
|
108
|
+
...produces
|
109
|
+
<pre>
|
110
|
+
<ul id="main" class="semantic-navigation">
|
111
|
+
<li id="image_gallery" class="highlighted"><a href="/media/images"><span>Image Gallery</span></a></li>
|
112
|
+
</ul>
|
113
|
+
</pre>
|
114
|
+
|
115
|
+
*Disabling* -- disabled on tuesdays, and when not logged in
|
116
|
+
|
117
|
+
<pre>
|
118
|
+
- semantic_navigation :main do
|
119
|
+
= n.item 'Image Gallery', :link => 'media/images'
|
120
|
+
:disabled_if => proc { Time.now.wday == 2 || !logged_in? }
|
121
|
+
</pre>
|
122
|
+
...produces
|
123
|
+
<pre>
|
124
|
+
<ul id="main" class="semantic-navigation">
|
125
|
+
<li id="image_gallery" class="disabled"><span>Image Gallery</span></li>
|
126
|
+
</ul>
|
127
|
+
</pre>
|
128
|
+
|
129
|
+
h3. ERB
|
130
|
+
|
131
|
+
*Nesting of items and additional markup*
|
132
|
+
|
133
|
+
<pre>
|
134
|
+
<% semantic_navigation :main, :html => { :class => 'primary' } do |n| %>
|
135
|
+
<%= n.group 'Media' do %>
|
136
|
+
<%= n.item 'Image Gallery', :link => {:controller => 'media/images', :action => 'index'} %>
|
137
|
+
<%= n.item 'Videos', :link => {:controller => 'media/videos'} %>
|
138
|
+
<% end %>
|
139
|
+
<div class="secondary">
|
140
|
+
<%= n.group 'Info' do %>
|
141
|
+
<%= n.item 'About Us', :link => '/about_us' do %>
|
142
|
+
<ul><%= n.item 'Nothing Here' %></ul>
|
143
|
+
<% end %>
|
144
|
+
<% end %>
|
145
|
+
</div>
|
146
|
+
<% end %>
|
147
|
+
</pre>
|
148
|
+
...produces...
|
149
|
+
<pre>
|
150
|
+
<ul id="main" class="primary semantic-navigation">
|
151
|
+
<li id="media" class="with-group">
|
152
|
+
<span>Media</span>
|
153
|
+
<ul>
|
154
|
+
<li id="image_gallery"><a href="/media/images"><span>Image Gallery</span></a></li>
|
155
|
+
<li id="videos"><a href="/media/videos"><span>Videos</span></a></li>
|
156
|
+
</ul>
|
157
|
+
</li>
|
158
|
+
<div class="secondary">
|
159
|
+
<li id="info" class="with-group">
|
160
|
+
<span>Info</span>
|
161
|
+
<ul>
|
162
|
+
<li id="about_us">
|
163
|
+
<a href="/about_us"><span>About Us</span></a>
|
164
|
+
<ul>
|
165
|
+
<li id="nothing_here"><span>Nothing Here</span></li>
|
166
|
+
</ul>
|
167
|
+
</li>
|
168
|
+
</ul>
|
169
|
+
</li>
|
170
|
+
</div>
|
171
|
+
</ul>
|
172
|
+
</pre>
|
173
|
+
|
174
|
+
h3. XML
|
175
|
+
|
176
|
+
<pre>
|
177
|
+
...Still working on the xml builder...
|
178
|
+
</pre>
|
179
|
+
|
180
|
+
h3. Other
|
181
|
+
|
182
|
+
You can always create your own builder by extending one of the existing ones, or creating one from scratch.
|
183
|
+
|
184
|
+
Then just specify your builder, or do it as a configuration.
|
185
|
+
|
186
|
+
@semantic_navigation :main, :builder => MyCustomBuilder do@
|
187
|
+
|
188
|
+
@Navigasmic::SemanticNavigationHelper.builder = MyCustomBuilder@
|
189
|
+
|
190
|
+
h2. Documentation
|
191
|
+
|
192
|
+
RDoc documentation _should_ be automatically generated after each commit and made available on the "rdoc.info website":http://rdoc.info/projects/jejacks0n/navigasmic.
|
193
|
+
|
194
|
+
h2. Compatibility
|
195
|
+
|
196
|
+
I'm only testing with the latest Rails 2.4.x stable release, and it should work under Rails 2.3.x as well. Feel free to add backwards compatibility if you need it.
|
197
|
+
|
198
|
+
h2. Project Info
|
199
|
+
|
200
|
+
Navigasmic is hosted on Github: "http://github.com/jejacks0n/navigasmic":http://github.com/jejacks0n/navigasmic, and the gem is available on Gemcutter: "http://gemcutter.org/navigasmic":http://gemcutter.org/navigasmic
|
201
|
+
|
202
|
+
|
203
|
+
Copyright (c) Jeremy Jackson, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "navigasmic"
|
8
|
+
gem.summary = %Q{Semantic navigation for Rails}
|
9
|
+
gem.description = %Q{Semantic navigation; a semantic way to build beautifully simple navigation structures in Rails.}
|
10
|
+
gem.email = "jejacks0n@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/jejacks0n/navigasmic"
|
12
|
+
gem.authors = ["Jeremy Jackson"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
if File.exist?('VERSION')
|
47
|
+
version = File.read('VERSION')
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "navigasmic #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Navigasmic
|
2
|
+
class HtmlNavigationBuilder
|
3
|
+
|
4
|
+
@@classnames = {
|
5
|
+
:with_group => 'with-group',
|
6
|
+
:disabled => 'disabled',
|
7
|
+
:highlighted => 'highlighted'
|
8
|
+
}
|
9
|
+
|
10
|
+
attr_accessor :template, :name, :items
|
11
|
+
|
12
|
+
def initialize(template, name, options = {}, &proc)
|
13
|
+
@template, @name, @items = template, name.to_s, options, []
|
14
|
+
render(options.delete(:html), &proc)
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(options, &proc)
|
18
|
+
buffer = template.capture(self, &proc)
|
19
|
+
template.concat(template.content_tag(:ul, buffer, options))
|
20
|
+
end
|
21
|
+
|
22
|
+
def group(label = nil, options = {}, &proc)
|
23
|
+
raise ArgumentError, "Missing block" unless block_given?
|
24
|
+
|
25
|
+
options[:html] ||= {}
|
26
|
+
options[:html][:class] = template.add_class(options[:html][:class], @@classnames[:with_group])
|
27
|
+
options[:html][:id] ||= label.to_s.gsub(/\s/, '_').underscore
|
28
|
+
|
29
|
+
buffer = template.capture(self, &proc)
|
30
|
+
group = template.content_tag(:ul, buffer)
|
31
|
+
label = label_for_group(label) unless label.blank?
|
32
|
+
|
33
|
+
template.content_tag(:li, label.to_s + group, options.delete(:html))
|
34
|
+
end
|
35
|
+
|
36
|
+
def item(label, options = {}, &proc)
|
37
|
+
buffer = block_given? ? template.capture(self, &proc) : ''
|
38
|
+
|
39
|
+
item = NavigationItem.new(label, options)
|
40
|
+
|
41
|
+
options[:html] ||= {}
|
42
|
+
options[:html][:id] ||= label.to_s.gsub(/\s/, '_').underscore
|
43
|
+
|
44
|
+
options[:html][:class] = template.add_class(options[:html][:class], @@classnames[:disabled]) if item.disabled?
|
45
|
+
options[:html][:class] = template.add_class(options[:html][:class], @@classnames[:highlighted]) if item.highlighted?(template.request.path, template.params)
|
46
|
+
|
47
|
+
label = label_for_item(label)
|
48
|
+
label = template.link_to(label, item.link) unless item.link.empty?
|
49
|
+
|
50
|
+
template.content_tag(:li, label + buffer, options.delete(:html))
|
51
|
+
end
|
52
|
+
|
53
|
+
def label_for_group(label)
|
54
|
+
template.content_tag(:span, label.to_s)
|
55
|
+
end
|
56
|
+
|
57
|
+
def label_for_item(label)
|
58
|
+
template.content_tag(:span, label.to_s)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Navigasmic
|
2
|
+
class XmlNavigationBuilder
|
3
|
+
|
4
|
+
@@classnames = {
|
5
|
+
:with_group => 'with-group',
|
6
|
+
:disabled => 'disabled',
|
7
|
+
:highlighted => 'highlighted'
|
8
|
+
}
|
9
|
+
|
10
|
+
attr_accessor :template, :name, :items
|
11
|
+
|
12
|
+
def initialize(template, name, options = {}, &proc)
|
13
|
+
@template, @name, @items = template, name.to_s, options, []
|
14
|
+
render(options.delete(:html), &proc)
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(options, &proc)
|
18
|
+
buffer = template.capture(self, &proc)
|
19
|
+
template.concat(template.content_tag(:ol, buffer, options))
|
20
|
+
end
|
21
|
+
|
22
|
+
def group(label = nil, options = {}, &proc)
|
23
|
+
raise ArgumentError, "Missing block" unless block_given?
|
24
|
+
|
25
|
+
options[:html] ||= {}
|
26
|
+
options[:html][:class] = template.add_class(options[:html][:class], @@classnames[:with_group])
|
27
|
+
options[:html][:id] ||= label.to_s.gsub(/\s/, '_').underscore
|
28
|
+
|
29
|
+
buffer = template.capture(self, &proc)
|
30
|
+
group = template.content_tag(:ol, buffer)
|
31
|
+
label = label_for_group(label) unless label.blank?
|
32
|
+
|
33
|
+
template.content_tag(:li, label.to_s + group, options.delete(:html))
|
34
|
+
end
|
35
|
+
|
36
|
+
def item(label, options = {}, &proc)
|
37
|
+
buffer = block_given? ? template.capture(self, &proc) : ''
|
38
|
+
|
39
|
+
item = NavigationItem.new(label, options)
|
40
|
+
|
41
|
+
options[:html] ||= {}
|
42
|
+
options[:html][:id] ||= label.to_s.gsub(/\s/, '_').underscore
|
43
|
+
|
44
|
+
options[:html][:class] = template.add_class(options[:html][:class], @@classnames[:disabled]) if item.disabled?
|
45
|
+
options[:html][:class] = template.add_class(options[:html][:class], @@classnames[:highlighted]) if item.highlighted?(template.request.path, template.params)
|
46
|
+
|
47
|
+
label = label_for_item(label)
|
48
|
+
label = template.link_to(label, item.link) unless item.link.empty?
|
49
|
+
|
50
|
+
template.content_tag(:li, label + buffer, options.delete(:html))
|
51
|
+
end
|
52
|
+
|
53
|
+
def label_for_group(label)
|
54
|
+
template.content_tag(:span, label.to_s)
|
55
|
+
end
|
56
|
+
|
57
|
+
def label_for_item(label)
|
58
|
+
template.content_tag(:span, label.to_s)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
data/lib/navigasmic.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.join(File.dirname(__FILE__), *%w[builders html_builder])
|
3
|
+
require File.join(File.dirname(__FILE__), *%w[builders xml_builder])
|
4
|
+
|
5
|
+
module Navigasmic #:nodoc:
|
6
|
+
|
7
|
+
# Semantic navigation helper methods
|
8
|
+
#
|
9
|
+
# Example Usage:
|
10
|
+
#
|
11
|
+
# <% semantic_navigation :primary, :html => {:class => 'primary'} do |n| %>
|
12
|
+
# <%= n.item 'Blog Posts', :link => {:controller => 'posts'} %>
|
13
|
+
# <% end %>
|
14
|
+
#
|
15
|
+
# <% semantic_navigation :primary, :builder => MyCustomBuilder do |n| %>
|
16
|
+
# <%= n.group 'My Thoughts' do %>
|
17
|
+
# <%= n.item 'Blog Posts', :link => {:controller => 'posts'} %>
|
18
|
+
# <% end %>
|
19
|
+
# <% end %>
|
20
|
+
#
|
21
|
+
# <% semantic_navigation :primary do |n| %>
|
22
|
+
# <%= n.group 'My Thoughts' do %>
|
23
|
+
# <%= n.item 'Blog Posts', :link => {:controller => 'posts'} do %>
|
24
|
+
# <ul>
|
25
|
+
# <%= n.item 'Recent Posts', :link => {:controller => 'posts', :action => 'recent'} %>
|
26
|
+
# </ul>
|
27
|
+
# <% end %>
|
28
|
+
# <% end %>
|
29
|
+
# <% end %>
|
30
|
+
module SemanticNavigationHelper
|
31
|
+
|
32
|
+
@@builder = ::Navigasmic::HtmlNavigationBuilder
|
33
|
+
mattr_accessor :builder
|
34
|
+
|
35
|
+
def semantic_navigation(name, *args, &proc)
|
36
|
+
raise ArgumentError, "Missing block" unless block_given?
|
37
|
+
|
38
|
+
options = args.extract_options!
|
39
|
+
|
40
|
+
options[:html] ||= {}
|
41
|
+
options[:html][:class] = add_class(options[:html][:class], 'semantic-navigation')
|
42
|
+
options[:html][:id] ||= name.to_s.underscore
|
43
|
+
|
44
|
+
builder = options[:builder] || HtmlNavigationBuilder
|
45
|
+
builder.new(@template, name, options, &proc)
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_class(classnames, classname)
|
49
|
+
out = (classnames.is_a?(String) ? classnames.split(' ') : []) << classname
|
50
|
+
out.join(' ')
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
#
|
57
|
+
#
|
58
|
+
#
|
59
|
+
#
|
60
|
+
class NavigationItem
|
61
|
+
|
62
|
+
attr_accessor :label, :link
|
63
|
+
|
64
|
+
def initialize(label, options = {})
|
65
|
+
@label = label
|
66
|
+
@link = options[:link] || {}
|
67
|
+
|
68
|
+
@disabled_conditions = options[:disabled_if] || proc { false }
|
69
|
+
|
70
|
+
options[:highlights] = [options[:highlights]] if options[:highlights].kind_of?(Hash)
|
71
|
+
@highlights_on = options[:highlights] || []
|
72
|
+
@highlights_on << @link if link?
|
73
|
+
end
|
74
|
+
|
75
|
+
def link?
|
76
|
+
@link && !@link.empty?
|
77
|
+
end
|
78
|
+
|
79
|
+
def disabled?
|
80
|
+
@disabled_conditions.call
|
81
|
+
end
|
82
|
+
|
83
|
+
def highlighted?(path, params = {})
|
84
|
+
params = clean_unwanted_keys(params)
|
85
|
+
result = false
|
86
|
+
|
87
|
+
@highlights_on.each do |highlight|
|
88
|
+
highlighted = true
|
89
|
+
|
90
|
+
case highlight
|
91
|
+
when String
|
92
|
+
highlighted &= path == highlight
|
93
|
+
when Proc
|
94
|
+
h = highlight.call
|
95
|
+
raise 'proc highlighting rules must evaluate to TrueClass or FalseClass' unless (h.is_a?(TrueClass) || h.is_a?(FalseClass))
|
96
|
+
highlighted &= h
|
97
|
+
when Hash
|
98
|
+
h = clean_unwanted_keys(highlight)
|
99
|
+
h.each_key do |key|
|
100
|
+
h_key = h[key].to_s.dup
|
101
|
+
h_key.gsub!(/^\//, '') if key == :controller
|
102
|
+
highlighted &= h_key == params[key].to_s
|
103
|
+
end
|
104
|
+
else
|
105
|
+
raise 'highlighting rules should be a String, Proc or a Hash'
|
106
|
+
end
|
107
|
+
|
108
|
+
result |= highlighted
|
109
|
+
end
|
110
|
+
|
111
|
+
return result
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
# removes unwanted keys from a Hash and returns a new hash
|
117
|
+
def clean_unwanted_keys(hash)
|
118
|
+
ignored_keys = [:only_path, :use_route]
|
119
|
+
hash.dup.delete_if { |key, value| ignored_keys.include?(key) }
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
ActionController::Base.helper Navigasmic::SemanticNavigationHelper
|
data/navigasmic.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
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{navigasmic}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jeremy Jackson"]
|
12
|
+
s.date = %q{2010-01-09}
|
13
|
+
s.description = %q{Semantic navigation; a semantic way to build beautifully simple navigation structures in Rails.}
|
14
|
+
s.email = %q{jejacks0n@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.textile"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.textile",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/builders/html_builder.rb",
|
27
|
+
"lib/builders/xml_builder.rb",
|
28
|
+
"lib/navigasmic.rb",
|
29
|
+
"navigasmic.gemspec",
|
30
|
+
"test/navigasmic_test.rb",
|
31
|
+
"test/test_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/jejacks0n/navigasmic}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.5}
|
37
|
+
s.summary = %q{Semantic navigation for Rails}
|
38
|
+
s.test_files = [
|
39
|
+
"test/navigasmic_test.rb",
|
40
|
+
"test/test_helper.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
+
end
|
55
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: navigasmic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Jackson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-09 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Semantic navigation; a semantic way to build beautifully simple navigation structures in Rails.
|
26
|
+
email: jejacks0n@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.textile
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.textile
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- lib/builders/html_builder.rb
|
42
|
+
- lib/builders/xml_builder.rb
|
43
|
+
- lib/navigasmic.rb
|
44
|
+
- navigasmic.gemspec
|
45
|
+
- test/navigasmic_test.rb
|
46
|
+
- test/test_helper.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/jejacks0n/navigasmic
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Semantic navigation for Rails
|
75
|
+
test_files:
|
76
|
+
- test/navigasmic_test.rb
|
77
|
+
- test/test_helper.rb
|