forked from unders/simple_nav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
81 lines (62 loc) · 2.67 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
SimpleNav
=========
SimpleNav is a plugin that provides helpers the make navigation display simple.
It breaks down navigation into 3 parts:
1. The Links that your site has for navigation
(all of them, regardless if they are going to show up on every request)
2. The order to display them for this request. This order can be any subset of the above list.
3. The process to select the tab that is currently marked with the "selected" css class
(this part is broken into a basic and advanced version)
Once you have configured the 3 parts, you can just call
nav_links anywhere in your view to get your nav ul:
<ul>
<li><a href="/home">Home</a></li>
<li class="selected"><a href="/login">Login</a></li>
</ul>
To generate your NavigationHelper, run:
./script/generate nav_helper <helper_name>
where <helper_name> is "navigation" or what ever word you want to use (w/o the "helper" word)
The generated helper is documented with the method stubs for the above 3 parts
Namespaces
==========
If you are upgrading from a previous version of SimpleNav, you need to add
a namespace parameter as the last parameter of every helper in your
navigation helper. Example:
OLD:
def nav_list
def nav_selection_advanced(controller, action)
NEW:
def nav_list(namespace)
def nav_selection_advanced(controller, action, namespace)
Every nav helper method takes a "namespace" parameter as its last or only parameter.
The namespace parameter can be used to differentiate between different sets of
navigation links. (i.e. main nav, and sub nav)
If you only have 1 set of nav links, ignore the namespace parameter.
If you have multiple sets of links, you can pass the namespace to
the "nav_links" method to get the appropriate links for that namespace.
Namespaces should be symbols or strings, just be consistent.
Example
=======
Here is an example of a nav helper that is being used on my blog:
module NavigationHelper
include SimpleNavHelper
def nav_list
{
:blog => {:text => "blog", :href => '/', :class => []},
:resources => {:text => "resources", :href => resources_path, :class => []},
:about => {:text => "about", :href => about_path, :class => []},
:admin => {:text => "admin", :href => admin_path, :class => ["right"]}
}
end
def nav_order
[:blog, :resources, :about, :admin]
end
def nav_selection_hash(controller, action)
{
:pages => {[:error_404, :error_500] => :false, :else => action},
:posts => {[:index, :show, :search, :tags] => :blog},
:links => {:resources => :resources},
:else => :admin
}
end
end